Example usage for org.joda.time LocalDate minus

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

Introduction

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

Prototype

public LocalDate minus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this date with the specified period taken away.

Usage

From source file:com.mbc.jfin.daycount.impl.calculator.AFBActualActualDaycountCalculator.java

License:Open Source License

public double calculateDaycountFraction(SchedulePeriod period) {
    int daysBetween = DateUtils.daysBetween(period.getStart(), period.getEnd());

    if (daysBetween == 0)
        return 0;

    LocalDate newD2 = period.getEnd();
    LocalDate temp = period.getEnd();

    double sum = 0.0;
    while (temp.isAfter(period.getStart())) {
        temp = newD2;//from   w  w  w. j a  va2 s  .  c o  m
        temp = temp.minus(Years.ONE);
        if (temp.getDayOfMonth() == 28 && temp.getMonthOfYear() == 2 && DateUtils.isLeapYear(temp)) {
            temp = temp.plus(Days.ONE);
        }
        if (temp.isAfter(period.getStart()) || temp.equals(period.getStart())) {
            sum += 1.0;
            newD2 = temp;
        }
    }

    double den = 365.0;

    if (DateUtils.isLeapYear(newD2)) {
        temp = newD2;

        temp = new LocalDate(temp.getYear(), 2, 29);

        if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp)))
            den += 1.0;
    } else if (DateUtils.isLeapYear(period.getStart())) {

        temp = new LocalDate(period.getStart().getYear(), 2, 29);

        if (newD2.isAfter(temp) && (period.getStart().isBefore(temp) || period.getStart().equals(temp)))
            den += 1.0;
    }

    return sum + DateUtils.daysBetween(period.getStart(), newD2) / den;

}

From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java

License:Open Source License

public LocalDate preceding(LocalDate calendar, HolidayCalendar holidayCalendar) {
    LocalDate d1 = calendar;
    while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) {
        d1 = d1.minus(Days.ONE);
    }/*from   w w  w  .jav a 2 s  .co m*/
    return d1;
}

From source file:com.mbc.jfin.holiday.impl.DefaultDateAdjustmentServiceImpl.java

License:Open Source License

public LocalDate modPreceding(LocalDate calendar, HolidayCalendar holidayCalendar) {
    LocalDate d1 = calendar;
    while (holidayCalendar.isHoliday(d1) || holidayCalendar.isWeekend(d1)) {
        d1 = d1.minus(Days.ONE);
    }//from ww  w. j  a v a 2s  .  co  m

    if (d1.getMonthOfYear() != calendar.getMonthOfYear()) {
        return following(calendar, holidayCalendar);
    }

    return d1;
}

From source file:com.mbc.jfin.schedule.impl.LongFirstStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = end;//  w w  w .  ja v  a2  s. c o  m

    int periodCount = 1;

    while (holdDate.isAfter(start)) {
        LocalDate nextDate = end.minus(multiplyPeriod(frequency, periodCount));

        LocalDate nextDate2 = end.minus(multiplyPeriod(frequency, periodCount + 1));

        if (nextDate2.isBefore(start)) {
            SchedulePeriod schedulePeriod = new SchedulePeriod(start, holdDate, nextDate, holdDate);

            schedulePeriods.add(0, schedulePeriod);

            holdDate = nextDate2;
        } else {
            SchedulePeriod schedulePeriod = new SchedulePeriod(nextDate, holdDate);

            schedulePeriods.add(0, schedulePeriod);

            holdDate = nextDate;
        }

        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:com.mbc.jfin.schedule.impl.ShortFirstStubScheduleGenerator.java

License:Open Source License

public Schedule generate(LocalDate start, LocalDate end, ReadablePeriod frequency) throws ScheduleException {
    ArrayList<SchedulePeriod> schedulePeriods = new ArrayList<SchedulePeriod>();

    LocalDate holdDate = end;//from w  w  w . j av a  2  s  .  c  om

    int periodCount = 1;

    while (holdDate.isAfter(start)) {
        LocalDate nextDate = end.minus(multiplyPeriod(frequency, periodCount));

        LocalDate notionalStartDate = null;
        LocalDate notionalEndDate = null;

        if (nextDate.isBefore(start)) {
            notionalStartDate = nextDate;
            notionalEndDate = holdDate;
            nextDate = start;
        }

        SchedulePeriod schedulePeriod = new SchedulePeriod(nextDate, holdDate, notionalStartDate,
                notionalEndDate);

        schedulePeriods.add(0, schedulePeriod);

        holdDate = nextDate;
        periodCount++;
        if (maxPeriods > 0 && periodCount > maxPeriods) {
            throw new ScheduleTooLongException(maxPeriods);
        }
    }

    return new Schedule(schedulePeriods);
}

From source file:de.ifgi.airbase.feeder.io.sos.http.AbstractTransactionalSosClient.java

License:Open Source License

protected int getLastSundayOfOctober(int year) {
    LocalDate ld = new LocalDate(year, DateTimeConstants.OCTOBER, 1).dayOfMonth().withMaximumValue().dayOfWeek()
            .setCopy(DateTimeConstants.SUNDAY);
    if (ld.getMonthOfYear() != DateTimeConstants.OCTOBER) {
        return ld.minus(Period.days(7)).getDayOfMonth();
    } else {/*w  w  w.j  a v  a2  s .c o  m*/
        return ld.getDayOfMonth();
    }
}

From source file:org.estatio.dom.lease.breaks.BreakOptions.java

License:Apache License

@Action(semantics = SemanticsOf.NON_IDEMPOTENT)
@ActionLayout(contributed = Contributed.AS_ACTION)
public Lease newBreakOption(final Lease lease, final @ParameterLayout(named = "Break date") LocalDate breakDate,
        final @ParameterLayout(named = "Notification period", describedAs = "Notification period in a text format. Example 6y5m2d") String notificationPeriodStr,
        final BreakType breakType, final BreakExerciseType breakExerciseType,
        final @ParameterLayout(named = "Description") @Parameter(optionality = Optionality.OPTIONAL) String description) {
    final BreakOption breakOption = newTransientInstance(breakType.getFactoryClass());
    breakOption.setType(breakType);//  ww  w . ja v  a2  s .com
    breakOption.setLease(lease);
    breakOption.setExerciseType(breakExerciseType);
    breakOption.setBreakDate(breakDate);
    breakOption.setNotificationPeriod(notificationPeriodStr);
    breakOption.setExerciseDate(breakDate.minus(JodaPeriodUtils.asPeriod(notificationPeriodStr)));
    breakOption.setDescription(description);
    persist(breakOption);
    return lease;
}

From source file:org.estatio.dom.lease.breaks.BreakOptions.java

License:Apache License

public String validateNewBreakOption(final Lease lease, final LocalDate breakDate,
        final String notificationPeriodStr, final BreakType breakType,
        final BreakExerciseType breakExerciseType, final String description) {

    final Period notificationPeriodJoda = JodaPeriodUtils.asPeriod(notificationPeriodStr);
    if (notificationPeriodJoda == null) {
        return "Notification period format not recognized";
    }//  w w w .  jav a  2 s. co  m
    final LocalDate notificationDate = breakDate.minus(notificationPeriodJoda);
    return checkNewBreakOptionDuplicate(lease, BreakType.FIXED, notificationDate);
}

From source file:org.isisaddons.module.fakedata.dom.JodaLocalDates.java

License:Apache License

@Programmatic
public LocalDate before(final Period period) {
    final LocalDate now = fake.clockService.now();
    return now.minus(period);
}