public static DateTime rollForwardWith(ReadableInstant now, AbstractPartial lp) { DateTime dt = lp.toDateTime(now); while (dt.isBefore(now)) { dt = dt.withFieldAdded(lp.getFieldTypes()[0].getRangeDurationType(), 1); } return dt; }
@Override public String format(final AbstractPartial target, String pattern) { try { return DateTimeFormat.forPattern(pattern).withLocale(locale).print(target); } catch (final Exception e) { throw new TemplateProcessingException( "Error formatting Joda LocalTime with pattern '" + pattern + "' for locale " + this.locale, e); } }
private Calendar convertPartialToCalendar(AbstractPartial partial) { Calendar calendar = Calendar.getInstance(); calendar.clear(); DateTimeFieldType[] fieldTypes = partial.getFieldTypes(); for (DateTimeFieldType fieldType : fieldTypes) { if (fieldType.equals(DateTimeFieldType.dayOfMonth())) { calendar.set(Calendar.DAY_OF_MONTH, partial.get(DateTimeFieldType.dayOfMonth())); continue; } if (fieldType.equals(DateTimeFieldType.monthOfYear())) { calendar.set(Calendar.MONTH, partial.get(DateTimeFieldType.monthOfYear()) - 1); continue; } if (fieldType.equals(DateTimeFieldType.year())) { calendar.set(Calendar.YEAR, partial.get(DateTimeFieldType.year())); continue; } if (fieldType.equals(DateTimeFieldType.hourOfDay())) { calendar.set(Calendar.HOUR_OF_DAY, partial.get(DateTimeFieldType.hourOfDay())); continue; } if (fieldType.equals(DateTimeFieldType.minuteOfHour())) { calendar.set(Calendar.MINUTE, partial.get(DateTimeFieldType.minuteOfHour())); continue; } if (fieldType.equals(DateTimeFieldType.secondOfMinute())) { calendar.set(Calendar.SECOND, partial.get(DateTimeFieldType.secondOfMinute())); continue; } } return calendar; }
private Date convertPartialToDate(AbstractPartial partial) { if (partial == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.clear(); if (isHour()) { calendar.set(Calendar.HOUR_OF_DAY, partial.get(DateTimeFieldType.hourOfDay())); } if (isMinute()) { calendar.set(Calendar.MINUTE, partial.get(DateTimeFieldType.minuteOfHour())); } return calendar.getTime(); }
private Date convertPartialToDate(AbstractPartial partial) { if (partial == null) { return null; } Calendar calendar = Calendar.getInstance(); calendar.clear(); if (isDay()) { calendar.set(Calendar.DAY_OF_MONTH, partial.get(DateTimeFieldType.dayOfMonth())); } if (isMonth()) { calendar.set(Calendar.MONTH, partial.get(DateTimeFieldType.monthOfYear()) - 1); } if (isYear()) { calendar.set(Calendar.YEAR, partial.get(DateTimeFieldType.year())); } if (isHour()) { calendar.set(Calendar.HOUR_OF_DAY, partial.get(DateTimeFieldType.hourOfDay())); } if (isMinute()) { calendar.set(Calendar.MINUTE, partial.get(DateTimeFieldType.minuteOfHour())); } if (isSecond()) { calendar.set(Calendar.SECOND, partial.get(DateTimeFieldType.secondOfMinute())); } return calendar.getTime(); }
@Override public boolean before(final AbstractPartial date1, final AbstractPartial date2) { return date1.isBefore(date2); }
@Override public boolean after(final AbstractPartial date1, final AbstractPartial date2) { return date1.isAfter(date2); }
@Override public boolean equals(final AbstractPartial date1, final AbstractPartial date2) { return date1.equals(date2); }
@Override protected HtmlComponent createTextField(Object object, Class type) { Date date = convertPartialToDate((AbstractPartial) object); return super.createTextField(date, type); }
/** * Usage: #joda.format(target, pattern) * * @param target Joda {@link org.joda.time.LocalDate} or {@link org.joda.time.LocalTime} * @param pattern Valid {@link org.joda.time.format.DateTimeFormatter} pattern * @return Formatted string */ String format(AbstractPartial target, String pattern);
/** * Usage: #joda.before(date1, date2) * * @see org.joda.time.base.AbstractPartial#isBefore(org.joda.time.ReadablePartial) */ boolean before(AbstractPartial date1, AbstractPartial date2);
/** * Usage: #joda.after(date1, date2) * * @see org.joda.time.base.AbstractPartial#isAfter(org.joda.time.ReadablePartial) */ boolean after(AbstractPartial date1, AbstractPartial date2);
/** * Usage: #joda.equals(date1, date2) * * @see org.joda.time.base.AbstractPartial#equals(java.lang.Object) */ boolean equals(AbstractPartial date1, AbstractPartial date2);