Example usage for org.joda.time LocalDate plusDays

List of usage examples for org.joda.time LocalDate plusDays

Introduction

In this page you can find the example usage for org.joda.time LocalDate plusDays.

Prototype

public LocalDate plusDays(int days) 

Source Link

Document

Returns a copy of this date plus the specified number of days.

Usage

From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java

License:Apache License

private LocalDate deriveLockinPeriodDuration(final Integer lockinPeriod, final PeriodFrequencyType periodType,
        LocalDate purchaseDate) {
    LocalDate lockinDate = purchaseDate;
    if (periodType != null) {
        switch (periodType) {
        case INVALID: //It never comes in to this state.
            break;
        case DAYS:
            lockinDate = purchaseDate.plusDays(lockinPeriod);
            break;
        case WEEKS:
            lockinDate = purchaseDate.plusWeeks(lockinPeriod);
            break;
        case MONTHS:
            lockinDate = purchaseDate.plusMonths(lockinPeriod);
            break;
        case YEARS:
            lockinDate = purchaseDate.plusYears(lockinPeriod);
            break;
        }//from  w  w w . ja  va  2  s .  c  om
    }
    return lockinDate;
}

From source file:com.gst.portfolio.tax.serialization.TaxValidator.java

License:Apache License

private void validateGroupTotal(final Set<TaxGroupMappings> taxMappings,
        final DataValidatorBuilder baseDataValidator, final String paramenter) {
    for (TaxGroupMappings groupMappingsOne : taxMappings) {
        Collection<LocalDate> dates = groupMappingsOne.getTaxComponent().allStartDates();
        for (LocalDate date : dates) {
            LocalDate applicableDate = date.plusDays(1);
            BigDecimal total = BigDecimal.ZERO;
            for (TaxGroupMappings groupMappings : taxMappings) {
                if (groupMappings.occursOnDayFromAndUpToAndIncluding(applicableDate)) {
                    BigDecimal applicablePercentage = groupMappings.getTaxComponent()
                            .getApplicablePercentage(applicableDate);
                    if (applicablePercentage != null) {
                        total = total.add(applicablePercentage);
                    }/*from  www  .j a va  2s.  c  o  m*/
                }
            }
            baseDataValidator.reset().parameter(paramenter).value(total)
                    .notGreaterThanMax(BigDecimal.valueOf(100));
        }
    }
}

From source file:com.helger.datetime.holiday.CalendarUtil.java

License:Apache License

/**
 * Searches for the occurrences of a month/day in one chronology within one
 * gregorian year.//from   w  w  w.  j av  a  2 s. co m
 *
 * @param nTargetMonth
 *        Target month
 * @param nTargetDay
 *        Target day
 * @param nGregorianYear
 *        Gregorian year
 * @param aTargetChronoUTC
 *        Target chronology
 * @return the list of gregorian dates.
 */
@Nonnull
public static Set<LocalDate> getDatesFromChronologyWithinGregorianYear(final int nTargetMonth,
        final int nTargetDay, final int nGregorianYear, final Chronology aTargetChronoUTC) {
    final Set<LocalDate> aHolidays = new HashSet<LocalDate>();
    final LocalDate aFirstGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.JANUARY,
            1);
    final LocalDate aLastGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.DECEMBER,
            31);

    final LocalDate aFirstTargetDate = new LocalDate(
            aFirstGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(),
            aTargetChronoUTC);
    final LocalDate aLastTargetDate = new LocalDate(
            aLastGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(),
            aTargetChronoUTC);

    final Interval aInterv = new Interval(
            aFirstTargetDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()),
            aLastTargetDate.plusDays(1).toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()));

    for (int nTargetYear = aFirstTargetDate.getYear(); nTargetYear <= aLastTargetDate
            .getYear(); ++nTargetYear) {
        final LocalDate aLocalDate = new LocalDate(nTargetYear, nTargetMonth, nTargetDay, aTargetChronoUTC);
        if (aInterv.contains(aLocalDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()))) {
            aHolidays.add(convertToGregorianDate(aLocalDate));
        }
    }
    return aHolidays;
}

From source file:com.helger.datetime.holiday.CalendarUtil.java

License:Apache License

/**
 * Get the next working day based on the current day. If the current day is a
 * working day, the current day is returned. A working day is determined by:
 * it's not a weekend day (usually Saturday and Sunday).
 *
 * @return The next matching date./*from   w ww. ja  v a 2s.com*/
 * @see PDTUtils#isWorkDay(LocalDate)
 */
@Nonnull
public static LocalDate getCurrentOrNextWorkDay() {
    LocalDate aDT = PDTFactory.getCurrentLocalDate();
    while (!PDTUtils.isWorkDay(aDT))
        aDT = aDT.plusDays(1);
    return aDT;
}

