|
From: <be...@us...> - 2006-09-04 17:17:43
|
Revision: 97
http://svn.sourceforge.net/objectlabkit/?rev=97&view=rev
Author: benoitx
Date: 2006-09-04 10:16:22 -0700 (Mon, 04 Sep 2006)
Log Message:
-----------
Added 3 extra methods for IMM:
- 2 using IMMPeriod and ALL have been implemented (albeit not tested for JDK)
- isIMMDate method implemented for JODA but not JDK ==> Marcin, have fun! ;-)
Modified Paths:
--------------
trunk/datecalc-common/project.xml
trunk/datecalc-common/qalab.xml
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java
trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractBackwardDateCalculatorTest.java
trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardDateCalculatorTest.java
trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedFollowingDateCalculatorTest.java
trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedPreceedingDateCalculatorTest.java
trunk/datecalc-jdk/project.xml
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarPeriodCountCalculator.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkCalendarBaseDateCalculator.java
trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkDateBaseDateCalculator.java
trunk/datecalc-joda/project.xml
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java
trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java
trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/IMMDateTest.java
Added Paths:
-----------
trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/IMMPeriod.java
Modified: trunk/datecalc-common/project.xml
===================================================================
--- trunk/datecalc-common/project.xml 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/project.xml 2006-09-04 17:16:22 UTC (rev 97)
@@ -35,7 +35,7 @@
<report>maven-simian-plugin</report>
<report>maven-cobertura-plugin</report>
<report>maven-qalab-plugin</report>
- <report>maven-ydoc-plugin</report>
+ <!--<report>maven-ydoc-plugin</report>-->
<report>maven-jdepend-plugin</report>
<report>maven-faq-plugin</report>
<report>maven-junit-report-plugin</report>
Modified: trunk/datecalc-common/qalab.xml
===================================================================
--- trunk/datecalc-common/qalab.xml 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/qalab.xml 2006-09-04 17:16:22 UTC (rev 97)
@@ -46,6 +46,10 @@
<summaryresult date="2006-09-02" filecount="13" statvalue="9" type="checkstyle"/>
<summaryresult date="2006-09-02" filecount="12" statvalue="59" type="cobertura-line"/>
<summaryresult date="2006-09-02" filecount="12" statvalue="61" type="cobertura-branch"/>
+ <summaryresult date="2006-09-04" filecount="14" statvalue="12" type="checkstyle"/>
+ <summaryresult date="2006-09-04" filecount="1" statvalue="1" type="findbugs"/>
+ <summaryresult date="2006-09-04" filecount="13" statvalue="62" type="cobertura-line"/>
+ <summaryresult date="2006-09-04" filecount="13" statvalue="64" type="cobertura-branch"/>
</summary>
<file id="net_objectlab_kit_datecalc_common_package.html" path="net/objectlab/kit/datecalc/common/package.html">
<result date="2006-08-08" statvalue="1" type="checkstyle"/>
@@ -57,6 +61,7 @@
<result date="2006-08-24" statvalue="1" type="checkstyle"/>
<result date="2006-08-28" statvalue="1" type="checkstyle"/>
<result date="2006-09-02" statvalue="1" type="checkstyle"/>
+ <result date="2006-09-04" statvalue="1" type="checkstyle"/>
</file>
<file id="net_objectlab_kit_datecalc_common_Tenor.java" path="net/objectlab/kit/datecalc/common/Tenor.java">
<result date="2006-08-08" statvalue="1" type="checkstyle"/>
@@ -80,6 +85,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_WorkingWeek.java" path="net/objectlab/kit/datecalc/common/WorkingWeek.java">
<result date="2006-08-08" statvalue="3" type="checkstyle"/>
@@ -104,6 +111,10 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="1" type="checkstyle"/>
+ <result date="2006-09-04" statvalue="1" type="findbugs"/>
+ <result date="2006-09-04" statvalue="95" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_TenorCode.java" path="net/objectlab/kit/datecalc/common/TenorCode.java">
<result date="2006-08-08" statvalue="100" type="cobertura-line"/>
@@ -124,6 +135,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_HolidayHandlerType.java" path="net/objectlab/kit/datecalc/common/HolidayHandlerType.java">
<result date="2006-08-08" statvalue="100" type="cobertura-branch"/>
@@ -135,6 +148,7 @@
<result date="2006-08-24" statvalue="100" type="cobertura-branch"/>
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_PeriodCountBasis.java" path="net/objectlab/kit/datecalc/common/PeriodCountBasis.java">
<result date="2006-08-08" statvalue="100" type="cobertura-branch"/>
@@ -144,6 +158,7 @@
<result date="2006-08-24" statvalue="100" type="cobertura-branch"/>
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_StandardTenor.java" path="net/objectlab/kit/datecalc/common/StandardTenor.java">
<result date="2006-08-08" statvalue="100" type="cobertura-branch"/>
@@ -163,6 +178,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="92" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="92" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file
id="net_objectlab_kit_datecalc_common_AbstractDateCalculator.java" path="net/objectlab/kit/datecalc/common/AbstractDateCalculator.java">
@@ -180,6 +197,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file id="net_objectlab_kit_datecalc_common_HolidayHandler.java" path="net/objectlab/kit/datecalc/common/HolidayHandler.java">
<result date="2006-08-23" statvalue="100" type="cobertura-line"/>
@@ -190,6 +209,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file
id="net_objectlab_kit_datecalc_common_AbstractDateCalculatorFactory.java" path="net/objectlab/kit/datecalc/common/AbstractDateCalculatorFactory.java">
@@ -197,6 +218,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="2" type="checkstyle"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="2" type="checkstyle"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file
id="net_objectlab_kit_datecalc_common_DateCalculatorFactory.java" path="net/objectlab/kit/datecalc/common/DateCalculatorFactory.java">
@@ -204,6 +227,8 @@
<result date="2006-08-28" statvalue="100" type="cobertura-branch"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
<file
id="net_objectlab_kit_datecalc_common_PeriodCountCalculator.java" path="net/objectlab/kit/datecalc/common/PeriodCountCalculator.java">
@@ -212,5 +237,13 @@
<result date="2006-09-02" statvalue="6" type="checkstyle"/>
<result date="2006-09-02" statvalue="100" type="cobertura-line"/>
<result date="2006-09-02" statvalue="100" type="cobertura-branch"/>
+ <result date="2006-09-04" statvalue="6" type="checkstyle"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
</file>
+ <file id="net_objectlab_kit_datecalc_common_Utils.java" path="net/objectlab/kit/datecalc/common/Utils.java">
+ <result date="2006-09-04" statvalue="2" type="checkstyle"/>
+ <result date="2006-09-04" statvalue="88" type="cobertura-line"/>
+ <result date="2006-09-04" statvalue="100" type="cobertura-branch"/>
+ </file>
</qalab>
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -19,6 +19,7 @@
import java.util.Collections;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
/**
@@ -215,18 +216,53 @@
* @return the next IMMDate based on current date.
*/
public E getNextIMMDate() {
- return getNextIMMDate(true, currentBusinessDate);
+ return getNextIMMDate(true, currentBusinessDate, IMMPeriod.QUARTERLY);
}
/**
+ * @param period
+ * specify when the "next" IMM is, if quarterly then it is the
+ * conventional algorithm.
+ * @return the next IMMDate based on current date.
+ */
+ public E getNextIMMDate(final IMMPeriod period) {
+ return getNextIMMDate(true, currentBusinessDate, period);
+ }
+
+ /**
* @return the previous IMMDate based on current date.
*/
public E getPreviousIMMDate() {
- return getNextIMMDate(false, currentBusinessDate);
+ return getNextIMMDate(false, currentBusinessDate, IMMPeriod.QUARTERLY);
}
- protected abstract E getNextIMMDate(final boolean forward, final E theStartDate);
+ /**
+ * @param period
+ * specify when the "previous" IMM is, if quarterly then it is
+ * the conventional algorithm.
+ * @return the previous IMMDate based on current date.
+ */
+ public E getPreviousIMMDate(final IMMPeriod period) {
+ return getNextIMMDate(false, currentBusinessDate, period);
+ }
+ /**
+ * Returns a list of IMM dates between 2 dates, it will exclude the start
+ * date if it is an IMM date but would include the end date if it is an IMM
+ * (same as IMMPeriod.QUARTERLY).
+ *
+ * @param start
+ * start of the interval, excluded
+ * @param end
+ * end of the interval, may be included.
+ * @return list of IMM dates
+ */
+ public List<E> getIMMDates(final E start, final E end) {
+ return getIMMDates(start, end, IMMPeriod.QUARTERLY);
+ }
+
+ protected abstract E getNextIMMDate(final boolean forward, final E theStartDate, final IMMPeriod period);
+
protected abstract DateCalculator<E> createNewCalcultaor(String calcName, E theStartDate, Set<E> holidays,
HolidayHandler<E> handler);
}
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -152,24 +152,70 @@
DateCalculator<E> moveByTenor(final Tenor tenor);
/**
+ * @param date
+ * @return true if that date is an IMM date.
+ */
+ boolean isIMMDate(E date);
+
+ /**
+ * Even if the current date is an IMM date, it will return the next one.
+ *
* @return the next IMMDate based on current date.
*/
E getNextIMMDate();
/**
+ * Even if the current date is an IMM date, it will return the next one.
+ *
+ * @param period
+ * specify when the "next" IMM is, if quarterly then it is the
+ * conventional algorithm.
+ * @return the next IMMDate based on current date.
+ */
+ E getNextIMMDate(IMMPeriod period);
+
+ /**
+ * Even if the current date is an IMM date, it will return the previous one.
+ *
* @return the previous IMMDate based on current date.
*/
E getPreviousIMMDate();
/**
+ * Even if the current date is an IMM date, it will return the previous one.
+ *
+ * @param period
+ * specify when the "previous" IMM is, if quarterly then it is
+ * the conventional algorithm.
+ * @return the previous IMMDate based on current date.
+ */
+ E getPreviousIMMDate(IMMPeriod period);
+
+ /**
* Returns a list of IMM dates between 2 dates, it will exclude the start
+ * date if it is an IMM date but would include the end date if it is an IMM
+ * (same as IMMPeriod.QUARTERLY).
+ *
+ * @param start
+ * start of the interval, excluded
+ * @param end
+ * end of the interval, may be included.
+ * @return list of IMM dates
+ */
+ List<E> getIMMDates(final E start, final E end);
+
+ /**
+ * Returns a list of IMM dates between 2 dates, it will exclude the start
* date if it is an IMM date but would include the end date if it is an IMM.
*
* @param start
* start of the interval, excluded
* @param end
* end of the interval, may be included.
+ * @param period
+ * specify when the "next" IMM is, if quarterly then it is the
+ * conventional algorithm.
* @return list of IMM dates
*/
- List<E> getIMMDates(final E start, final E end);
+ List<E> getIMMDates(final E start, final E end, final IMMPeriod period);
}
\ No newline at end of file
Added: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/IMMPeriod.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/IMMPeriod.java (rev 0)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/IMMPeriod.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -0,0 +1,35 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package net.objectlab.kit.datecalc.common;
+
+/**
+ * Some instruments require a period Bi Annually which then can be Mar-Sep or
+ * Jun-Dec.
+ *
+ * @author Benoit Xhenseval
+ * @author $LastChangedBy$
+ * @version $Revision$ $Date$
+ */
+public enum IMMPeriod {
+ /** Bi annually March and September */
+ BI_ANNUALY_MAR_SEP,
+ /** Bi annually March and September */
+ BI_ANNUALY_JUN_DEC,
+ /** Quarterly: eg March, June, September, December */
+ QUARTERLY
+}
Modified: trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java
===================================================================
--- trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/Utils.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -27,6 +27,7 @@
/**
* TODO javadoc
+ *
* @author Marcin Jekot
* @author $LastModifiedBy$
* @version $Revision$ $Date$
@@ -35,6 +36,7 @@
public class Utils {
private static final String DATE_PATTERN = "yyyy-MM-dd";
+
private static final SimpleDateFormat SDF = new SimpleDateFormat(DATE_PATTERN);
public static Calendar getCal(final Date date) {
@@ -50,35 +52,35 @@
public static Date createDate(final String str) throws IllegalArgumentException {
try {
- Date date = SDF.parse(str);
- Calendar cal = getCal(date);
+ final Date date = SDF.parse(str);
+ final Calendar cal = getCal(date);
return cal.getTime();
} catch (final ParseException e) {
throw new IllegalArgumentException("\"" + str + "\"" + " is an invalid date, the pattern is : " + DATE_PATTERN);
}
}
-
- public static Set<Calendar> toCalendarSet(Set<Date> dates) {
- Set<Calendar> calendars = new HashSet<Calendar>();
- for (Date date : dates) {
+
+ public static Set<Calendar> toCalendarSet(final Set<Date> dates) {
+ final Set<Calendar> calendars = new HashSet<Calendar>();
+ for (final Date date : dates) {
calendars.add(getCal(date));
}
return calendars;
}
- public static Set<Date> toDateSet(Set<Calendar> calendars) {
-
- Set<Date> dates = new HashSet<Date>();
- for (Calendar calendar : calendars) {
+ public static Set<Date> toDateSet(final Set<Calendar> calendars) {
+
+ final Set<Date> dates = new HashSet<Date>();
+ for (final Calendar calendar : calendars) {
dates.add(calendar.getTime());
}
return dates;
}
- public static List<Date> toDateList(List<Calendar> dates) {
-
- List<Date> dateList = new ArrayList<Date>();
- for (Calendar calendar : dates) {
+ public static List<Date> toDateList(final List<Calendar> dates) {
+
+ final List<Date> dateList = new ArrayList<Date>();
+ for (final Calendar calendar : dates) {
dateList.add(calendar.getTime());
}
Modified: trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractBackwardDateCalculatorTest.java
===================================================================
--- trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractBackwardDateCalculatorTest.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractBackwardDateCalculatorTest.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -50,8 +50,8 @@
public void testSimpleForwardStartDateNoWeekend() {
final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.BACKWARD);
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(true,
- Calendar.SUNDAY);
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(
+ true, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
@@ -83,8 +83,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(false, Calendar.FRIDAY).withWorkingDayFromCalendar(true,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
@@ -116,8 +116,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(true, Calendar.FRIDAY).withWorkingDayFromCalendar(false,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Modified: trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardDateCalculatorTest.java
===================================================================
--- trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardDateCalculatorTest.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractForwardDateCalculatorTest.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -50,8 +50,8 @@
public void testSimpleForwardStartDateNoWeekend() {
final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.FORWARD);
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(true,
- Calendar.SUNDAY);
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(
+ true, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
@@ -83,8 +83,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(false, Calendar.FRIDAY).withWorkingDayFromCalendar(true,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
@@ -116,8 +116,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(true, Calendar.FRIDAY).withWorkingDayFromCalendar(false,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Modified: trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedFollowingDateCalculatorTest.java
===================================================================
--- trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedFollowingDateCalculatorTest.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedFollowingDateCalculatorTest.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -50,8 +50,8 @@
public void testSimpleForwardStartDateNoWeekend() {
final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.MODIFIED_FOLLLOWING);
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(true,
- Calendar.SUNDAY);
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(
+ true, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Assert.assertEquals("Name", "bla", cal.getName());
@@ -84,8 +84,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(false, Calendar.FRIDAY).withWorkingDayFromCalendar(true,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
@@ -117,8 +117,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(true, Calendar.FRIDAY).withWorkingDayFromCalendar(false,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Modified: trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedPreceedingDateCalculatorTest.java
===================================================================
--- trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedPreceedingDateCalculatorTest.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-common/src/test/java/net/objectlab/kit/datecalc/common/AbstractModifiedPreceedingDateCalculatorTest.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -51,8 +51,8 @@
public void testSimpleForwardStartDateNoWeekend() {
final DateCalculator<E> cal = newDateCalculator("bla", HolidayHandlerType.MODIFIED_PRECEEDING);
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(true,
- Calendar.SUNDAY);
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(true, Calendar.SATURDAY).withWorkingDayFromCalendar(
+ true, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Assert.assertEquals("Name", "bla", cal.getName());
@@ -85,8 +85,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(false, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(false, Calendar.FRIDAY).withWorkingDayFromCalendar(true,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
@@ -118,8 +118,8 @@
Assert.assertEquals("Name", "bla", cal.getName());
Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
- final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(true,
- Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
+ final WorkingWeek ww = new WorkingWeek().withWorkingDayFromCalendar(false, Calendar.MONDAY).withWorkingDayFromCalendar(
+ true, Calendar.TUESDAY).withWorkingDayFromCalendar(true, Calendar.WEDNESDAY).withWorkingDayFromCalendar(true,
Calendar.THURSDAY).withWorkingDayFromCalendar(true, Calendar.FRIDAY).withWorkingDayFromCalendar(false,
Calendar.SATURDAY).withWorkingDayFromCalendar(false, Calendar.SUNDAY);
cal.setWorkingWeek(getWorkingWeek(ww));
Modified: trunk/datecalc-jdk/project.xml
===================================================================
--- trunk/datecalc-jdk/project.xml 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-jdk/project.xml 2006-09-04 17:16:22 UTC (rev 97)
@@ -42,7 +42,7 @@
<report>maven-simian-plugin</report>
<report>maven-cobertura-plugin</report>
<report>maven-qalab-plugin</report>
- <report>maven-ydoc-plugin</report>
+ <!--<report>maven-ydoc-plugin</report>-->
<report>maven-jdepend-plugin</report>
<report>maven-faq-plugin</report>
<report>maven-junit-report-plugin</report>
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarPeriodCountCalculator.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarPeriodCountCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/CalendarPeriodCountCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -82,11 +82,12 @@
}
private int dayDiff(final Calendar start, final Calendar end) {
-// System.out.println("start:" + start.getTime() + " end:" + end.getTime());
- long diff = Math.abs(start.getTimeInMillis() - end.getTimeInMillis());
-// System.out.println("ms diff:" + diff);
- double dayDiff = ((double)diff) / MILLIS_IN_DAY;
-// System.out.println("day diff:" + dayDiff);
+ // System.out.println("start:" + start.getTime() + " end:" +
+ // end.getTime());
+ final long diff = Math.abs(start.getTimeInMillis() - end.getTimeInMillis());
+ // System.out.println("ms diff:" + diff);
+ final double dayDiff = ((double) diff) / MILLIS_IN_DAY;
+ // System.out.println("day diff:" + dayDiff);
return (int) (dayDiff);
}
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkCalendarBaseDateCalculator.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkCalendarBaseDateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkCalendarBaseDateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -26,6 +26,7 @@
import net.objectlab.kit.datecalc.common.AbstractDateCalculator;
import net.objectlab.kit.datecalc.common.DateCalculator;
import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.IMMPeriod;
import net.objectlab.kit.datecalc.common.Tenor;
import net.objectlab.kit.datecalc.common.WorkingWeek;
@@ -93,17 +94,24 @@
}
/**
- * Calculates IMMDates between a start and end dates the 3rd wednesday of
- * Mar/Jun/Sep/Dec when a lot of derivative contracts expire
+ * Returns a list of IMM dates between 2 dates, it will exclude the start
+ * date if it is an IMM date but would include the end date if it is an IMM.
*
- * @return a List of Dates
+ * @param start
+ * start of the interval, excluded
+ * @param end
+ * end of the interval, may be included.
+ * @param period
+ * specify when the "next" IMM is, if quarterly then it is the
+ * conventional algorithm.
+ * @return list of IMM dates
*/
- public List<Calendar> getIMMDates(final Calendar start, final Calendar end) {
+ public List<Calendar> getIMMDates(final Calendar start, final Calendar end, final IMMPeriod period) {
final List<Calendar> dates = new ArrayList<Calendar>();
Calendar cal = (Calendar) start.clone();
while (true) {
- cal = getNextIMMDate(true, cal);
+ cal = getNextIMMDate(true, cal, period);
if (!cal.after(end)) {
dates.add(cal);
} else {
@@ -115,9 +123,9 @@
}
@Override
- protected Calendar getNextIMMDate(final boolean forward, final Calendar startDate) {
+ protected Calendar getNextIMMDate(final boolean forward, final Calendar startDate, final IMMPeriod period) {
- final Calendar cal = (Calendar) startDate.clone();
+ Calendar cal = (Calendar) startDate.clone();
if (isIMMMonth(cal)) {
moveToIMMDay(cal);
@@ -135,6 +143,18 @@
} while (!isIMMMonth(cal));
moveToIMMDay(cal);
+
+ final int month = cal.get(Calendar.MONTH);
+ if ( (period == IMMPeriod.BI_ANNUALY_JUN_DEC
+ && (Calendar.MARCH == month || Calendar.SEPTEMBER==month) )
+ ||
+ ( period == IMMPeriod.BI_ANNUALY_MAR_SEP
+ && (Calendar.JUNE == month || Calendar.DECEMBER==month) ) ) {
+ // need to move to the next one.
+ cal = getNextIMMDate(forward, cal, period);
+ }
+
+
return cal;
}
@@ -190,4 +210,9 @@
return (JdkCalendarBaseDateCalculator) super.moveByBusinessDays(businessDays);
}
+ public boolean isIMMDate(final Calendar date) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
}
Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkDateBaseDateCalculator.java
===================================================================
--- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkDateBaseDateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/JdkDateBaseDateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -25,6 +25,7 @@
import net.objectlab.kit.datecalc.common.DateCalculator;
import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.IMMPeriod;
import net.objectlab.kit.datecalc.common.Tenor;
import net.objectlab.kit.datecalc.common.Utils;
import net.objectlab.kit.datecalc.common.WorkingWeek;
@@ -58,16 +59,16 @@
return delegate.getCurrentBusinessDate().getTime();
}
- public List<Date> getIMMDates(final Date start, final Date end) {
- return Utils.toDateList(delegate.getIMMDates(Utils.getCal(start), Utils.getCal(end)));
+ public List<Date> getIMMDates(final Date start, final Date end, final IMMPeriod period) {
+ return Utils.toDateList(delegate.getIMMDates(Utils.getCal(start), Utils.getCal(end), period));
}
- public Date getNextIMMDate() {
- return delegate.getNextIMMDate().getTime();
+ public Date getNextIMMDate(final IMMPeriod period) {
+ return delegate.getNextIMMDate(period).getTime();
}
- public Date getPreviousIMMDate() {
- return delegate.getPreviousIMMDate().getTime();
+ public Date getPreviousIMMDate(final IMMPeriod period) {
+ return delegate.getPreviousIMMDate(period).getTime();
}
public Date getStartDate() {
@@ -154,4 +155,20 @@
return new JdkDateBaseDateCalculator(delegate.getName() + "/" + calculator.getName(), getStartDate(), newSet, delegate
.getHolidayHandler());
}
+
+ public List<Date> getIMMDates(final Date start, final Date end) {
+ return getIMMDates(start, end, IMMPeriod.QUARTERLY);
+ }
+
+ public Date getNextIMMDate() {
+ return getNextIMMDate(IMMPeriod.QUARTERLY);
+ }
+
+ public Date getPreviousIMMDate() {
+ return getPreviousIMMDate(IMMPeriod.QUARTERLY);
+ }
+
+ public boolean isIMMDate(final Date date) {
+ return delegate.isIMMDate(Utils.getCal(date));
+ }
}
Modified: trunk/datecalc-joda/project.xml
===================================================================
--- trunk/datecalc-joda/project.xml 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-joda/project.xml 2006-09-04 17:16:22 UTC (rev 97)
@@ -41,7 +41,7 @@
<report>maven-simian-plugin</report>
<report>maven-cobertura-plugin</report>
<report>maven-qalab-plugin</report>
- <report>maven-ydoc-plugin</report>
+ <!--<report>maven-ydoc-plugin</report>-->
<report>maven-jdepend-plugin</report>
<report>maven-faq-plugin</report>
<report>maven-junit-report-plugin</report>
Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/LocalDateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -23,6 +23,7 @@
import net.objectlab.kit.datecalc.common.AbstractDateCalculator;
import net.objectlab.kit.datecalc.common.DateCalculator;
import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.IMMPeriod;
import net.objectlab.kit.datecalc.common.WorkingWeek;
import org.joda.time.DateTimeConstants;
@@ -92,12 +93,12 @@
return new LocalDateCalculator(name, startDate, holidays, handler);
}
- public List<LocalDate> getIMMDates(final LocalDate start, final LocalDate end) {
+ public List<LocalDate> getIMMDates(final LocalDate start, final LocalDate end, final IMMPeriod period) {
final List<LocalDate> dates = new ArrayList<LocalDate>();
LocalDate date = start;
while (true) {
- date = getNextIMMDate(true, date);
+ date = getNextIMMDate(true, date, period);
if (!date.isAfter(end)) {
dates.add(date);
} else {
@@ -109,7 +110,7 @@
}
@Override
- protected LocalDate getNextIMMDate(final boolean forward, final LocalDate start) {
+ protected LocalDate getNextIMMDate(final boolean forward, final LocalDate start, final IMMPeriod period) {
LocalDate date = start;
final int month = date.getMonthOfYear();
@@ -151,7 +152,18 @@
break;
}
- return calculate3rdWednesday(date);
+ LocalDate imm = calculate3rdWednesday(date);
+
+ if ( period == IMMPeriod.BI_ANNUALY_JUN_DEC
+ && (DateTimeConstants.MARCH == imm.getMonthOfYear() || DateTimeConstants.SEPTEMBER==imm.getMonthOfYear() )
+ ||
+ period == IMMPeriod.BI_ANNUALY_MAR_SEP
+ && (DateTimeConstants.JUNE == imm.getMonthOfYear() || DateTimeConstants.DECEMBER==imm.getMonthOfYear()) ) {
+ // need to move to the next one.
+ imm = getNextIMMDate(forward, imm, period);
+ }
+
+ return imm;
}
/**
@@ -169,4 +181,20 @@
}
return firstWed.plusWeeks(2);
}
+
+ /**
+ * @param date
+ * @return true if that date is an IMM date.
+ */
+ public boolean isIMMDate(final LocalDate date) {
+ boolean same = false;
+
+ final List<LocalDate> dates = getIMMDates(date.minusDays(1), date, IMMPeriod.QUARTERLY);
+
+ if (!dates.isEmpty()) {
+ same = date.equals(dates.get(0));
+ }
+
+ return same;
+ }
}
Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java
===================================================================
--- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/YearMonthDayDateCalculator.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -24,6 +24,7 @@
import net.objectlab.kit.datecalc.common.AbstractDateCalculator;
import net.objectlab.kit.datecalc.common.DateCalculator;
import net.objectlab.kit.datecalc.common.HolidayHandler;
+import net.objectlab.kit.datecalc.common.IMMPeriod;
import net.objectlab.kit.datecalc.common.WorkingWeek;
import org.joda.time.LocalDate;
@@ -79,32 +80,15 @@
delegate.setCurrentBusinessDate(getCurrentBusinessDate().toLocalDate());
setCurrentBusinessDate(new YearMonthDay(delegate.moveByDays(days).getCurrentBusinessDate()));
return this;
- // if (getCurrentBusinessDate() == null) {
- // initialise();
- // }
- // setCurrentBusinessDate(getCurrentBusinessDate().plusDays(days));
- //
- // if (getHolidayHandler() != null) {
- // setCurrentBusinessDate(getHolidayHandler().moveCurrentDate(this));
- // }
- //
- // return this;
}
- // private void initialise() {
- // if (getStartDate() == null) {
- // setStartDate(new YearMonthDay());
- // } else if (getCurrentBusinessDate() == null) {
- // setCurrentBusinessDate(new YearMonthDay());
- // }
- // }
- //
@Override
protected DateCalculator<YearMonthDay> createNewCalcultaor(final String name, final YearMonthDay startDate,
final Set<YearMonthDay> holidays, final HolidayHandler<YearMonthDay> handler) {
return new YearMonthDayDateCalculator(name, startDate, holidays, handler);
}
+ @Override
public List<YearMonthDay> getIMMDates(final YearMonthDay start, final YearMonthDay end) {
final List<YearMonthDay> dates = new ArrayList<YearMonthDay>();
final List<LocalDate> localDates = delegate.getIMMDates(start.toLocalDate(), end.toLocalDate());
@@ -117,19 +101,10 @@
}
@Override
- protected YearMonthDay getNextIMMDate(final boolean forward, final YearMonthDay start) {
- return new YearMonthDay(delegate.getNextIMMDate(forward, start.toLocalDate()));
+ protected YearMonthDay getNextIMMDate(final boolean forward, final YearMonthDay start, final IMMPeriod period) {
+ return new YearMonthDay(delegate.getNextIMMDate(forward, start.toLocalDate(), period));
}
- // @Override
- // public YearMonthDay setCurrentBusinessDate(YearMonthDay date) {
- // if (delegate != null) {
- // delegate.setCurrentBusinessDate(date != null ? date.toLocalDate() :
- // null);
- // }
- // return super.setCurrentBusinessDate(date);
- // }
-
@Override
public void setStartDate(final YearMonthDay startDate) {
if (delegate != null) {
@@ -138,4 +113,17 @@
super.setStartDate(startDate);
}
+ public List<YearMonthDay> getIMMDates(final YearMonthDay start, final YearMonthDay end, final IMMPeriod period) {
+ final List<YearMonthDay> dates = new ArrayList<YearMonthDay>();
+ final List<LocalDate> d = delegate.getIMMDates(start.toLocalDate(), end.toLocalDate(), period);
+ for (final LocalDate date : d) {
+ dates.add(new YearMonthDay(date));
+ }
+ return dates;
+ }
+
+ public boolean isIMMDate(final YearMonthDay date) {
+ return delegate.isIMMDate(date.toLocalDate());
+ }
+
}
Modified: trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/IMMDateTest.java
===================================================================
--- trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/IMMDateTest.java 2006-09-04 15:01:20 UTC (rev 96)
+++ trunk/datecalc-joda/src/test/java/net/objectlab/kit/datecalc/joda/IMMDateTest.java 2006-09-04 17:16:22 UTC (rev 97)
@@ -6,6 +6,7 @@
import junit.framework.TestCase;
import net.objectlab.kit.datecalc.common.DateCalculator;
import net.objectlab.kit.datecalc.common.HolidayHandlerType;
+import net.objectlab.kit.datecalc.common.IMMPeriod;
import net.objectlab.kit.datecalc.common.StandardTenor;
import org.joda.time.LocalDate;
@@ -80,6 +81,65 @@
Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2007-03-21"), cal.getNextIMMDate());
}
+ public void testNextIMMWithPeriod() {
+ final DateCalculator<LocalDate> cal = DefaultLocalDateCalculatorFactory.getDefaultInstance().getDateCalculator("bla",
+ HolidayHandlerType.FORWARD);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ final LocalDate startDate = new LocalDate("2006-08-01");
+ cal.setStartDate(startDate);
+
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-09-20"), cal.getNextIMMDate());
+
+ cal.setStartDate(new LocalDate("2006-01-09"));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-03-15"), cal.getNextIMMDate(IMMPeriod.QUARTERLY));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-06-21"), cal
+ .getNextIMMDate(IMMPeriod.BI_ANNUALY_JUN_DEC));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-03-15"), cal
+ .getNextIMMDate(IMMPeriod.BI_ANNUALY_MAR_SEP));
+
+ cal.setStartDate(new LocalDate("2006-03-20"));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-06-21"), cal.getNextIMMDate(IMMPeriod.QUARTERLY));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-06-21"), cal
+ .getNextIMMDate(IMMPeriod.BI_ANNUALY_JUN_DEC));
+ Assert.assertEquals("From " + cal.getStartDate(), new LocalDate("2006-09-20"), cal
+ .getNextIMMDate(IMMPeriod.BI_ANNUALY_MAR_SEP));
+ }
+
+ public void testIfIMMDate() {
+ final DateCalculator<LocalDate> cal = DefaultLocalDateCalculatorFactory.getDefaultInstance().getDateCalculator("bla",
+ HolidayHandlerType.FORWARD);
+ Assert.assertEquals("Name", "bla", cal.getName());
+ Assert.assertEquals("Holidays size", 0, cal.getNonWorkingDays().size());
+
+ final LocalDate startDate = new LocalDate("2006-08-01");
+ cal.setStartDate(startDate);
+
+ checkImm(cal, new LocalDate("2006-08-01"), false);
+
+ checkImm(cal, new LocalDate("2006-03-14"), false);
+ checkImm(cal, new LocalDate("2006-03-15"), true);
+ checkImm(cal, new LocalDate("2006-03-16"), false);
+
+ checkImm(cal, new LocalDate("2006-06-20"), false);
+ checkImm(cal, new LocalDate("2006-06-21"), true);
+ checkImm(cal, new LocalDate("2006-06-22"), false);
+
+ checkImm(cal, new LocalDate("2006-09-19"), false);
+ checkImm(cal, new LocalDate("2006-09-20"), true);
+ checkImm(cal, new LocalDate("2006-09-21"), false);
+
+ checkImm(cal, new LocalDate("2006-12-19"), false);
+ checkImm(cal, new LocalDate("2006-12-20"), true);
+ checkImm(cal, new LocalDate("2006-12-21"), false);
+
+ }
+
+ private void checkImm(final DateCalculator<LocalDate> cal, final LocalDate date, final boolean expected) {
+ assertEquals("check " + date, expected, cal.isIMMDate(date));
+ }
+
public void testMoveByIMMTenor() {
final DateCalculator<LocalDate> cal = DefaultLocalDateCalculatorFactory.getDefaultInstance().getDateCalculator("bla",
HolidayHandlerType.FORWARD);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|