Example usage for org.joda.time LocalDate getDayOfMonth

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

Introduction

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

Prototype

public int getDayOfMonth() 

Source Link

Document

Get the day of month field value.

Usage

From source file:com.gst.portfolio.calendar.domain.Calendar.java

License:Apache License

public Map<String, Object> updateStartDateAndDerivedFeilds(final LocalDate newMeetingStartDate) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(9);

    final LocalDate currentDate = DateUtils.getLocalDateOfTenant();

    if (newMeetingStartDate.isBefore(currentDate)) {
        final String defaultUserMessage = "New meeting effective from date cannot be in past";
        throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage,
                newMeetingStartDate, getStartDateLocalDate());
    } else if (isStartDateAfter(newMeetingStartDate) && isStartDateBeforeOrEqual(currentDate)) {
        // new meeting date should be on or after start date or current
        // date//from   w w w .ja  va  2s.co m
        final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date";
        throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage,
                newMeetingStartDate, getStartDateLocalDate());
    } else {

        actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue(), newMeetingStartDate.toString());
        this.startDate = newMeetingStartDate.toDate();

        /*
         * If meeting start date is changed then there is possibilities of
         * recurring day may change, so derive the recurring day and update
         * it if it is changed. For weekly type is weekday and for monthly
         * type it is day of the month
         */

        CalendarFrequencyType calendarFrequencyType = CalendarUtils.getFrequency(this.recurrence);
        Integer interval = CalendarUtils.getInterval(this.recurrence);
        Integer repeatsOnDay = null;

        /*
         * Repeats on day, need to derive based on the start date
         */

        if (calendarFrequencyType.isWeekly()) {
            repeatsOnDay = newMeetingStartDate.getDayOfWeek();
        } else if (calendarFrequencyType.isMonthly()) {
            repeatsOnDay = newMeetingStartDate.getDayOfMonth();
        }

        // TODO cover other recurrence also

        this.recurrence = constructRecurrence(calendarFrequencyType, interval, repeatsOnDay, null);

    }

    return actualChanges;

}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static LocalDate adjustDate(final LocalDate date, final LocalDate seedDate,
        final PeriodFrequencyType frequencyType) {
    LocalDate adjustedVal = date;
    if (frequencyType.isMonthly() && seedDate.getDayOfMonth() > 28) {
        switch (date.getMonthOfYear()) {
        case 2://from   w  w w  .  ja v a 2s .com
            if (date.year().isLeap()) {
                adjustedVal = date.dayOfMonth().setCopy(29);
            }
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            if (seedDate.getDayOfMonth() > 30) {
                adjustedVal = date.dayOfMonth().setCopy(30);
            } else {
                adjustedVal = date.dayOfMonth().setCopy(seedDate.getDayOfMonth());
            }
            break;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            adjustedVal = date.dayOfMonth().setCopy(seedDate.getDayOfMonth());
            break;
        }
    }
    return adjustedVal;
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static LocalDate adjustRecurringDate(final LocalDate recuringDate, final Integer numberOfDays) {
    if (recuringDate.getDayOfMonth() == 1) {
        LocalDate adjustedRecurringDate = recuringDate.plusDays(numberOfDays);
        return adjustedRecurringDate;
    }// ww  w  . j av  a  2s.c  o m
    return recuringDate;
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static String getRRuleReadable(final LocalDate startDate, final String recurringRule) {

    String humanReadable = "";

    RRule rrule;//from   www .  ja  v a  2  s  .c om
    Recur recur = null;
    try {
        rrule = new RRule(recurringRule);
        rrule.validate();
        recur = rrule.getRecur();
    } catch (final ValidationException e) {
        throw new PlatformDataIntegrityException("error.msg.invalid.recurring.rule",
                "The Recurring Rule value: " + recurringRule + " is not valid.", "recurrence", recurringRule);
    } catch (final ParseException e) {
        throw new PlatformDataIntegrityException("error.msg.recurring.rule.parsing.error",
                "Error in pasring the Recurring Rule value: " + recurringRule, "recurrence", recurringRule);
    }

    if (recur == null) {
        return humanReadable;
    }

    if (recur.getFrequency().equals(Recur.DAILY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Daily";
        } else {
            humanReadable = "Every " + recur.getInterval() + " days";
        }
    } else if (recur.getFrequency().equals(Recur.WEEKLY)) {
        if (recur.getInterval() == 1 || recur.getInterval() == -1) {
            humanReadable = "Weekly";
        } else {
            humanReadable = "Every " + recur.getInterval() + " weeks";
        }

        humanReadable += " on ";
        final WeekDayList weekDayList = recur.getDayList();

        for (@SuppressWarnings("rawtypes")
        final Iterator iterator = weekDayList.iterator(); iterator.hasNext();) {
            final WeekDay weekDay = (WeekDay) iterator.next();
            humanReadable += DayNameEnum.from(weekDay.getDay()).getCode();
        }

    } else if (recur.getFrequency().equals(Recur.MONTHLY)) {
        NumberList nthDays = recur.getSetPosList();
        Integer nthDay = null;
        if (!nthDays.isEmpty())
            nthDay = (Integer) nthDays.get(0);
        NumberList monthDays = recur.getMonthDayList();
        Integer monthDay = null;
        if (!monthDays.isEmpty())
            monthDay = (Integer) monthDays.get(0);
        WeekDayList weekdays = recur.getDayList();
        WeekDay weekDay = null;
        if (!weekdays.isEmpty())
            weekDay = (WeekDay) weekdays.get(0);
        if (nthDay != null && weekDay != null) {
            NthDayType nthDayType = NthDayType.fromInt(nthDay);
            NthDayNameEnum nthDayName = NthDayNameEnum.from(nthDayType.toString());
            DayNameEnum weekdayType = DayNameEnum.from(weekDay.getDay());
            if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                humanReadable = "Monthly on " + nthDayName.getCode().toLowerCase() + " "
                        + weekdayType.getCode().toLowerCase();
            } else {
                humanReadable = "Every " + recur.getInterval() + " months on "
                        + nthDayName.getCode().toLowerCase() + " " + weekdayType.getCode().toLowerCase();
            }
        } else if (monthDay != null) {
            if (monthDay == -1) {
                if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                    humanReadable = "Monthly on last day";
                } else {
                    humanReadable = "Every " + recur.getInterval() + " months on last day";
                }
            } else {
                if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                    humanReadable = "Monthly on day " + monthDay;
                } else {
                    humanReadable = "Every " + recur.getInterval() + " months on day " + monthDay;
                }
            }
        } else {
            if (recur.getInterval() == 1 || recur.getInterval() == -1) {
                humanReadable = "Monthly on day " + startDate.getDayOfMonth();
            } else {
                humanReadable = "Every " + recur.getInterval() + " months on day " + startDate.getDayOfMonth();
            }
        }
    } else if (recur.getFrequency().equals(Recur.YEARLY)) {
        if (recur.getInterval() == 1) {
            humanReadable = "Annually on " + startDate.toString("MMM") + " " + startDate.getDayOfMonth();
        } else {
            humanReadable = "Every " + recur.getInterval() + " years on " + startDate.toString("MMM") + " "
                    + startDate.getDayOfMonth();
        }
    }

    if (recur.getCount() > 0) {
        if (recur.getCount() == 1) {
            humanReadable = "Once";
        }
        humanReadable += ", " + recur.getCount() + " times";
    }

    final Date endDate = recur.getUntil();
    final LocalDate date = new LocalDate(endDate);
    final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MMMM YY");
    final String formattedDate = date.toString(fmt);
    if (endDate != null) {
        humanReadable += ", until " + formattedDate;
    }

    return humanReadable;
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static boolean isValidRecurringDate(final Recur recur, final LocalDate seedDate, final LocalDate date,
        boolean isSkipRepaymentonFirstDayOfMonth, final int numberOfDays) {
    LocalDate startDate = date;/*from ww w . j  a v a2 s . c om*/
    if (isSkipRepaymentonFirstDayOfMonth && date.getDayOfMonth() == (numberOfDays + 1)) {
        startDate = startDate.minusDays(numberOfDays);
    }
    final Collection<LocalDate> recurDate = getRecurringDates(recur, seedDate, startDate, date.plusDays(1), 1,
            isSkipRepaymentonFirstDayOfMonth, numberOfDays);

    return (recurDate == null || recurDate.isEmpty()) ? false : recurDate.contains(date);
}

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

