Java Code Examples for org.joda.time.LocalDate#plusMonths()

The following examples show how to use org.joda.time.LocalDate#plusMonths() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(1)))  && counter < 12) {
        String month = checkDate.monthOfYear().getAsShortText();
        String year = checkDate.year().getAsString();

        String date = checkDate.toString(DATE_FORMAT);
        String label = String.format(DATE_LABEL_FORMAT, month, year);

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusMonths(1);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 2
Source File: DateRangeStaticFacotry.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public static Collection<DateRange> splitAsDateRangeByMonth(LocalDate start, LocalDate end){
	
	Set<DateRange> dates = new LinkedHashSet<DateRange>();
	dates.add(new DateRange(start, start.withDayOfMonth(start.dayOfMonth().getMaximumValue())));
	
	LocalDate startDateOfMonth = start.withDayOfMonth(start.dayOfMonth().getMinimumValue()).plusMonths(1);
	while(!startDateOfMonth.isAfter(end)){
		LocalDate endDateOfWeek = startDateOfMonth.withDayOfMonth(startDateOfMonth.dayOfMonth().getMaximumValue());
		if(endDateOfWeek.isAfter(end)){
			endDateOfWeek = end;
		}
		DateRange dr = new DateRange(startDateOfMonth, endDateOfWeek);
		dates.add(dr);
		startDateOfMonth = startDateOfMonth.plusMonths(1);
	}
	return dates;
}
 
Example 3
Source File: IncomingInvoice.java    From estatio with Apache License 2.0 6 votes vote down vote up
public LocalDate default13CompleteInvoice(
        final IncomingInvoiceType incomingInvoiceType,
        final boolean createNewSupplier,
        final Party seller,
        final Boolean createRoleIfRequired,
        final BankAccount bankAccount,
        final OrganisationNameNumberViewModel newSupplierCandidate,
        final Country newSupplierCountry,
        final String newSupplierChamberOfCommerceCode,
        final String newSupplierIban,
        final String invoiceNumber,
        final String communicationNumber,
        final LocalDate dateReceived,
        final LocalDate invoiceDate) {
    if (getDueDate() != null)
        return getDueDate();
    else if (getInvoiceDate() != null)
        return getInvoiceDate().plusMonths(1);
    else
        return invoiceDate != null ? invoiceDate.plusMonths(1) : null;
}
 
Example 4
Source File: TurnoverAnalysisService.java    From estatio with Apache License 2.0 6 votes vote down vote up
/**
 * NOTE: this method (and the methods called by it) should be a reflection of the talks with the users on the rules they prefer (https://docs.google.com/presentation/d/1LklFa3fdX7gl5BaHwmm7f0iERh6IGRuADxQxWy1scpA)
 * @param report
 * @return
 */
List<LocalDate> aggregationDatesForTurnoverReportingConfig(
        final AggregationAnalysisReportForConfig report) {

    LocalDate startDateToUse = getStartDateToUse(report).withDayOfMonth(1); // the method should always return first day of month, but just in case ...

    LocalDate endDateToUse = getEndDateToUse(report);

    List<LocalDate> result = new ArrayList<>();
    while (!endDateToUse.isBefore(startDateToUse)) {
        switch (report.getTurnoverReportingConfig().getFrequency()){
        case MONTHLY:
            result.add(startDateToUse);
            startDateToUse = startDateToUse.plusMonths(1);
            break;
        case YEARLY:
        case DAILY:
            // NOOP since (should be) called only by TurnoverAnalysisService#analyze which has TurnoverAggregationService#guard
            return Collections.emptyList();
        }
    }
    return result;
}
 
Example 5
Source File: QuarterYearIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(3))) && counter < 4) {
        String label;
        String date;

        int cMonth = checkDate.getMonthOfYear();
        String cYearStr = checkDate.year().getAsString();

        if (cMonth < MAR) {
            date = cYearStr + Q1;
            label = String.format(DATE_LABEL_FORMAT, JAN_STR, MAR_STR, cYearStr);
        } else if ((cMonth >= MAR) && (cMonth < JUN)) {
            date = cYearStr + Q2;
            label = String.format(DATE_LABEL_FORMAT, APR_STR, JUN_STR, cYearStr);
        } else if ((cMonth >= JUN) && (cMonth < SEP)) {
            date = cYearStr + Q3;
            label = String.format(DATE_LABEL_FORMAT, JUL_STR, SEP_STR, cYearStr);
        } else {
            date = cYearStr + Q4;
            label = String.format(DATE_LABEL_FORMAT, OCT_STR, DEC_STR, cYearStr);
        }

        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        checkDate = checkDate.plusMonths(3);
        counter++;
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 6
Source File: FinancialYearOctExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    LocalDate periodDate = LocalDate.parse(period,
            DateTimeFormat.forPattern(DATE_FORMAT));
    periodDate = periodDate.withMonthOfYear(monthOfYear());
    periodDate = periodDate.plusMonths(plusMonths());
    return periodDate.plusDays(expiryDays - 2);
}
 
