|
From: <be...@us...> - 2006-08-24 13:58:15
|
Revision: 48 Author: benoitx Date: 2006-08-24 06:57:57 -0700 (Thu, 24 Aug 2006) ViewCVS: http://svn.sourceforge.net/objectlabkit/?rev=48&view=rev Log Message: ----------- Move more functionality to the AbstractDateCalculator. Got a bit stuck on WorkingWeek, may be that could be <parameterised>... Modified Paths: -------------- 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-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/BaseDateCalculator.java trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/ForwardHandler.java trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/Utils.java trunk/datecalc-joda/maven.xml trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/BaseDateCalculator.java trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java Property Changed: ---------------- trunk/datecalc-joda/ 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-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/AbstractDateCalculator.java 2006-08-24 13:57:57 UTC (rev 48) @@ -1,19 +1,33 @@ package net.objectlab.kit.datecalc.common; import java.util.Collections; +import java.util.HashSet; import java.util.Set; public abstract class AbstractDateCalculator<E> implements DateCalculator<E> { protected static final int MONTHS_IN_QUARTER = 3; + protected static final int MONTH_IN_YEAR = 12; + protected static final int DAYS_IN_WEEK = 7; - protected String name; + + private String name; + protected E startDate; + protected E currentDate; + protected Set<E> nonWorkingDays; + protected HolidayHandler<E> holidayHandler; - + + protected AbstractDateCalculator(final String name, final Set<E> nonWorkingDays, final HolidayHandler<E> holidayHandler) { + this.name = name; + this.nonWorkingDays = nonWorkingDays; + this.holidayHandler = holidayHandler; + } + public String getName() { return name; } @@ -39,7 +53,7 @@ public Set<E> getNonWorkingDays() { return Collections.unmodifiableSet(nonWorkingDays); } - + public void setNonWorkingDays(final Set<E> holidays) { if (holidays == null) { nonWorkingDays = Collections.emptySet(); @@ -61,7 +75,7 @@ if (tenor == null) { throw new IllegalArgumentException("Tenor cannot be null"); } - + switch (tenor.getCode()) { case DAY: return moveByDays(tenor.getUnits()); @@ -73,7 +87,7 @@ default: throw new UnsupportedOperationException("Sorry not yet..."); } - + } public void setHolidayHandler(final HolidayHandler<E> holidayHandler) { @@ -84,4 +98,91 @@ return (holidayHandler != null ? holidayHandler.getType() : null); } + /** + * is the given date a non working day? + */ + public boolean isNonWorkingDay(final E date) { + return (isWeekend(date) || nonWorkingDays.contains(date)); + } + + public boolean isCurrentDateNonWorking() { + return isNonWorkingDay(currentDate); + } + + public E setCurrentBusinessDate(final E date) { + currentDate = date; + if (holidayHandler != null && date != null) { + currentDate = holidayHandler.moveCurrentDate(this); + } + return currentDate; + } + + protected HolidayHandler<E> getHolidayHandler() { + return holidayHandler; + } + + public DateCalculator<E> moveByBusinessDays(final int businessDays) { + final int numberOfStepsLeft = Math.abs(businessDays); + final int step = (businessDays < 0 ? -1 : 1); + + for (int i = 0; i < numberOfStepsLeft; i++) { + moveByDays(step); + } + + return this; + } + + /** + * Allows DateCalculators to be combined into a new one, the startDate and + * currentDate will be the ones from the existing calendar (not the + * parameter one). The name will be combined name1+"/"+calendar.getName(). + * + * @param calendar, + * return the same DateCalculator if calender is null or the + * original calendar (but why would you want to do that?) + * @throws IllegalArgumentException + * if both calendars have different types of HolidayHandlers or + * WorkingWeek; + */ + public DateCalculator<E> combine(final DateCalculator<E> calendar) { + if (calendar == null || calendar == this) { + return this; + } + + if (holidayHandler == null && calendar.getHolidayHandlerType() != null || holidayHandler != null + && !holidayHandler.getType().equals(calendar.getHolidayHandlerType())) { + throw new IllegalArgumentException("Combined Calendars cannot have different handler types"); + } + + final Set<E> newSet = new HashSet<E>(); + if (nonWorkingDays != null) { + newSet.addAll(nonWorkingDays); + } + if (calendar.getNonWorkingDays() != null) { + newSet.addAll(calendar.getNonWorkingDays()); + } + + final DateCalculator<E> cal = createNewCalcultaor(getName() + "/" + calendar.getName(), getStartDate(), newSet, + holidayHandler); + + return cal; + } + + /** + * @return the next IMMDate based on current date. + */ + public E getNextIMMDate() { + return getNextIMMDate(true, currentDate); + } + + /** + * @return the previous IMMDate based on current date. + */ + public E getPreviousIMMDate() { + return getNextIMMDate(false, currentDate); + } + + protected abstract E getNextIMMDate(final boolean forward, final E startDate); + + protected abstract DateCalculator<E> createNewCalcultaor(String name, E startDate, 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-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-common/src/main/java/net/objectlab/kit/datecalc/common/DateCalculator.java 2006-08-24 13:57:57 UTC (rev 48) @@ -3,14 +3,13 @@ import java.util.List; import java.util.Set; - public interface DateCalculator<E> { /** * @return Calendar name (Typically the name associated with the holiday * set). */ - public String getName(); + String getName(); /** * @param startDate @@ -18,33 +17,34 @@ * updated and may be moved if it falls on a non working day * (holiday/weekend). */ - public void setStartDate(final E startDate); + void setStartDate(final E startDate); /** * @return startDate the reference date for this calendar. */ - public E getStartDate(); + E getStartDate(); /** - * @param currentDate held by the calendar. + * @param currentDate + * held by the calendar. */ - public E getCurrentDate(); + E getCurrentDate(); /** * is the given date on a weekend, according to the WorkingWeek */ - public boolean isWeekend(final E date); + boolean isWeekend(final E date); /** * is the given date a non working day, i.e. either a "weekend" or a * holiday? */ - public boolean isNonWorkingDay(final E date); + boolean isNonWorkingDay(final E date); /** * @return true if the current date is either a weekend or a holiday. */ - public boolean isCurrentDateNonWorking(); + boolean isCurrentDateNonWorking(); /** * This is typically used at the construction of a DateCalculator. @@ -52,12 +52,12 @@ * @param holidays * the holiday (if null, an empty set will be put in place) */ - public void setNonWorkingDays(final Set<E> holidays); + void setNonWorkingDays(final Set<E> holidays); /** * @return an immutable copy of the holiday set. */ - public Set<E> getNonWorkingDays(); + Set<E> getNonWorkingDays(); /** * Allow user to define what their Working Week should be (default is @@ -65,7 +65,7 @@ * * @param week */ - public void setWorkingWeek(final WorkingWeek week); + void setWorkingWeek(final WorkingWeek week); /** * give a current business date which may be moved if it falls on a non @@ -74,12 +74,12 @@ * @param date * @return new current date if moved. */ - public E setCurrentBusinessDate(final E date); + E setCurrentBusinessDate(final E date); /** * @return the holiday handler type, can be null */ - public String getHolidayHandlerType(); + String getHolidayHandlerType(); /** * move the current date by the number of days and, if it falls on a weekend @@ -91,7 +91,7 @@ * @return the businessCalendar (so one can do * calendar.moveByDays(-2).getCurrentBusinessDate();) */ - public DateCalculator<E> moveByDays(final int days); + DateCalculator<E> moveByDays(final int days); /** * move the current date by a number of business days, this means that if a @@ -102,7 +102,7 @@ * @return the current businessCalendar (so one can do * calendar.moveByBusinessDays(2).getCurrentBusinessDate();) */ - public DateCalculator<E> moveByBusinessDays(final int businessDays); + DateCalculator<E> moveByBusinessDays(final int businessDays); /** * By combining several calendars, we take into account several set of @@ -111,7 +111,7 @@ * @param calendar * @return a new DateCalculator */ - public DateCalculator<E> combine(DateCalculator<E> calendar); + DateCalculator<E> combine(DateCalculator<E> calendar); /** * move the current date by a given tenor, this means that if a date is @@ -122,17 +122,17 @@ * @return the current businessCalendar (so one can do * calendar.moveByTenor(StandardTenor.T_2M).getCurrentBusinessDate();) */ - public DateCalculator<E> moveByTenor(final Tenor tenor); + DateCalculator<E> moveByTenor(final Tenor tenor); /** * @return the next IMMDate based on current date. */ - public E getNextIMMDate(); + E getNextIMMDate(); /** * @return the previous IMMDate based on current date. */ - public E getPreviousIMMDate(); + E getPreviousIMMDate(); /** * Returns a list of IMM dates between 2 dates, it will exclude the start @@ -144,6 +144,5 @@ * end of the interval, may be included. * @return list of IMM dates */ - public List<E> getIMMDates(final E start, final E end); - + List<E> getIMMDates(final E start, final E end); } \ No newline at end of file Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/BaseDateCalculator.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/BaseDateCalculator.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/BaseDateCalculator.java 2006-08-24 13:57:57 UTC (rev 48) @@ -19,7 +19,6 @@ import java.util.Calendar; import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -44,17 +43,10 @@ this(null, null, Collections.EMPTY_SET, null); } - @SuppressWarnings("unchecked") - public BaseDateCalculator(final HolidayHandler holidayHandler) { - this(null, null, Collections.EMPTY_SET, holidayHandler); - } - public BaseDateCalculator(final String name, final Date startDate, final Set<Date> nonWorkingDays, - final HolidayHandler holidayHandler) { - this.name = name; + final HolidayHandler<Date> holidayHandler) { + super(name, nonWorkingDays, holidayHandler); setStartDate(startDate); - this.nonWorkingDays = nonWorkingDays; - this.holidayHandler = holidayHandler; } public void setWorkingWeek(final WorkingWeek week) { @@ -69,31 +61,12 @@ return !workingWeek.isWorkingDay(date); } - /** - * is the given date a non working day? - */ - public boolean isNonWorkingDay(final Date date) { - return (isWeekend(date) || nonWorkingDays.contains(date)); - } - - public boolean isCurrentDateNonWorking() { - return isNonWorkingDay(currentDate); - } - - public Date setCurrentBusinessDate(final Date date) { - currentDate = date; - if (holidayHandler != null && date != null) { - currentDate = holidayHandler.moveCurrentDate(this); - } - return currentDate; - } - public DateCalculator<Date> moveByDays(final int days) { if (currentDate == null) { initialise(); } - Calendar cal = Utils.getCal(currentDate); + final Calendar cal = Utils.getCal(currentDate); cal.add(Calendar.DAY_OF_MONTH, days); setCurrentBusinessDate(cal.getTime()); @@ -108,62 +81,22 @@ } } - public DateCalculator<Date> moveByBusinessDays(final int businessDays) { - final int numberOfStepsLeft = Math.abs(businessDays); - final int step = (businessDays < 0 ? -1 : 1); - - for (int i = 0; i < numberOfStepsLeft; i++) { - moveByDays(step); - } - - return this; + @Override + protected DateCalculator<Date> createNewCalcultaor(final String name, final Date startDate, final Set<Date> holidays, + final HolidayHandler<Date> handler) { + return new BaseDateCalculator(name, startDate, holidays, handler); } - + + /** - * Allows DateCalculators to be combined into a new one, the startDate and - * currentDate will be the ones from the existing calendar (not the - * parameter one). The name will be combined name1+"/"+calendar.getName(). + * Calculates IMMDates between a start and end dates the 3rd wednesday of + * Mar/Jun/Sep/Dec when a lot of derivative contracts expire * - * @param calendar, - * return the same DateCalculator if calender is null or the - * original calendar (but why would you want to do that?) - * @throws IllegalArgumentException - * if both calendars have different types of HolidayHandlers or - * WorkingWeek; - */ - public DateCalculator<Date> combine(final DateCalculator calendar) { - if (calendar == null || calendar == this) { - return this; - } - - if (holidayHandler == null && calendar.getHolidayHandlerType() != null || holidayHandler != null - && !holidayHandler.getType().equals(calendar.getHolidayHandlerType())) { - throw new IllegalArgumentException("Combined Calendars cannot have different handler types"); - } - - final Set<Date> newSet = new HashSet<Date>(); - if (nonWorkingDays != null) { - newSet.addAll(nonWorkingDays); - } - if (calendar.getNonWorkingDays() != null) { - newSet.addAll(calendar.getNonWorkingDays()); - } - - final DateCalculator cal = new BaseDateCalculator(getName() + "/" + calendar.getName(), getStartDate(), newSet, - holidayHandler); - - return cal; - } - - /** - * Calculates IMMDates between a start and end dates - * the 3rd wednesday of Mar/Jun/Sep/Dec - * when a lot of derivative contracts expire * @return a List of Dates */ public List<Date> getIMMDates(final Date start, final Date end) { - List<Date> dates = new ArrayList<Date>(); + final List<Date> dates = new ArrayList<Date>(); Date date = start; while (true) { date = getNextIMMDate(true, date); @@ -177,28 +110,21 @@ return dates; } - public Date getNextIMMDate() { - return getNextIMMDate(true, currentDate); - } - - public Date getPreviousIMMDate() { - return getNextIMMDate(false, currentDate); - } - - private Date getNextIMMDate(final boolean forward, final Date startDate) { + @Override + protected Date getNextIMMDate(final boolean forward, final Date startDate) { - Calendar cal = Utils.getCal(startDate); + final Calendar cal = Utils.getCal(startDate); if (isIMMMonth(cal)) { moveToIMMDay(cal); - //TODO simplify this if condition + // TODO simplify this if condition if ((forward && cal.getTime().after(startDate)) || (!forward && cal.getTime().before(startDate))) { return cal.getTime(); } } - int delta = (forward ? 1 : -1); + final int delta = (forward ? 1 : -1); do { cal.add(Calendar.MONTH, delta); } while (!isIMMMonth(cal)); @@ -208,7 +134,7 @@ } private boolean isIMMMonth(final Calendar cal) { - int month = cal.get(Calendar.MONTH); + final int month = cal.get(Calendar.MONTH); return (month == Calendar.MARCH || month == Calendar.JUNE || month == Calendar.SEPTEMBER || month == Calendar.DECEMBER); } @@ -223,7 +149,7 @@ cal.set(Calendar.DAY_OF_MONTH, 1); // go to 1st wed - int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); + final int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if (dayOfWeek < Calendar.WEDNESDAY) { cal.add(Calendar.DAY_OF_MONTH, Calendar.WEDNESDAY - dayOfWeek); } else if (dayOfWeek == Calendar.WEDNESDAY) { @@ -235,5 +161,4 @@ // go to 3rd wednesday - i.e. move 2 weeks forward cal.add(Calendar.DAY_OF_MONTH, 7 * 2); } - } Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/DefaultDateCalculatorFactory.java 2006-08-24 13:57:57 UTC (rev 48) @@ -55,9 +55,9 @@ } else { throw new UnsupportedOperationException("only forward supported"); } - + return cal; - + // } else if (HolidayHandlerType.BACKWARD.equals(holidayHandlerType)) { // cal.setHolidayHandler(new BackwardHandler()); // } else if Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/ForwardHandler.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/ForwardHandler.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/ForwardHandler.java 2006-08-24 13:57:57 UTC (rev 48) @@ -25,18 +25,18 @@ /** * * @author Marcin Jekot - * + * */ public class ForwardHandler implements HolidayHandler<Date> { - public Date moveCurrentDate(DateCalculator<Date> calendar) { - - Calendar cal = Utils.getCal(calendar.getCurrentDate()); + public Date moveCurrentDate(final DateCalculator<Date> calendar) { + final Calendar cal = Utils.getCal(calendar.getCurrentDate()); + while (calendar.isNonWorkingDay(cal.getTime())) { cal.add(Calendar.DAY_OF_MONTH, 1); } - + return cal.getTime(); } Modified: trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/Utils.java =================================================================== --- trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/Utils.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-jdk/src/main/java/net/objectlab/kit/datecalc/jdk/Utils.java 2006-08-24 13:57:57 UTC (rev 48) @@ -21,14 +21,14 @@ /** * * @author Marcin Jekot - * + * */ public class Utils { public static Calendar getCal(final Date date) { - Calendar cal = Calendar.getInstance(); + final Calendar cal = Calendar.getInstance(); cal.setTime(date); return cal; } - + } Property changes on: trunk/datecalc-joda ___________________________________________________________________ Name: svn:ignore - target + target .fbwarnings Modified: trunk/datecalc-joda/maven.xml =================================================================== --- trunk/datecalc-joda/maven.xml 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-joda/maven.xml 2006-08-24 13:57:57 UTC (rev 48) @@ -1,31 +1,28 @@ <?xml version="1.0"?> -<!-- -/* - * ======================================================================== - * - * - * ======================================================================== - */ +<!-- + /* + * ======================================================================== + * ObjectLab Financial Ltd, proud sponsor of The Kit. + * ======================================================================== + */ --> -<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:artifact="artifact" xmlns:maven="jelly:org.apache.maven.jelly.tags.project.MavenTagLibrary"> - - <goal name="kit:rebuild" prereqs="kit:build" /> +<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" + xmlns:artifact="artifact" + xmlns:maven="jelly:org.apache.maven.jelly.tags.project.MavenTagLibrary"> - <goal name="kit:build" prereqs="jar:jar"> - <echo>ADD Common to full JAR</echo> - <ant:jar - basedir="target/classes" - jarfile="${maven.build.dir}/${maven.final.name}-full.jar" - update="yes" - > - <fileset dir="${basedir}/../datecalc-common/target/classes" - excludes="**/Test.class" - includes="**/*.class" - /> - </ant:jar> + <goal name="kit:rebuild" prereqs="clean,kit:build" /> - </goal> + <goal name="kit:build" prereqs="jar:jar"> + <echo>ADD Common classes to full JAR</echo> + <ant:jar basedir="target/classes" + jarfile="${maven.build.dir}/${pom.artifactId}-full-${pom.currentVersion}.jar" + update="yes"> + <fileset dir="${basedir}/../datecalc-common/target/classes" + excludes="**/Test.class" includes="**/*.class" /> + </ant:jar> + + </goal> </project> Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/BaseDateCalculator.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/BaseDateCalculator.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/BaseDateCalculator.java 2006-08-24 13:57:57 UTC (rev 48) @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,17 +44,10 @@ this(null, null, Collections.EMPTY_SET, null); } - @SuppressWarnings("unchecked") - public BaseDateCalculator(final HolidayHandler holidayHandler) { - this(null, null, Collections.EMPTY_SET, holidayHandler); - } - public BaseDateCalculator(final String name, final LocalDate startDate, final Set<LocalDate> nonWorkingDays, - final HolidayHandler holidayHandler) { - this.name = name; + final HolidayHandler<LocalDate> holidayHandler) { + super(name, nonWorkingDays, holidayHandler); setStartDate(startDate); - this.nonWorkingDays = nonWorkingDays; - this.holidayHandler = holidayHandler; } public void setWorkingWeek(final WorkingWeek week) { @@ -72,25 +64,6 @@ return !workingWeek.isWorkingDay(date); } - /** - * is the given date a non working day? - */ - public boolean isNonWorkingDay(final LocalDate date) { - return (isWeekend(date) || nonWorkingDays.contains(date)); - } - - public boolean isCurrentDateNonWorking() { - return isNonWorkingDay(currentDate); - } - - public LocalDate setCurrentBusinessDate(final LocalDate date) { - currentDate = date; - if (holidayHandler != null && date != null) { - currentDate = holidayHandler.moveCurrentDate(this); - } - return currentDate; - } - public DateCalculator<LocalDate> moveByDays(final int days) { if (currentDate == null) { initialise(); @@ -112,53 +85,11 @@ } } - public DateCalculator<LocalDate> moveByBusinessDays(final int businessDays) { - final int numberOfStepsLeft = Math.abs(businessDays); - final int step = (businessDays < 0 ? -1 : 1); - - for (int i = 0; i < numberOfStepsLeft; i++) { - moveByDays(step); - } - - return this; + @Override + protected DateCalculator<LocalDate> createNewCalcultaor(final String name, final LocalDate startDate,final Set<LocalDate> holidays,final HolidayHandler<LocalDate> handler) { + return new BaseDateCalculator(name, startDate, holidays, handler); } - - /** - * Allows DateCalculators to be combined into a new one, the startDate and - * currentDate will be the ones from the existing calendar (not the - * parameter one). The name will be combined name1+"/"+calendar.getName(). - * - * @param calendar, - * return the same DateCalculator if calender is null or the - * original calendar (but why would you want to do that?) - * @throws IllegalArgumentException - * if both calendars have different types of HolidayHandlers or - * WorkingWeek; - */ - public DateCalculator<LocalDate> combine(final DateCalculator calendar) { - if (calendar == null || calendar == this) { - return this; - } - - if (holidayHandler == null && calendar.getHolidayHandlerType() != null || holidayHandler != null - && !holidayHandler.getType().equals(calendar.getHolidayHandlerType())) { - throw new IllegalArgumentException("Combined Calendars cannot have different handler types"); - } - - final Set<LocalDate> newSet = new HashSet<LocalDate>(); - if (nonWorkingDays != null) { - newSet.addAll(nonWorkingDays); - } - if (calendar.getNonWorkingDays() != null) { - newSet.addAll(calendar.getNonWorkingDays()); - } - - final DateCalculator<LocalDate> cal = new BaseDateCalculator(getName() + "/" + calendar.getName(), getStartDate(), newSet, - holidayHandler); - - return cal; - } - + public List<LocalDate> getIMMDates(final LocalDate start, final LocalDate end) { final List<LocalDate> dates = new ArrayList<LocalDate>(); @@ -175,23 +106,9 @@ return dates; } - public LocalDate getNextIMMDate() { - return getNextIMMDate(true, currentDate); - } - - public LocalDate getPreviousIMMDate() { - return getNextIMMDate(false, currentDate); - } - - private LocalDate getNextIMMDate(final boolean forward, final LocalDate start) { + @Override + protected LocalDate getNextIMMDate(final boolean forward, final LocalDate start) { LocalDate date = start; - // Monday = 1 -> + 2 for 1st Wed + 14 | 7 + 3 - 1 = 9 - // Tuesday = 2 -> + 1 for 1st Wed + 14 - // Wednesday = 3 -> + 0 for 1st Wed + 14 - // Thursday = 4 -> + 6 for 1st Wed + 14 - // Friday = 5 -> + 5 for 1st Wed + 14 - // Saturday = 6 -> + 4 for 1st Wed + 14 - // Sunday = 7 -> + 3 for 1st Wed + 14 final int month = date.getMonthOfYear(); int monthOffset = 0; @@ -207,17 +124,6 @@ } else if (!forward && !date.isAfter(immDate)) { date = date.minusMonths(MONTHS_IN_QUARTER); } - // - // final int day = date.getDayOfMonth(); - // final int immDay = calculateIMMDay(date); - // if (forward && day >= immDay || !forward && day <= immDay) { - // monthOffset = 3; - // if (forward) { - // date = date.plusMonths(monthOffset); - // } else { - // date = date.minusMonths(monthOffset); - // } - // } break; default: @@ -244,8 +150,6 @@ } return calculate3rdWednesday(date); - - // return date.dayOfMonth().setCopy(calculateIMMDay(date)); } /** @@ -263,5 +167,4 @@ } return firstWed.plusWeeks(2); } - } Modified: trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java =================================================================== --- trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java 2006-08-24 13:49:09 UTC (rev 47) +++ trunk/datecalc-joda/src/main/java/net/objectlab/kit/datecalc/joda/DefaultPeriodCountCalculator.java 2006-08-24 13:57:57 UTC (rev 48) @@ -82,7 +82,7 @@ final int diff1 = new Period(start, endOfStartYear, PeriodType.days()).getDays(); final int diff2 = new Period(startOfEndYear, end, PeriodType.days()).getDays(); - diff = (diff1 + 1.0) / (double) start.dayOfYear().getMaximumValue() + (endYear - startYear - 1.0) + (diff2) + diff = (diff1 + 1.0) / start.dayOfYear().getMaximumValue() + (endYear - startYear - 1.0) + (diff2) / (double) end.dayOfYear().getMaximumValue(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |