List of usage examples for org.joda.time LocalDate getMonthOfYear
public int getMonthOfYear()
From source file:org.apache.isis.schema.utils.jaxbadapters.XmlCalendarFactory.java
License:Apache License
public static XMLGregorianCalendar create(LocalDate localDate) { return localDate != null ? withTypeFactoryDo(dtf -> dtf.newXMLGregorianCalendarDate(localDate.getYear(), localDate.getMonthOfYear(), localDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED)) : null;//from w ww .j a v a 2 s . c o m }
From source file:org.estatio.services.clock.ClockService.java
License:Apache License
static LocalDate beginningOfQuarter(final LocalDate date) { final LocalDate beginningOfMonth = beginningOfMonth(date); final int monthOfYear = beginningOfMonth.getMonthOfYear(); final int quarter = (monthOfYear - 1) / MONTHS_IN_QUARTER; // 0, 1, 2, 3 final int monthStartOfQuarter = quarter * MONTHS_IN_QUARTER + 1; return beginningOfMonth.minusMonths(monthOfYear - monthStartOfQuarter); }
From source file:org.fornax.cartridges.sculptor.framework.richclient.databinding.JodaLocalDateObservableValue.java
License:Apache License
private void setLocalDateSelection(LocalDate date) { if (date == null) { // TODO how to handle null date = new LocalDate(); }/*from ww w . j ava2s. c o m*/ dateTime.setYear(date.getYear()); dateTime.setMonth(date.getMonthOfYear() - 1); dateTime.setDay(date.getDayOfMonth()); }
From source file:org.goobi.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 ww w. j a va 2 s .com * * @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); 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 = false; 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 "); } } } if (next != null) { 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.goobi.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 .jav a 2 s . com * 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()); return; }
From source file:org.goobi.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:/*from w ww.ja v a2s .c o 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 */ @SuppressWarnings("incomplete-switch") 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" + Integer.toString(((date.getMonthOfYear() - 1) / 3) + 1); case WEEKS: return ISODateTimeFormat.weekyearWeek().print(date); case YEARS: return ISODateTimeFormat.year().print(date); } throw new NotImplementedException(); }
From source file:org.gravidence.gravifon.util.DateTimeUtils.java
License:Open Source License
/** * Converts local date object to array of date fields.<p> * Resulting array content is as follows: <code>[yyyy,MM,dd]</code>. * //from w w w. j av a2s . c om * @param value date object * @return array of date fields */ public static int[] localDateToArray(LocalDate value) { int[] result; if (value == null) { result = null; } else { result = new int[3]; result[0] = value.getYear(); result[1] = value.getMonthOfYear(); result[2] = value.getDayOfMonth(); } return result; }
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;/* w ww . j a va 2s .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();/* ww w . ja v a 2 s .c o m*/ 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 www .j a v a 2 s .co m // 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)); }