Example 7
Source File: SixMonthlyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    int periodNumber = Character.getNumericValue(period.charAt(period.length() - 1));
    LocalDate periodDate = LocalDate.parse(period.substring(0, period.length() - 1),
            DateTimeFormat.forPattern(getDateFormat()));
    periodDate = periodDate.withMonthOfYear(monthOfYear(periodNumber));
    periodDate = periodDate.plusMonths(plusMonths());
    return periodDate.plusDays(expiryDays - 2);
}
 
Example 8
Source File: FinancialYearAprilExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    LocalDate periodDate = LocalDate.parse(period,
            DateTimeFormat.forPattern(DATE_FORMAT));
    periodDate = periodDate.withMonthOfYear(monthOfYear());
    periodDate = periodDate.plusMonths(plusMonths());
    return periodDate.plusDays(expiryDays - 2);
}
 
Example 9
Source File: BiMonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BiMonthIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.getYear(), JAN, 1);
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), 1);
    for (int i = 0; i < openFuturePeriods; i++) {
        maxDate = maxDate.plusMonths(2);
    }
}
 
Example 10
Source File: SixMonthAprilIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);
    int counter = 0;


    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(6))) && counter < 2) {
        String year = checkDate.year().getAsString();
        String yearLastPeriod = Integer.parseInt(year)+1+"";
        String label;
        String date;

        if (checkDate.getMonthOfYear() >= APR && checkDate.getMonthOfYear() <= SEP) {
            label = String.format(DATE_LABEL_FORMAT, APR_STR_LONG, SEP_STR_LONG, year);
            date = year + S1;
        } else {
            label = String.format(DATE_LABEL_FORMAT, OCT_STR_LONG +" "+ year, MAR_STR_LONG, yearLastPeriod);
            date = year + S2;
        }


        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }
        checkDate = checkDate.plusMonths(6);
        counter++;
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 11
Source File: LocalDateIMMDateCalculator.java    From objectlabkit with Apache License 2.0 5 votes vote down vote up
private LocalDate calculateIMMMonth(final boolean requestNextIMM, final LocalDate startDate, final int month) {
    int monthOffset;
    LocalDate date = startDate;
    switch (month) {
    case MARCH:
    case JUNE:
    case SEPTEMBER:
    case DECEMBER:
        final LocalDate immDate = calculate3rdWednesday(date);
        if (requestNextIMM && !date.isBefore(immDate)) {
            date = date.plusMonths(MONTHS_IN_QUARTER);
        } else if (!requestNextIMM && !date.isAfter(immDate)) {
            date = date.minusMonths(MONTHS_IN_QUARTER);
        }
        break;

    default:
        if (requestNextIMM) {
            monthOffset = (MONTH_IN_YEAR - month) % MONTHS_IN_QUARTER;
            date = date.plusMonths(monthOffset);
        } else {
            monthOffset = month % MONTHS_IN_QUARTER;
            date = date.minusMonths(monthOffset);
        }
        break;
    }
    return date;
}
 
Example 12
Source File: SixMonthAprilIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public SixMonthAprilIterator(int openFP, String[] dataInputPeriods) {
    super(dataInputPeriods);
    openFuturePeriods = openFP;
    cPeriod = new LocalDate(currentDate.getYear(), APR, 1);
    checkDate = new LocalDate(cPeriod);
    maxDate = new LocalDate(currentDate.getYear(), currentDate.getMonthOfYear(), 1);
    for (int i = 0; i < openFuturePeriods-1; i++) {
        maxDate = maxDate.plusMonths(6);
    }
}
 
Example 13
Source File: MonthlyExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected LocalDate getMaxDateCanEdit() {
    LocalDate periodDate = LocalDate.parse(period, DateTimeFormat.forPattern(getDateFormat()));
    periodDate = periodDate.plusMonths(plusMonths());
    return periodDate.plusDays(expiryDays - 2);
}
 