public static LocalDate getFirstRepaymentMeetingDate(final Calendar calendar, final LocalDate disbursementDate,
        final Integer loanRepaymentInterval, final String frequency, boolean isSkipRepaymentOnFirstDayOfMonth,
        final Integer numberOfDays) {
    final Recur recur = CalendarUtils.getICalRecur(calendar.getRecurrence());
    if (recur == null) {
        return null;
    }//  w ww .jav a2s .c  om
    LocalDate startDate = disbursementDate;
    final LocalDate seedDate = calendar.getStartDateLocalDate();
    if (isValidRedurringDate(calendar.getRecurrence(), seedDate, startDate, isSkipRepaymentOnFirstDayOfMonth,
            numberOfDays)) {
        startDate = startDate.plusDays(1);
    }
    // Recurring dates should follow loanRepaymentInterval.
    // e.g.
    // for weekly meeting interval is 1
    // where as for loan product with fortnightly frequency interval is 2
    // to generate currect set of meeting dates reset interval same as loan
    // repayment interval.
    recur.setInterval(loanRepaymentInterval);

    // Recurring dates should follow loanRepayment frequency.
    // e.g.
    // daily meeting frequency should support all loan products with any
    // frequency type.
    // to generate currect set of meeting dates reset frequency same as loan
    // repayment frequency.
    if (recur.getFrequency().equals(Recur.DAILY)) {
        recur.setFrequency(frequency);
    }

    final LocalDate firstRepaymentDate = getNextRecurringDate(recur, seedDate, startDate);
    if (isSkipRepaymentOnFirstDayOfMonth && firstRepaymentDate.getDayOfMonth() == 1) {
        return adjustRecurringDate(firstRepaymentDate, numberOfDays);
    }

    return firstRepaymentDate;
}

