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:org.killbill.billing.invoice.generator.BillingIntervalDetail.java

License:Apache License

public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay) {
    final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue();
    int proposedBillCycleDate = proposedDate.getDayOfMonth();
    if (proposedBillCycleDate < billingCycleDay && billingCycleDay <= lastDayOfMonth) {
        proposedBillCycleDate = billingCycleDay;
    }// w ww .j  a  v a2s  .c  o m
    return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate,
            proposedDate.getChronology());
}

From source file:org.killbill.billing.util.bcd.BillCycleDayCalculator.java

License:Apache License

public static LocalDate alignProposedBillCycleDate(final LocalDate proposedDate, final int billingCycleDay,
        final BillingPeriod billingPeriod) {
    // billingCycleDay alignment only makes sense for month based BillingPeriod (MONTHLY, QUARTERLY, BIANNUAL, ANNUAL)
    final boolean isMonthBased = (billingPeriod.getPeriod().getMonths()
            | billingPeriod.getPeriod().getYears()) > 0;
    if (!isMonthBased) {
        return proposedDate;
    }//from  www  .j ava 2s .  c om
    final int lastDayOfMonth = proposedDate.dayOfMonth().getMaximumValue();
    int proposedBillCycleDate = proposedDate.getDayOfMonth();
    if (proposedBillCycleDate < billingCycleDay) {
        if (billingCycleDay <= lastDayOfMonth) {
            proposedBillCycleDate = billingCycleDay;
        } else {
            proposedBillCycleDate = lastDayOfMonth;
        }
    }
    return new LocalDate(proposedDate.getYear(), proposedDate.getMonthOfYear(), proposedBillCycleDate,
            proposedDate.getChronology());
}

From source file:org.killbill.clock.ClockUtil.java

License:Apache License

/**
 * The method will convert the provided LocalDate into an instant (DateTime).
 * The conversion will use a reference time that should be interpreted from a UTC standpoint.
 *
 * The the provided LocalDate overlaps with the present, the current point in time is returned (to make sure we don't
 * end up with future instant).//from  w w w .j a v a2  s  .  co  m
 *
 * If not, we use both the provide LocalDate and LocalTime to return the DateTime in UTC
 *
 * @param inputDateInTargetTimeZone The input LocalDate as interpreted in the specified targetTimeZone
 * @param inputTimeInUTCTimeZone    The referenceTime in UTC
 * @param targetTimeZone            The target timeZone
 * @param clock                     The current clock
 * @return
 */
public static DateTime computeDateTimeWithUTCReferenceTime(final LocalDate inputDateInTargetTimeZone,
        final LocalTime inputTimeInUTCTimeZone, final DateTimeZone targetTimeZone, final Clock clock) {

    final Interval interval = inputDateInTargetTimeZone.toInterval(targetTimeZone);
    // If the input date overlaps with the present, we return NOW.
    if (interval.contains(clock.getUTCNow())) {
        return clock.getUTCNow();
    }
    // If not, we convert the inputTimeInUTCTimeZone -> inputTimeInTargetTimeZone, compute the resulting DateTime in targetTimeZone, and convert into a UTC DateTime:
    final LocalTime inputTimeInTargetTimeZone = inputTimeInUTCTimeZone
            .plusMillis(targetTimeZone.getOffset(clock.getUTCNow()));
    final DateTime resultInTargetTimeZone = new DateTime(inputDateInTargetTimeZone.getYear(),
            inputDateInTargetTimeZone.getMonthOfYear(), inputDateInTargetTimeZone.getDayOfMonth(),
            inputTimeInTargetTimeZone.getHourOfDay(), inputTimeInTargetTimeZone.getMinuteOfHour(),
            inputTimeInTargetTimeZone.getSecondOfMinute(), targetTimeZone);
    return resultInTargetTimeZone.toDateTime(DateTimeZone.UTC);
}

From source file:org.kitodo.production.helper.tasks.CreateNewspaperProcessesTask.java

License:Open Source License

/**
 * Creates a logical structure tree in the process under creation. In the
 * tree, all issues will have been created. Presumption is that never issues
 * for more than one year will be added to the same process.
 *
 * @param newProcess//w  ww.  j av  a2 s .  c  o m
 *            process under creation
 * @param issues
 *            issues to add
 * @param publicationRun
 *            verbal description of the course of appearance
 */
