Example usage for org.joda.time LocalDate get

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

Introduction

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

Prototype

public int get(DateTimeFieldType fieldType) 

Source Link

Document

Get the value of one of the fields of a datetime.

Usage

From source file:org.mifosplatform.infrastructure.reportmailingjob.service.ReportMailingJobWritePlatformServiceImpl.java

License:Mozilla Public License

/**
 * create the next recurring DateTime from recurrence pattern, start DateTime and current DateTime
 * //from w w w  . ja va 2  s  .  c o m
 * @param recurrencePattern
 * @param startDateTime
 * @return DateTime object
 */
private DateTime createNextRecurringDateTime(final ReportMailingJob reportMailingJob) {
    DateTime nextRecurringDateTime = null;
    final String recurrencePattern = reportMailingJob.getRecurrence();
    final DateTime nextRunDateTime = reportMailingJob.getNextRunDateTime();

    // the recurrence pattern/rule cannot be empty
    if (StringUtils.isNotBlank(recurrencePattern) && nextRunDateTime != null) {
        final LocalDate currentDate = DateUtils.getLocalDateOfTenant();
        final LocalDate nextRunDate = nextRunDateTime.toLocalDate();

        LocalDate nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate,
                nextRunDate);

        if (nextRecurringLocalDate.isBefore(currentDate)) {
            nextRecurringLocalDate = CalendarUtils.getNextRecurringDate(recurrencePattern, nextRunDate,
                    currentDate);
        }

        // get the date fields
        final int currentYearIntValue = nextRecurringLocalDate.get(DateTimeFieldType.year());
        final int currentMonthIntValue = nextRecurringLocalDate.get(DateTimeFieldType.monthOfYear());
        final int currentDayIntValue = nextRecurringLocalDate.get(DateTimeFieldType.dayOfMonth());

        // append the time of the previous next run date time
        nextRecurringDateTime = nextRunDateTime.withDate(currentYearIntValue, currentMonthIntValue,
                currentDayIntValue);
    }

    return nextRecurringDateTime;
}