Example 14
Source File: TurnoverAggregationService_Test.java    From estatio with Apache License 2.0 4 votes vote down vote up
@Test
public void getTurnoversForAggregationPeriod_works() throws Exception {

    // given
    TurnoverAggregationService service = new TurnoverAggregationService();
    final LocalDate aggregationDate = new LocalDate(2020, 1, 1);
    final AggregationPeriod aggregationPeriod = AggregationPeriod.P_2M;
    List<Turnover> turnovers = new ArrayList<>();

    // when
    final Turnover turnoverThisYear = new Turnover(null, aggregationDate, null, null, null, null);
    final Turnover turnoverPlus1Month = new Turnover(null, aggregationDate.plusMonths(1), null, null, null, null);
    final Turnover turnoverMinus1Month = new Turnover(null, aggregationDate.minusMonths(1), null, null, null, null);
    turnovers.add(turnoverThisYear);
    turnovers.add(turnoverPlus1Month);
    turnovers.add(turnoverMinus1Month);

    // then
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).hasSize(2);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).contains(turnoverThisYear);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).contains(turnoverMinus1Month);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).doesNotContain(turnoverPlus1Month);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, true)).isEmpty();

    // and when
    final Turnover turnoverPreviousYear = new Turnover(null, aggregationDate.minusYears(1), null, null, null, null);
    final Turnover turnoverPYPlus1Month = new Turnover(null, aggregationDate.minusYears(1).plusMonths(1), null, null, null, null);
    final Turnover turnoverPYMinus1Month = new Turnover(null, aggregationDate.minusYears(1).minusMonths(1), null, null, null, null);
    turnovers.add(turnoverPreviousYear);
    turnovers.add(turnoverPYPlus1Month);
    turnovers.add(turnoverPYMinus1Month);

    // then
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).hasSize(2);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).contains(turnoverThisYear);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).contains(turnoverMinus1Month);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, false)).doesNotContain(turnoverPlus1Month);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, true)).hasSize(2);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, true)).contains(turnoverPreviousYear);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, true)).contains(turnoverPYMinus1Month);
    Assertions.assertThat(service.getTurnoversForAggregationPeriod(aggregationPeriod, aggregationDate, turnovers, true)).doesNotContain(turnoverPYPlus1Month);

}
 
Example 15
Source File: BiMonthIterator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected ArrayList<DateHolder> generatePeriod() {
    int counter = 0;
    ArrayList<DateHolder> dates = new ArrayList<DateHolder>();
    checkDate = new LocalDate(cPeriod);

    while ((openFuturePeriods > 0 || currentDate.isAfter(checkDate.plusMonths(2))) && counter < 6) {
        int cMonth = checkDate.getMonthOfYear();
        String year = checkDate.year().getAsString();

        String date;
        String label;

        if (cMonth < FEB) {
            date = year + B1;
            label = String.format(DATE_LABEL_FORMAT, JAN_STR, FEB_STR, year);
        } else if ((cMonth >= FEB) && (cMonth < APR)) {
            date = year + B2;
            label = String.format(DATE_LABEL_FORMAT, MAR_STR, APR_STR, year);
        } else if ((cMonth >= APR) && (cMonth < JUN)) {
            date = year + B3;
            label = String.format(DATE_LABEL_FORMAT, MAY_STR, JUN_STR, year);
        } else if ((cMonth >= JUN) && (cMonth < AUG)) {
            date = year + B4;
            label = String.format(DATE_LABEL_FORMAT, JUL_STR, AUG_STR, year);
        } else if ((cMonth >= AUG) && (cMonth < OCT)) {
            date = year + B5;
            label = String.format(DATE_LABEL_FORMAT, SEP_STR, OCT_STR, year);
        } else {
            date = year + B6;
            label = String.format(DATE_LABEL_FORMAT, NOV_STR, DEC_STR, year);
        }


        if (checkDate.isBefore(maxDate) && isInInputPeriods(date)) {
            DateHolder dateHolder = new DateHolder(date, checkDate.toString(), label);
            dates.add(dateHolder);
        }

        counter++;
        checkDate = checkDate.plusMonths(2);
    }

    Collections.reverse(dates);
    return dates;
}
 
Example 16
Source File: LocalDateCurrencyDateCalculator.java    From objectlabkit with Apache License 2.0 4 votes vote down vote up
@Override
protected LocalDate addMonths(LocalDate date, int unit) {
    return date.plusMonths(unit);
}
 
Example 17
Source File: MonthCalendar.java    From NCalendar with Apache License 2.0 4 votes vote down vote up
@Override
protected LocalDate getIntervalDate(LocalDate localDate, int count) {
    return localDate.plusMonths(count);
}
 
