Example usage for org.joda.time LocalDate getMonthOfYear

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

Introduction

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

Prototype

public int getMonthOfYear() 

Source Link

Document

Get the month of year field value.

Usage

From source file:org.jruby.ext.date.RubyDate.java

License:LGPL

private static DateTime todayDate(final ThreadContext context, final Chronology chrono) {
    org.joda.time.LocalDate today = new org.joda.time.LocalDate(RubyTime.getLocalTimeZone(context.runtime));
    return new DateTime(today.getYear(), today.getMonthOfYear(), today.getDayOfMonth(), 0, 0, chrono);
}

From source file:org.jtotus.gui.graph.GraphPrinter.java

License:Open Source License

private Day localDateToDay(LocalDate date) {
    Day tmpDay = new Day(date.getDayOfMonth(), date.getMonthOfYear(), date.getYear());

    return tmpDay;
}

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;
    }//from  w w w  . ja  va  2 s. 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;
    }//w  w  w  . j  a  va 2 s  . 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. jav  a  2  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/*from  w  w  w . j a va 2  s.com*/
 *            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  w w  .j  a  v a2 s.  co 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 www . jav 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.kitodo.production.model.bibliography.course.Granularity.java

License:Open Source License

/**
 * The function format() converts a given LocalDate to a String
 * representation of the date in the given granularity. For the 1st January
 * 2000 it will return://  ww w. j a v a2  s .co  m
 * <p/>
 *  for DAYS: 2000-01-01  for WEEKS: 1999-W52  for MONTHS: 2000-01  for
 * QUARTERS: 2000/Q1  for YEARS: 2000
 *
 * <p>
 * The remaining cases are undefined and will throw NotImplementedException.
 * </p>
 *
 * @param date
 *            date to format
 * @return an expression of the date in the given granularity
 */
public String format(LocalDate date) {
    switch (this) {
    case DAYS:
        return ISODateTimeFormat.date().print(date);
    case MONTHS:
        return ISODateTimeFormat.yearMonth().print(date);
    case QUARTERS:
        return ISODateTimeFormat.year().print(date) + "/Q" + ((date.getMonthOfYear() - 1) / 3) + 1;
    case WEEKS:
        return ISODateTimeFormat.weekyearWeek().print(date);
    case YEARS:
        return ISODateTimeFormat.year().print(date);
    default:
        throw new NotImplementedException();
    }
}

From source file:org.libreplan.importers.notifications.realization.SendEmailOnMilestoneReached.java

License:Open Source License

public void checkMilestoneDate() {
    List<TaskElement> milestones = taskElementDAO.getTaskElementsWithMilestones();

    LocalDate date = new LocalDate();
    int currentYear = date.getYear();
    int currentMonth = date.getMonthOfYear();
    int currentDay = date.getDayOfMonth();

    for (TaskElement item : milestones) {
        if (item.getDeadline() != null) {

            LocalDate deadline = item.getDeadline();
            int deadlineYear = deadline.getYear();
            int deadlineMonth = deadline.getMonthOfYear();
            int deadlineDay = deadline.getDayOfMonth();

            if (currentYear == deadlineYear && currentMonth == deadlineMonth && currentDay == deadlineDay) {
                sendEmailNotificationToManager(item);
            }/*from w  w  w . j av a  2  s. c  o m*/

        }
    }
}