From source file:com.helger.datetime.holiday.HolidayUtils.java

License:Apache License

/**
 * Get the number of working days between start date (incl.) and end date
 * (incl.). An optional holiday calculator can be used as well.
 * //from  w w  w.j  a  v  a 2 s .com
 * @param aStartDate
 *        The start date. May not be <code>null</code>.
 * @param aEndDate
 *        The end date. May not be <code>null</code>.
 * @param aHolidayMgr
 *        The holiday calculator to use. May not be <code>null</code>.
 * @return The number of working days. If start date is after end date, the
 *         value will be negative! If start date equals end date the return
 *         will be 1 if it is a working day.
 */
public static int getWorkingDays(@Nonnull final LocalDate aStartDate, @Nonnull final LocalDate aEndDate,
        @Nonnull final IHolidayManager aHolidayMgr) {
    if (aStartDate == null)
        throw new NullPointerException("startDate");
    if (aEndDate == null)
        throw new NullPointerException("endDate");
    if (aHolidayMgr == null)
        throw new NullPointerException("holidayCalc");

    final boolean bFlip = aStartDate.isAfter(aEndDate);
    LocalDate aCurDate = bFlip ? aEndDate : aStartDate;
    final LocalDate aRealEndDate = bFlip ? aStartDate : aEndDate;

    int ret = 0;
    while (!aRealEndDate.isBefore(aCurDate)) {
        if (isWorkDay(aCurDate, aHolidayMgr))
            ret++;
        aCurDate = aCurDate.plusDays(1);
    }
    return bFlip ? -1 * ret : ret;
}

From source file:com.helger.datetime.holiday.HolidayUtils.java

License:Apache License

/**
 * Get the next working day based on the current day. If the current day is a
 * working day, the current day is returned. A working day is determined by:
 * it's not a weekend day (usually Saturday and Sunday) and it's not a holiday
 * (based on the holiday manager).//from w ww  . java  2s.c om
 * 
 * @param aHolidayMgr
 *        An optional holiday calculator to be used. May be <code>null</code>.
 * @return The next matching date.
 * @see HolidayUtils#isWorkDay(LocalDate, IHolidayManager)
 * @see CalendarUtil#getCurrentOrNextWorkDay()
 */
@Nonnull
public static LocalDate getCurrentOrNextWorkDay(@Nullable final IHolidayManager aHolidayMgr) {
    if (aHolidayMgr == null)
        return CalendarUtil.getCurrentOrNextWorkDay();
    LocalDate aDT = PDTFactory.getCurrentLocalDate();
    while (!isWorkDay(aDT, aHolidayMgr))
        aDT = aDT.plusDays(1);
    return aDT;
}

From source file:com.helger.datetime.holiday.parser.AbstractHolidayParser.java

License:Apache License

/**
 * Moves the date using the FixedMoving information
 * //from   w  w  w.  j  a  v a  2  s.c  om
 * @param aMoveCond
 * @param aDate
 * @return The moved date
 */
private static LocalDate _moveDate(final MovingCondition aMoveCond, final LocalDate aDate) {
    final int nWeekday = XMLUtil.getWeekday(aMoveCond.getWeekday());
    final int nDirection = aMoveCond.getWith() == With.NEXT ? 1 : -1;

    LocalDate aMovedDate = aDate;
    while (aMovedDate.getDayOfWeek() != nWeekday) {
        aMovedDate = aMovedDate.plusDays(nDirection);
    }
    return aMovedDate;
}

From source file:com.helger.datetime.holiday.parser.impl.ChristianHolidayParser.java

License:Apache License

/**
 * {@inheritDoc} Parses all christian holidays relative to eastern.
 *///from   w ww  . jav a 2 s . c om