private void createLogicalStructure(ProzesskopieForm newProcess, List<IndividualIssue> issues,
        String publicationRun) {

    // initialise
    LegacyPrefsHelper ruleset = ServiceManager.getRulesetService()
            .getPreferences(newProcess.getProzessKopie().getRuleset());
    LegacyMetsModsDigitalDocumentHelper document;
    document = newProcess.getFileformat().getDigitalDocument();
    LegacyDocStructHelperInterface newspaper = document.getLogicalDocStruct();

    // try to add the publication run
    addMetadatum(newspaper, "PublicationRun", publicationRun, false);

    // create the year level
    LegacyDocStructHelperInterface year = createFirstChild(newspaper, document, ruleset);
    String theYear = Integer.toString(issues.get(0).getDate().getYear());
    addMetadatum(year, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE, theYear, true);

    // create the month level
    Map<Integer, LegacyDocStructHelperInterface> months = new HashMap<>();
    Map<LocalDate, LegacyDocStructHelperInterface> days = new HashMap<>(488);
    for (IndividualIssue individualIssue : issues) {
        LocalDate date = individualIssue.getDate();
        Integer monthNo = date.getMonthOfYear();
        if (!months.containsKey(monthNo)) {
            LegacyDocStructHelperInterface newMonth = createFirstChild(year, document, ruleset);
            addMetadatum(newMonth, LegacyMetsModsDigitalDocumentHelper.CREATE_ORDERLABEL_ATTRIBUTE_TYPE,
                    monthNo.toString(), true);
            addMetadatum(newMonth, year.getDocStructType().getName(), theYear, false);
            addMetadatum(newMonth, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE,
                    monthNo.toString(), false);
            months.put(monthNo, newMonth);
        }
        LegacyDocStructHelperInterface month = months.get(monthNo);

        // create the day level
        if (!days.containsKey(date)) {
            LegacyDocStructHelperInterface newDay = createFirstChild(month, document, ruleset);
            addMetadatum(newDay, LegacyMetsModsDigitalDocumentHelper.CREATE_ORDERLABEL_ATTRIBUTE_TYPE,
                    Integer.toString(date.getDayOfMonth()), true);
            addMetadatum(newDay, year.getDocStructType().getName(), theYear, false);
            addMetadatum(newDay, month.getDocStructType().getName(), Integer.toString(date.getMonthOfYear()),
                    false);
            addMetadatum(newDay, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE,
                    Integer.toString(date.getDayOfMonth()), false);
            days.put(date, newDay);
        }
        LegacyDocStructHelperInterface day = days.get(date);

        // create the issue
        LegacyDocStructHelperInterface issue = createFirstChild(day, document, ruleset);
        String heading = individualIssue.getHeading();
        if (Objects.nonNull(heading) && !heading.trim().isEmpty()) {
            addMetadatum(issue, issue.getDocStructType().getName(), heading, true);
        }
        addMetadatum(issue, year.getDocStructType().getName(), theYear, false);
        addMetadatum(issue, month.getDocStructType().getName(), Integer.toString(date.getMonthOfYear()), false);
        addMetadatum(issue, day.getDocStructType().getName(), Integer.toString(date.getDayOfMonth()), false);
        addMetadatum(issue, LegacyMetsModsDigitalDocumentHelper.CREATE_LABEL_ATTRIBUTE_TYPE, heading, false);
    }
}

From source file:org.kitodo.production.model.bibliography.course.CourseToGerman.java

License:Open Source License

/**
 * The method appendManyDates() converts a lot of date objects into readable
 * text in German language.//from w  ww. j  a v a  2 s . c o  m
 *
 * @param buffer
 *            StringBuilder to write to
 * @param dates
 *            Set of dates to convert to text
 * @param signum
 *            sign, i.e. true for additions, false for exclusions
 * @throws NoSuchElementException
 *             if dates has no elements
 * @throws NullPointerException
 *             if buffer or dates is null
 */
