List of usage examples for org.joda.time LocalDate getYear
public int getYear()
From source file:org.jadira.usertype.dateandtime.joda.AbstractMultiColumnDateMidnight.java
License:Apache License
@Override protected DateMidnight fromConvertedColumns(Object[] convertedColumns) { LocalDate datePart = (LocalDate) convertedColumns[0]; DateTimeZoneWithOffset offset = (DateTimeZoneWithOffset) convertedColumns[1]; final DateMidnight result; if (datePart == null) { result = null;/*from www . java 2 s . com*/ } else { result = new DateMidnight(datePart.getYear(), datePart.getMonthOfYear(), datePart.getDayOfMonth(), offset.getStandardDateTimeZone()); } // Handling DST rollover if (datePart != null && offset.getOffsetDateTimeZone() != null && offset.getStandardDateTimeZone() .getOffset(result) > offset.getOffsetDateTimeZone().getOffset(result)) { return new DateMidnight(datePart.getYear(), datePart.getMonthOfYear(), datePart.getDayOfMonth(), offset.getOffsetDateTimeZone()); } return result; }
From source file:org.jpmml.evaluator.FieldValue.java
License:Open Source License
public LocalDateTime asLocalDateTime() { Object value = getValue();/*from www.ja v a 2s . c om*/ if (value instanceof LocalDate) { LocalDate instant = (LocalDate) value; return new LocalDateTime(instant.getYear(), instant.getMonthOfYear(), instant.getDayOfMonth(), 0, 0, 0); } else if (value instanceof LocalDateTime) { return (LocalDateTime) value; } throw new TypeCheckException(DataType.DATE_TIME, value); }
From source file:org.jpmml.evaluator.SecondsSinceDate.java
License:Open Source License
public SecondsSinceDate(LocalDate epoch, LocalDateTime dateTime) { setEpoch(epoch);//from w w w . ja v a 2 s . com // Have to have the same set of fields LocalDateTime epochDateTime = new LocalDateTime(epoch.getYear(), epoch.getMonthOfYear(), epoch.getDayOfMonth(), 0, 0, 0); setSeconds(Seconds.secondsBetween(epochDateTime, dateTime)); }
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; }/*w w w . j a va2 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 ava 2 s.co m*/ 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)./* w w w .j a v a 2s . c om*/ * * 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.DateUtils.java
License:Open Source License
/** * The function sameYear() compares two LocalDate objects in regard to the * question whether their two dates reside in the same year of the calendar * system presumed. Two dates are considered to be in the same year exactly * if none of them is null and their year fields are equal. * * @param current/*w ww . ja v a 2 s . c om*/ * date to compare against * @param next * date to compare, may be null * @return whether the two dates are in the same year */ public static boolean sameYear(LocalDate current, LocalDate next) { if (Objects.isNull(next)) { return false; } return current.getYear() == next.getYear(); }
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./* w ww .j a va 2 s.c om*/ * * @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); }