List of usage examples for org.joda.time.format DateTimeFormatterBuilder appendLiteral
public DateTimeFormatterBuilder appendLiteral(String text)
From source file:org.codelibs.elasticsearch.common.joda.StrictISODateTimeFormat.java
License:Apache License
/** * Adds the time fields to the builder./*from w ww . j av a 2 s. c o m*/ * Specification reference: 5.3.1. * * @param bld the builder * @param fields the fields * @param extended whether to use the extended format * @param strictISO whether to be strict * @param reducedPrec whether the date was reduced precision * @param datePresent whether there was a date * @since 1.1 */ private static void time(DateTimeFormatterBuilder bld, Collection<DateTimeFieldType> fields, boolean extended, boolean strictISO, boolean reducedPrec, boolean datePresent) { boolean hour = fields.remove(DateTimeFieldType.hourOfDay()); boolean minute = fields.remove(DateTimeFieldType.minuteOfHour()); boolean second = fields.remove(DateTimeFieldType.secondOfMinute()); boolean milli = fields.remove(DateTimeFieldType.millisOfSecond()); if (!hour && !minute && !second && !milli) { return; } if (hour || minute || second || milli) { if (strictISO && reducedPrec) { throw new IllegalArgumentException( "No valid ISO8601 format for fields because Date was reduced precision: " + fields); } if (datePresent) { bld.appendLiteral('T'); } } if (hour && minute && second || (hour && !second && !milli)) { // OK - HMSm/HMS/HM/H - valid in combination with date } else { if (strictISO && datePresent) { throw new IllegalArgumentException( "No valid ISO8601 format for fields because Time was truncated: " + fields); } if (!hour && (minute && second || (minute && !milli) || second)) { // OK - MSm/MS/M/Sm/S - valid ISO formats } else { if (strictISO) { throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields); } } } if (hour) { bld.appendHourOfDay(2); } else if (minute || second || milli) { bld.appendLiteral('-'); } if (extended && hour && minute) { bld.appendLiteral(':'); } if (minute) { bld.appendMinuteOfHour(2); } else if (second || milli) { bld.appendLiteral('-'); } if (extended && minute && second) { bld.appendLiteral(':'); } if (second) { bld.appendSecondOfMinute(2); } else if (milli) { bld.appendLiteral('-'); } if (milli) { bld.appendLiteral('.'); bld.appendMillisOfSecond(3); } }
From source file:org.codelibs.elasticsearch.common.joda.StrictISODateTimeFormat.java
License:Apache License
/** * Appends the separator if necessary./*from ww w. ja va2s .c o m*/ * * @param bld the builder * @param extended whether to append the separator * @since 1.1 */ private static void appendSeparator(DateTimeFormatterBuilder bld, boolean extended) { if (extended) { bld.appendLiteral('-'); } }
From source file:org.kalypso.ogc.sensor.util.TimestampHelper.java
License:Open Source License
/** * This function creates the date time formatter. * // www. j ava 2 s. c om * @return The date time formater. */ private static DateTimeFormatter createDateTimeFormatter() { /* Create the date time formatter builder. */ final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); builder.appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2); builder.appendLiteral(':'); // $NON-NLS-1$ builder.appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2); return builder.toFormatter(); }