From source file:com.gst.portfolio.loanaccount.loanschedule.domain.LoanApplicationTerms.java

License:Apache License

private boolean isFallingInRepaymentPeriod(LocalDate fromDate, LocalDate toDate) {
    boolean isSameAsRepaymentPeriod = false;
    if (this.interestCalculationPeriodMethod.getValue()
            .equals(InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD.getValue())) {
        switch (this.repaymentPeriodFrequencyType) {
        case WEEKS:
            int days = Days.daysBetween(fromDate, toDate).getDays();
            isSameAsRepaymentPeriod = (days % 7) == 0;
            break;
        case MONTHS:
            boolean isFromDateOnEndDate = false;
            if (fromDate.getDayOfMonth() > fromDate.plusDays(1).getDayOfMonth()) {
                isFromDateOnEndDate = true;
            }//from  ww  w .  j a v  a2  s. c  om
            boolean isToDateOnEndDate = false;
            if (toDate.getDayOfMonth() > toDate.plusDays(1).getDayOfMonth()) {
                isToDateOnEndDate = true;
            }

            if (isFromDateOnEndDate && isToDateOnEndDate) {
                isSameAsRepaymentPeriod = true;
            } else {

                int months = getPeriodsBetween(fromDate, toDate);
                fromDate = fromDate.plusMonths(months);
                isSameAsRepaymentPeriod = fromDate.isEqual(toDate);
            }

            break;
        default:
            break;
        }
    }
    return isSameAsRepaymentPeriod;
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static LocalDateTime createLocalDateTime(@Nonnull final LocalDate aDate) {
    return createLocalDateTime(aDate.getYear(), aDate.getMonthOfYear(), aDate.getDayOfMonth());
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static LocalDateTime createLocalDateTime(@Nonnull final LocalDate aDate, final int nHours,
        final int nMinutes) {
    return createLocalDateTime(aDate.getYear(), aDate.getMonthOfYear(), aDate.getDayOfMonth(), nHours, nMinutes,
            0, 0);/* w w  w . j av a2s. c  o m*/
}

From source file:com.helger.datetime.PDTFactory.java

License:Apache License

@Nonnull
public static LocalDateTime createLocalDateTime(@Nonnull final LocalDate aDate, final int nHours,
        final int nMinutes, final int nSeconds) {
    return createLocalDateTime(aDate.getYear(), aDate.getMonthOfYear(), aDate.getDayOfMonth(), nHours, nMinutes,
            nSeconds, 0);//from ww w  .  j  a va2 s  .  co  m
}