private static void appendManyDates(StringBuilder buffer, Set<LocalDate> dates, boolean signum) {
    if (signum) {
        buffer.append("zustzlich ");
    } else {
        buffer.append("nicht ");
    }

    TreeSet<LocalDate> orderedDates = dates instanceof TreeSet ? (TreeSet<LocalDate>) dates
            : new TreeSet<>(dates);

    //TODO: there is something wrong with this whole iterator - investigate it
    Iterator<LocalDate> datesIterator = orderedDates.iterator();

    LocalDate current = datesIterator.next();
    LocalDate next = datesIterator.hasNext() ? datesIterator.next() : null;
    LocalDate overNext = datesIterator.hasNext() ? datesIterator.next() : null;
    int previousYear = Integer.MIN_VALUE;
    boolean nextInSameMonth;
    boolean nextBothInSameMonth = next != null && DateUtils.sameMonth(current, next);
    int lastMonthOfYear = DateUtils.lastMonthForYear(orderedDates, current.getYear());

    do {
        nextInSameMonth = nextBothInSameMonth;
        nextBothInSameMonth = DateUtils.sameMonth(next, overNext);

        if (previousYear != current.getYear()) {
            buffer.append("am ");
        }

        buffer.append(current.getDayOfMonth());
        buffer.append('.');

        if (!nextInSameMonth) {
            buffer.append(' ');
            buffer.append(MONTH_NAMES[current.getMonthOfYear()]);
        }

        if (!DateUtils.sameYear(current, next)) {
            buffer.append(' ');
            buffer.append(current.getYear());
            if (next != null) {
                if (!DateUtils.sameYear(next, orderedDates.last())) {
                    buffer.append(", ");
                } else {
                    buffer.append(" und ebenfalls ");
                    if (!signum) {
                        buffer.append("nicht ");
                    }
                }
                lastMonthOfYear = DateUtils.lastMonthForYear(orderedDates, next.getYear());
            }
        } else if (next != null) {
            if (nextInSameMonth && nextBothInSameMonth
                    || !nextInSameMonth && next.getMonthOfYear() != lastMonthOfYear) {
                buffer.append(", ");
            } else {
                buffer.append(" und ");
            }
        }

        previousYear = current.getYear();
        current = next;
        next = overNext;
        overNext = datesIterator.hasNext() ? datesIterator.next() : null;
    } while (current != null);
}

From source file:org.kitodo.production.model.bibliography.course.CourseToGerman.java

License:Open Source License

/**
 * The method appendDate() writes a date to the buffer.
 *
 * @param buffer/*from  w w w.  j  a v  a  2  s.c  o  m*/
 *            Buffer to write to
 * @param date
 *            Date to write
 */
private static void appendDate(StringBuilder buffer, LocalDate date) {
    buffer.append(date.getDayOfMonth());
    buffer.append(". ");
    buffer.append(MONTH_NAMES[date.getMonthOfYear()]);
    buffer.append(' ');
    buffer.append(date.getYear());
}

From source file:org.kuali.kpme.core.accrualcategory.rule.service.AccrualCategoryRuleServiceImpl.java

License:Educational Community License