@Override
public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) {
    for (final ChristianHoliday aChristianHoliday : aConfig.getChristianHoliday()) {
        if (!isValid(aChristianHoliday, nYear))
            continue;

        LocalDate aEasterSunday;
        if (aChristianHoliday.getChronology() == ChronologyType.JULIAN)
            aEasterSunday = getJulianEasterSunday(nYear);
        else if (aChristianHoliday.getChronology() == ChronologyType.GREGORIAN)
            aEasterSunday = getGregorianEasterSunday(nYear);
        else
            aEasterSunday = getEasterSunday(nYear);

        switch (aChristianHoliday.getType()) {
        case EASTER:
            break;
        case CLEAN_MONDAY:
        case SHROVE_MONDAY:
            aEasterSunday = aEasterSunday.minusDays(48);
            break;
        case MARDI_GRAS:
        case CARNIVAL:
            aEasterSunday = aEasterSunday.minusDays(47);
            break;
        case ASH_WEDNESDAY:
            aEasterSunday = aEasterSunday.minusDays(46);
            break;
        case MAUNDY_THURSDAY:
            aEasterSunday = aEasterSunday.minusDays(3);
            break;
        case GOOD_FRIDAY:
            aEasterSunday = aEasterSunday.minusDays(2);
            break;
        case EASTER_SATURDAY:
            aEasterSunday = aEasterSunday.minusDays(1);
            break;
        case EASTER_MONDAY:
            aEasterSunday = aEasterSunday.plusDays(1);
            break;
        case EASTER_TUESDAY:
            aEasterSunday = aEasterSunday.plusDays(2);
            break;
        case GENERAL_PRAYER_DAY:
            aEasterSunday = aEasterSunday.plusDays(26);
            break;
        case ASCENSION_DAY:
            aEasterSunday = aEasterSunday.plusDays(39);
            break;
        case PENTECOST:
        case WHIT_SUNDAY:
            aEasterSunday = aEasterSunday.plusDays(49);
            break;
        case WHIT_MONDAY:
        case PENTECOST_MONDAY:
            aEasterSunday = aEasterSunday.plusDays(50);
            break;
        case CORPUS_CHRISTI:
            aEasterSunday = aEasterSunday.plusDays(60);
            break;
        case SACRED_HEART:
            aEasterSunday = aEasterSunday.plusDays(68);
            break;
        default:
            throw new IllegalArgumentException("Unknown christian holiday type " + aChristianHoliday.getType());
        }
        final LocalDate aConvertedDate = CalendarUtil.convertToGregorianDate(aEasterSunday);
        final IHolidayType aType = XMLUtil.getType(aChristianHoliday.getLocalizedType());
        final String sPropertiesKey = "christian." + aChristianHoliday.getType().name();
        addChrstianHoliday(aConvertedDate, sPropertiesKey, aType, aHolidayMap);
    }
}

From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayBetweenFixedParser.java

License:Apache License

/**
 * Parses the provided configuration and creates holidays for the provided
 * year.//www.ja v  a2s .  c om
 */
public void parse(final int nYear, final HolidayMap aHolidayMap, final Holidays aConfig) {
    for (final FixedWeekdayBetweenFixed aFixedWeekdayBetweenFixed : aConfig.getFixedWeekdayBetweenFixed()) {
        if (!isValid(aFixedWeekdayBetweenFixed, nYear))
            continue;

        final int nExpectedWeekday = XMLUtil.getWeekday(aFixedWeekdayBetweenFixed.getWeekday());
        LocalDate aFrom = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getFrom());
        final LocalDate aTo = XMLUtil.create(nYear, aFixedWeekdayBetweenFixed.getTo());
        LocalDate aResult = null;
        while (!aFrom.isAfter(aTo)) {
            if (aFrom.getDayOfWeek() == nExpectedWeekday) {
                aResult = aFrom;
                break;
            }
            aFrom = aFrom.plusDays(1);
        }

        if (aResult != null) {
            final IHolidayType aType = XMLUtil.getType(aFixedWeekdayBetweenFixed.getLocalizedType());
            final String sPropertyKey = aFixedWeekdayBetweenFixed.getDescriptionPropertiesKey();
            aHolidayMap.add(aResult, new ResourceBundleHoliday(aType, sPropertyKey));
        }
    }
}

From source file:com.helger.datetime.holiday.parser.impl.FixedWeekdayInMonthParser.java

License:Apache License

protected static LocalDate parse(final int nYear, final FixedWeekdayInMonth aFixedWeekdayInMonth) {
    LocalDate aDate = PDTFactory.createLocalDate(nYear, XMLUtil.getMonth(aFixedWeekdayInMonth.getMonth()), 1);
    int nDirection = 1;
    if (aFixedWeekdayInMonth.getWhich() == Which.LAST) {
        aDate = aDate.withDayOfMonth(aDate.dayOfMonth().getMaximumValue());
        nDirection = -1;//from  ww w  . j a  v a  2 s .c om
    }
    final int nWeekDay = XMLUtil.getWeekday(aFixedWeekdayInMonth.getWeekday());
    while (aDate.getDayOfWeek() != nWeekDay) {
        aDate = aDate.plusDays(nDirection);
    }
    switch (aFixedWeekdayInMonth.getWhich()) {
    case FIRST:
        break;
    case SECOND:
        aDate = aDate.plusDays(7);
        break;
    case THIRD:
        aDate = aDate.plusDays(14);
        break;
    case FOURTH:
        aDate = aDate.plusDays(21);
        break;
    case LAST:
        break;
    }
    return aDate;
}