Example 18
Source File: BreakOptionRepository_IntegTest.java    From estatio with Apache License 2.0 4 votes vote down vote up
@Test
public void whenRolling() throws Exception {

    // given
    Lease lease = fs.getLease();
    Assertions.assertThat(lease.getBreakOptions()).isEmpty();

    LocalDate currentDate = clockService.now();

    // when
    final LocalDate breakDate = currentDate.plusMonths(4);
    final String notificationPeriodStr = "3m";
    final BreakType breakType = BreakType.ROLLING;
    final BreakExerciseType breakExerciseType = fakeDataService.enums().anyOf(BreakExerciseType.class);
    final String description = fakeDataService.lorem().sentence();

    breakOptionRepository.newBreakOption(lease, breakDate, notificationPeriodStr, breakType, breakExerciseType, description);
    transactionService.nextTransaction();

    // then
    Assertions.assertThat(lease.getBreakOptions()).hasSize(1);
    final BreakOption breakOption = lease.getBreakOptions().first();

    Assertions.assertThat(breakOption.getLease()).isEqualTo(lease);

    Assertions.assertThat(breakOption.getBreakDate()).isEqualTo(breakDate);
    Assertions.assertThat(breakOption.getNotificationPeriod()).isEqualTo("3m");
    Assertions.assertThat(breakOption.getType()).isEqualTo(BreakType.ROLLING);
    Assertions.assertThat(breakOption).isInstanceOf(RollingBreakOption.class);

    Assertions.assertThat(breakOption.getExerciseType()).isEqualTo(breakExerciseType);
    Assertions.assertThat(breakOption.getDescription()).isEqualTo(description);

    Assertions.assertThat(breakOption.getExerciseDate()).isEqualTo(breakDate.minusMonths(3));

    // and given, meaning that...
    currentDate = clockService.now();
    LocalDate exerciseDate = breakOption.getExerciseDate();
    Assertions.assertThat(currentDate).isLessThan(exerciseDate);

    // then also
    Assertions.assertThat(breakOption.getCurrentBreakDate()).isEqualTo(exerciseDate.plusMonths(2));

    Assertions.assertThat(breakOption.getCalendarEvents()).hasSize(1);

    final List<Event> eventList = eventRepository.findBySource(breakOption);
    Assertions.assertThat(eventList).hasSize(1);
    final Event event = eventList.get(0);
    Assertions.assertThat(event.getDate()).isEqualTo(breakOption.getExerciseDate());
    Assertions.assertThat(event.getCalendarName()).isEqualTo("Rolling break exercise");
    Assertions.assertThat(event.getSource()).isEqualTo(breakOption);

    final Set<String> calendarNames = breakOption.getCalendarNames();
    Assertions.assertThat(calendarNames).containsExactly("Rolling break exercise");

    // and when
    final LocalDate exerciseDatePlus1 = breakOption.getExerciseDate().plusMonths(1);
    setFixtureClockDate(exerciseDatePlus1);

    // meaning that...
    currentDate = clockService.now();
    exerciseDate = breakOption.getExerciseDate();
    Assertions.assertThat(currentDate).isGreaterThan(exerciseDate);

    // then

    // this fails if run after 11pm... timezone issues
    // Assertions.assertThat(breakOption.getCurrentBreakDate()).isEqualTo(currentDate.plusMonths(2));

    Assertions.assertThat(breakOption.getCurrentBreakDate())
            .isBetween(currentDate.plusMonths(2).minusDays(1), currentDate.plusMonths(2));

}
 
Example 19
Source File: DateUtil.java    From activiti6-boot2 with Apache License 2.0 3 votes vote down vote up
public static Date addDate(Date startDate, Integer years, Integer months, Integer days) {

        LocalDate currentDate = new LocalDate(startDate);

        currentDate = currentDate.plusYears(years);
        currentDate = currentDate.plusMonths(months);
        currentDate = currentDate.plusDays(days);

        return currentDate.toDate();
    }
 
Example 20
Source File: CalendarUtil.java    From NCalendar with Apache License 2.0 2 votes vote down vote up
/**
 * 第一个是不是第二个的上一个月,只在此处有效
 *
 * @param date1
 * @param date2
 * @return
 */
public static boolean isLastMonth(LocalDate date1, LocalDate date2) {
    LocalDate date = date2.plusMonths(-1);
    return date1.getMonthOfYear() == date.getMonthOfYear();
}