Example usage for org.joda.time LocalDate withMonthOfYear

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

Introduction

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

Prototype

public LocalDate withMonthOfYear(int monthOfYear) 

Source Link

Document

Returns a copy of this date with the month of year field updated.

Usage

From source file:com.cronutils.htime.DateTimeFormatParser.java

License:Apache License

@VisibleForTesting
Map<String, String> initMonths(Locale locale) {
    String fullMonth = String.format("%s%s%s%s", constants.monthOfYear(), constants.monthOfYear(),
            constants.monthOfYear(), constants.monthOfYear());
    String shortMonth = String.format("%s%s%s", constants.monthOfYear(), constants.monthOfYear(),
            constants.monthOfYear());//from   w  w w.java  2s.c  o  m
    LocalDate date = new LocalDate();
    Map<String, String> mapping = Maps.newHashMap();
    for (int j = 1; j < 13; j++) {
        String moy = date.withMonthOfYear(j).monthOfYear().getAsText(locale).toLowerCase();
        mapping.put(moy, fullMonth);
        mapping.put(moy.substring(0, 3), shortMonth);
    }
    return mapping;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

License:Apache License

public LocalDate getNextDueDateFrom(final LocalDate startingDate) {
    LocalDate nextDueLocalDate = null;
    if (isAnnualFee() || isMonthlyFee()) {
        nextDueLocalDate = startingDate.withMonthOfYear(this.feeOnMonth);
        nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        while (startingDate.isAfter(nextDueLocalDate)) {
            nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
        }//from  w  w  w.j a v  a  2 s. c o  m
    } else if (isWeeklyFee()) {
        nextDueLocalDate = getDueLocalDate();
        while (startingDate.isAfter(nextDueLocalDate)) {
            nextDueLocalDate = calculateNextDueDate(nextDueLocalDate);
        }
    } else {
        nextDueLocalDate = calculateNextDueDate(startingDate);
    }
    return nextDueLocalDate;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

License:Apache License

private LocalDate calculateNextDueDate(final LocalDate date) {
    LocalDate nextDueLocalDate = null;
    if (isAnnualFee()) {
        nextDueLocalDate = date.withMonthOfYear(this.feeOnMonth).plusYears(1);
        nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
    } else if (isMonthlyFee()) {
        nextDueLocalDate = date.plusMonths(this.feeInterval);
        nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
    } else if (isWeeklyFee()) {
        nextDueLocalDate = date.plusWeeks(this.feeInterval);
        nextDueLocalDate = setDayOfWeek(nextDueLocalDate);
    }/*  www . j a  va  2s  . c  o m*/
    return nextDueLocalDate;
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

License:Apache License

public void updateToPreviousDueDate() {
    if (isAnnualFee() || isMonthlyFee() || isWeeklyFee()) {
        LocalDate nextDueLocalDate = new LocalDate(dueDate);
        if (isAnnualFee()) {
            nextDueLocalDate = nextDueLocalDate.withMonthOfYear(this.feeOnMonth).minusYears(1);
            nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        } else if (isMonthlyFee()) {
            nextDueLocalDate = nextDueLocalDate.minusMonths(this.feeInterval);
            nextDueLocalDate = setDayOfMonth(nextDueLocalDate);
        } else if (isWeeklyFee()) {
            nextDueLocalDate = nextDueLocalDate.minusDays(7 * this.feeInterval);
            nextDueLocalDate = setDayOfWeek(nextDueLocalDate);
        }/*  w  w  w. j av  a2 s .c o m*/

        this.dueDate = nextDueLocalDate.toDate();
    }
}

From source file:com.gst.portfolio.savings.domain.SavingsHelper.java

License:Apache License

private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate,
        final SavingsPostingInterestPeriodType interestPostingPeriodType,
        final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) {

    LocalDate periodEndDate = interestPostingUpToDate;
    final Integer monthOfYear = periodStartDate.getMonthOfYear();
    financialYearBeginningMonth--;/*from   w  w  w  .ja va  2s.c  om*/
    if (financialYearBeginningMonth == 0)
        financialYearBeginningMonth = 12;

    final ArrayList<LocalDate> quarterlyDates = new ArrayList<>();
    quarterlyDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(quarterlyDates);

    final ArrayList<LocalDate> biannualDates = new ArrayList<>();
    biannualDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(biannualDates);
    boolean isEndDateSet = false;

    switch (interestPostingPeriodType) {
    case INVALID:
        break;
    case MONTHLY:
        // produce period end date on last day of current month
        periodEndDate = periodStartDate.dayOfMonth().withMaximumValue();
        break;
    case QUATERLY:
        for (LocalDate quarterlyDate : quarterlyDates) {
            if (quarterlyDate.isAfter(periodStartDate)) {
                periodEndDate = quarterlyDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case BIANNUAL:
        for (LocalDate biannualDate : biannualDates) {
            if (biannualDate.isAfter(periodStartDate)) {
                periodEndDate = biannualDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case ANNUAL:
        if (financialYearBeginningMonth < monthOfYear) {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
            periodEndDate = periodEndDate.plusYears(1);
        } else {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
        }
        periodEndDate = periodEndDate.dayOfMonth().withMaximumValue();
        break;
    }
    // interest posting always occurs on next day after the period end date.
    periodEndDate = periodEndDate.plusDays(1);
    return periodEndDate;
}

From source file:com.squid.kraken.v4.api.core.EngineUtils.java

License:Open Source License

/**
 * Convert the facet value into a date. 
 * If the value start with '=', it is expected to be a Expression, in which case we'll try to resolve it to a Date constant.
 * @param ctx//from  w ww .  j av  a  2s.com
 * @param index
 * @param lower 
 * @param value
 * @param compareFromInterval 
 * @return
 * @throws ParseException
 * @throws ScopeException
 * @throws ComputingException 
 */
public Date convertToDate(Universe universe, DimensionIndex index, Bound bound, String value,
        IntervalleObject compareFromInterval) throws ParseException, ScopeException, ComputingException {
    if (value.equals("")) {
        return null;
    } else if (value.startsWith("__")) {
        //
        // support hard-coded shortcuts
        if (value.toUpperCase().startsWith("__COMPARE_TO_")) {
            // for compareTo
            if (compareFromInterval == null) {
                // invalid compare_to selection...
                return null;
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_PERIOD")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                if (bound == Bound.UPPER) {
                    LocalDate date = localLower.minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate date = localLower.minusDays(1 + days.getDays());
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_MONTH")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusMonths(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
            if (value.equalsIgnoreCase("__COMPARE_TO_PREVIOUS_YEAR")) {
                LocalDate localLower = new LocalDate(((Date) compareFromInterval.getLowerBound()).getTime());
                LocalDate compareLower = localLower.minusYears(1);
                if (bound == Bound.LOWER) {
                    return compareLower.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(
                            ((Date) compareFromInterval.getUpperBound()).getTime());
                    Days days = Days.daysBetween(localLower, localUpper);
                    LocalDate compareUpper = compareLower.plusDays(days.getDays());
                    return compareUpper.toDate();
                }
            }
        } else {
            // for regular
            // get MIN, MAX first
            Intervalle range = null;
            if (index.getDimension().getType() == Type.CONTINUOUS) {
                if (index.getStatus() == Status.DONE) {
                    List<DimensionMember> members = index.getMembers();
                    if (!members.isEmpty()) {
                        DimensionMember member = members.get(0);
                        Object object = member.getID();
                        if (object instanceof Intervalle) {
                            range = (Intervalle) object;
                        }
                    }
                } else {
                    try {
                        DomainHierarchy hierarchy = universe
                                .getDomainHierarchy(index.getAxis().getParent().getDomain());
                        hierarchy.isDone(index, null);
                    } catch (ComputingException | InterruptedException | ExecutionException
                            | TimeoutException e) {
                        throw new ComputingException("failed to retrieve period interval");
                    }
                }
            }
            if (range == null) {
                range = IntervalleObject.createInterval(new Date(), new Date());
            }
            if (value.equalsIgnoreCase("__ALL")) {
                if (index.getDimension().getType() != Type.CONTINUOUS) {
                    return null;
                }
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getLowerBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_DAY")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    return (Date) range.getUpperBound();
                }
            }
            if (value.equalsIgnoreCase("__LAST_7_DAYS")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.minusDays(6);// 6+1
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_MONTH")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__CURRENT_YEAR")) {
                if (bound == Bound.UPPER) {
                    return (Date) range.getUpperBound();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_MONTH")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withDayOfMonth(1).minusMonths(1);
                    return date.toDate();
                }
            }
            if (value.equalsIgnoreCase("__PREVIOUS_YEAR")) {// the previous complete month
                if (bound == Bound.UPPER) {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusDays(1);
                    return date.toDate();
                } else {
                    LocalDate localUpper = new LocalDate(((Date) range.getUpperBound()).getTime());
                    LocalDate date = localUpper.withMonthOfYear(1).withDayOfMonth(1).minusYears(1);
                    return date.toDate();
                }
            }
        }
        throw new ScopeException("undefined facet expression alias: " + value);
    } else if (value.startsWith("=")) {
        // if the value starts by equal token, this is a formula that can be
        // evaluated
        try {
            String expr = value.substring(1);
            // check if the index content is available or wait for it
            DomainHierarchy hierarchy = universe.getDomainHierarchy(index.getAxis().getParent().getDomain(),
                    true);
            hierarchy.isDone(index, null);
            // evaluate the expression
            Object defaultValue = evaluateExpression(universe, index, expr, compareFromInterval);
            // check we can use it
            if (defaultValue == null) {
                //throw new ScopeException("unable to parse the facet expression as a constant: " + expr);
                // T1769: it's ok to return null
                return null;
            }
            if (!(defaultValue instanceof Date)) {
                throw new ScopeException("unable to parse the facet expression as a date: " + expr);
            }
            // ok, it's a date
            return (Date) defaultValue;
        } catch (ComputingException | InterruptedException | ExecutionException | TimeoutException e) {
            throw new ComputingException("failed to retrieve period interval");
        }
    } else {
        Date date = ServiceUtils.getInstance().toDate(value);
        if (bound == Bound.UPPER
                && !index.getAxis().getDefinitionSafe().getImageDomain().isInstanceOf(IDomain.TIME)) {
            // clear the timestamp
            return new LocalDate(date.getTime()).toDate();
        } else {
            return date;
        }
    }
}

From source file:net.sourceforge.fenixedu.presentationTier.TagLib.messaging.ArchiveTag.java

License:Open Source License

private String renderYear(YearAnnouncementArchiveEntry year) {
    StringBuilder buffer = new StringBuilder();

    boolean first = true;
    for (int i = year.getFirstPostMonth(); i <= 12; i++) {
        MonthAnnouncementArchiveEntry month = year.getEntries().get(i);

        if (month != null && !first) {
            buffer.append(", ");
        }/*from ww w. j a v a2  s  .  c  o m*/
        if (month != null && this.getTargetUrl() != null) {
            buffer.append("<a href=\"").append(this.getTargetUrl());
            buffer.append("selectedYear=").append(year.getYear());
            buffer.append("&amp;selectedMonth=").append(month.getMonth());
            buffer.append("\">");
        }
        if (month != null) {
            Locale locale = I18N.getLocale();
            LocalDate localDate = new LocalDate();
            localDate = localDate.withMonthOfYear(month.getMonth());

            buffer.append(localDate.toString("MMM.", locale));
            buffer.append(" (");
            buffer.append(month.getAnnouncementCount());
            buffer.append(")");
            first = false;
        }
        if (month != null && this.getTargetUrl() != null) {
            buffer.append("</a>");
        }
    }
    return buffer.toString();
}

From source file:org.apache.fineract.portfolio.savings.domain.SavingsHelper.java

License:Apache License

private LocalDate determineInterestPostingPeriodEndDateFrom(final LocalDate periodStartDate,
        final SavingsPostingInterestPeriodType interestPostingPeriodType,
        final LocalDate interestPostingUpToDate, Integer financialYearBeginningMonth) {

    LocalDate periodEndDate = interestPostingUpToDate;
    final Integer monthOfYear = periodStartDate.getMonthOfYear();
    financialYearBeginningMonth--;// ww  w .  j  a v a  2s.co m
    if (financialYearBeginningMonth == 0)
        financialYearBeginningMonth = 12;

    final ArrayList<LocalDate> quarterlyDates = new ArrayList<>();
    quarterlyDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(3)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    quarterlyDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(9)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(quarterlyDates);

    final ArrayList<LocalDate> biannualDates = new ArrayList<>();
    biannualDates
            .add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).dayOfMonth().withMaximumValue());
    biannualDates.add(periodStartDate.withMonthOfYear(financialYearBeginningMonth).plusMonths(6)
            .withYear(periodStartDate.getYear()).dayOfMonth().withMaximumValue());
    Collections.sort(biannualDates);

    boolean isEndDateSet = false;

    switch (interestPostingPeriodType) {
    case INVALID:
        break;
    case MONTHLY:
        // produce period end date on last day of current month
        periodEndDate = periodStartDate.dayOfMonth().withMaximumValue();
        break;
    case QUATERLY:
        for (LocalDate quarterlyDate : quarterlyDates) {
            if (quarterlyDate.isAfter(periodStartDate)) {
                periodEndDate = quarterlyDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = quarterlyDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case BIANNUAL:
        for (LocalDate biannualDate : biannualDates) {
            if (biannualDate.isAfter(periodStartDate)) {
                periodEndDate = biannualDate;
                isEndDateSet = true;
                break;
            }
        }

        if (!isEndDateSet)
            periodEndDate = biannualDates.get(0).plusYears(1).dayOfMonth().withMaximumValue();
        break;
    case ANNUAL:
        if (financialYearBeginningMonth < monthOfYear) {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
            periodEndDate = periodEndDate.plusYears(1);
        } else {
            periodEndDate = periodStartDate.withMonthOfYear(financialYearBeginningMonth);
        }
        periodEndDate = periodEndDate.dayOfMonth().withMaximumValue();
        break;
    }

    // interest posting always occurs on next day after the period end date.
    periodEndDate = periodEndDate.plusDays(1);

    return periodEndDate;
}

From source file:org.kuali.kpme.core.leaveplan.service.LeavePlanServiceImpl.java

License:Educational Community License

@Override
public DateTime getFirstDayOfLeavePlan(String leavePlan, LocalDate asOfDate) {
    //The only thing this method does is tack on the year of the supplied asOfDate to the calendar year start date.
    LeavePlan lp = getLeavePlan(leavePlan, asOfDate);

    int priorYearCutOffMonth = Integer.parseInt(lp.getCalendarYearStartMonth());
    int priorYearCutOffDay = Integer.parseInt(lp.getCalendarYearStartDayOfMonth());

    LocalDate cutOffDate = asOfDate.withMonthOfYear(priorYearCutOffMonth).withDayOfMonth(priorYearCutOffDay);
    if (asOfDate.isBefore(cutOffDate)) {
        cutOffDate = cutOffDate.minusYears(1);
    }/*from  ww w.  j av  a  2  s  .co m*/
    return cutOffDate.toDateTimeAtStartOfDay();
}

From source file:org.kuali.kpme.core.leaveplan.service.LeavePlanServiceImpl.java

License:Educational Community License

@Override
public DateTime getRolloverDayOfLeavePlan(String leavePlan, LocalDate asOfDate) {
    LeavePlan lp = getLeavePlan(leavePlan, asOfDate);

    int priorYearCutOffMonth = Integer.parseInt(lp.getCalendarYearStartMonth());
    int priorYearCutOffDay = Integer.parseInt(lp.getCalendarYearStartDayOfMonth());

    LocalDate cutOffDate = asOfDate.withMonthOfYear(priorYearCutOffMonth).withDayOfMonth(priorYearCutOffDay);
    if (asOfDate.isAfter(cutOffDate) || asOfDate.equals(cutOffDate)) {
        cutOffDate = cutOffDate.plusYears(1);
    }//from w w  w.jav  a2s  . co m
    return cutOffDate.toDateTimeAtStartOfDay();
}