public AccrualCategoryRule getAccrualCategoryRuleForDate(AccrualCategory accrualCategory, LocalDate currentDate,
        LocalDate serviceDate) {/*from   w  w w.ja  v a 2s. c  om*/
    if (serviceDate == null) {
        return null;
    }
    List<AccrualCategoryRule> acrList = this
            .getActiveAccrualCategoryRules(accrualCategory.getLmAccrualCategoryId());
    for (AccrualCategoryRule acr : acrList) {
        String uot = acr.getServiceUnitOfTime();
        int startTime = acr.getStart().intValue();
        int endTime = acr.getEnd().intValue();

        LocalDate startDate = serviceDate;
        LocalDate endDate = serviceDate;
        if (uot.equals("M")) { // monthly
            startDate = startDate.plusMonths(startTime);
            endDate = endDate.plusMonths(endTime).minusDays(1);
        } else if (uot.endsWith("Y")) { // yearly
            startDate = startDate.plusYears(startTime);
            endDate = endDate.plusYears(endTime).minusDays(1);
        }

        // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
        if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
            startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
        }
        if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
            endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
        }

        if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
            return acr;
        }
    }
    return null;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public boolean isDateAtEarnInterval(LocalDate aDate, String earnInterval) {
    boolean atEarnInterval = false;
    if (HrConstants.ACCRUAL_EARN_INTERVAL_MAP.containsKey(earnInterval)) {
        if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.DAILY)) {
            atEarnInterval = true;/*from   w  w  w .  ja  v  a2  s  .c om*/
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.WEEKLY)) {
            // figure out if the day is a Saturday
            if (aDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.SEMI_MONTHLY)) {
            // either the 15th or the last day of the month
            if (aDate.getDayOfMonth() == 15 || aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.MONTHLY)) {
            // the last day of the month
            if (aDate.getDayOfMonth() == aDate.dayOfMonth().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.YEARLY)) {
            // the last day of the year
            if (aDate.getDayOfYear() == aDate.dayOfYear().getMaximumValue()) {
                atEarnInterval = true;
            }
        } else if (earnInterval.equals(HrConstants.ACCRUAL_EARN_INTERVAL_CODE.NO_ACCRUAL)) {
            // no calculation
        }
    }
    return atEarnInterval;
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

@Override
public void calculateFutureAccrualUsingPlanningMonth(String principalId, LocalDate asOfDate,
        String runAsPrincipalId) {
    PrincipalHRAttributes phra = HrServiceLocator.getPrincipalHRAttributeService()
            .getPrincipalCalendar(principalId, asOfDate);
    if (phra != null) {
        // use the date from pay period to get the leave plan
        LeavePlan lp = HrServiceLocator.getLeavePlanService().getLeavePlan(phra.getLeavePlan(), asOfDate);
        if (lp != null && StringUtils.isNotEmpty(lp.getPlanningMonths())) {
            // go back a year 
            LocalDate startDate = asOfDate.minusYears(1);
            if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
            }/*w  w  w  .j ava 2  s.co  m*/
            // go forward using planning months
            LocalDate endDate = asOfDate.plusMonths(Integer.parseInt(lp.getPlanningMonths()));
            // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
            if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
            }
            runAccrual(principalId, startDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay(), true,
                    runAsPrincipalId);

        }
    }
}

From source file:org.kuali.kpme.tklm.leave.accrual.service.AccrualServiceImpl.java

License:Educational Community License

public List<AccrualCategoryRule> getAccrualCategoryRulesForDate(List<AccrualCategoryRule> acrList,
        String accrualCategoryId, LocalDate currentDate, LocalDate serviceDate) {
    List<AccrualCategoryRule> aList = new ArrayList<AccrualCategoryRule>();
    if (CollectionUtils.isNotEmpty(acrList)) {
        for (AccrualCategoryRule acr : acrList) {
            if (acr.getLmAccrualCategoryId().equals(accrualCategoryId)) {
                String uot = acr.getServiceUnitOfTime();
                int startTime = acr.getStart().intValue();
                int endTime = acr.getEnd().intValue();

                LocalDate startDate = serviceDate;
                LocalDate endDate = serviceDate;
                if (uot.equals("M")) { // monthly
                    startDate = startDate.plusMonths(startTime);
                    endDate = endDate.plusMonths(endTime).minusDays(1);
                } else if (uot.endsWith("Y")) { // yearly
                    startDate = startDate.plusYears(startTime);
                    endDate = endDate.plusYears(endTime).minusDays(1);
                }//  w w  w  . j  a  v a2 s . c o  m

                // max days in months differ, if the date is bigger than the max day, set it to the max day of the month
                if (startDate.getDayOfMonth() > startDate.dayOfMonth().getMaximumValue()) {
                    startDate = startDate.withDayOfMonth(startDate.dayOfMonth().getMaximumValue());
                }
                if (endDate.getDayOfMonth() > endDate.dayOfMonth().getMaximumValue()) {
                    endDate = endDate.withDayOfMonth(endDate.dayOfMonth().getMaximumValue());
                }

                if (currentDate.compareTo(startDate) >= 0 && currentDate.compareTo(endDate) <= 0) {
                    aList.add(acr);
                }
            }
        }
    }
    return aList;
}