@Override public String toString() { return "Version " + this.version.toString(DateTimeFormat.shortDateTime()) + " at path " + this.path; }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
public Builder timeFormatter(String formatOrConstant) { if (formatOrConstant == null || formatOrConstant.equalsIgnoreCase("NONE") || formatOrConstant.equalsIgnoreCase("FALSE")) { timeFormatter = null; } else if (formatOrConstant.length() == 0 || formatOrConstant.equalsIgnoreCase("DEFAULT")) { timeFormatter = DateTimeFormat.forPattern("HH:mm:ss.SSS"); } else if (formatOrConstant.equalsIgnoreCase("ISO8601")) { timeFormatter = ISODateTimeFormat.dateTime(); } else if (formatOrConstant.equalsIgnoreCase("SHORT")) { timeFormatter = DateTimeFormat.shortDateTime(); } else if (formatOrConstant.equalsIgnoreCase("MEDIUM")) { timeFormatter = DateTimeFormat.mediumDateTime(); } else if (formatOrConstant.equalsIgnoreCase("LONG")) { timeFormatter = DateTimeFormat.longDateTime(); } else { try { timeFormatter = DateTimeFormat.forPattern(formatOrConstant); } catch (IllegalArgumentException exp) { throw new IllegalArgumentException( "Cannot parse log date specification '" + formatOrConstant + "'." + "Must be either DEFAULT, NONE, ISO8601, SHORT, MEDIUM, LONG or a " + "format string parseable by DateTimeFormat. See " + "http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html"); } } return this; }
@Test public void dateToStringWithFormat() { JodaTimeFormatterRegistrar registrar = new JodaTimeFormatterRegistrar(); registrar.setDateTimeFormatter(org.joda.time.format.DateTimeFormat.shortDateTime()); setup(registrar); Date date = new Date(); Object actual = this.conversionService.convert(date, TypeDescriptor.valueOf(Date.class), TypeDescriptor.valueOf(String.class)); String expected = JodaTimeContextHolder.getFormatter(org.joda.time.format.DateTimeFormat.shortDateTime(), Locale.US).print(new DateTime(date)); assertEquals(expected, actual); }
@Override public String toString() { return "Version " + this.version.toString(DateTimeFormat.shortDateTime()) + " at path " + this.path; }
@Override public String toString() { return "Version " + this.version.toString(DateTimeFormat.shortDateTime()) + " at path " + this.path; }
public Builder timeFormatter(String formatOrConstant) { if (formatOrConstant == null || formatOrConstant.equalsIgnoreCase("NONE") || formatOrConstant.equalsIgnoreCase("FALSE")) { timeFormatter = null; } else if (formatOrConstant.length() == 0 || formatOrConstant.equalsIgnoreCase("DEFAULT")) { timeFormatter = DateTimeFormat.forPattern("HH:mm:ss.SSS"); } else if (formatOrConstant.equalsIgnoreCase("ISO8601")) { timeFormatter = ISODateTimeFormat.dateTime(); } else if (formatOrConstant.equalsIgnoreCase("SHORT")) { timeFormatter = DateTimeFormat.shortDateTime(); } else if (formatOrConstant.equalsIgnoreCase("MEDIUM")) { timeFormatter = DateTimeFormat.mediumDateTime(); } else if (formatOrConstant.equalsIgnoreCase("LONG")) { timeFormatter = DateTimeFormat.longDateTime(); } else { try { timeFormatter = DateTimeFormat.forPattern(formatOrConstant); } catch (IllegalArgumentException exp) { throw new IllegalArgumentException( "Cannot parse log date specification '" + formatOrConstant + "'." + "Must be either DEFAULT, NONE, ISO8601, SHORT, MEDIUM, LONG or a " + "format string parseable by DateTimeFormat. See " + "http://joda-time.sourceforge.net/apidocs/org/joda/time/format/DateTimeFormat.html"); } } return this; }
private DateTimeFormatter getFallbackFormatter(Type type) { switch (type) { case DATE: return DateTimeFormat.shortDate(); case TIME: return DateTimeFormat.shortTime(); default: return DateTimeFormat.shortDateTime(); } }
public DateTime convert(String value, Class<? extends DateTime> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } }
private static LocalDateTime parseAsLocalDateTime(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyyMMddhhmmss"), DateTimeFormat.forPattern("yyyyMMddhhmm") }) { try { return formatter.parseLocalDateTime(dateStr); } catch (Exception e) { // continue; } } return null; }
public LocalDateTime convert(String value, Class<? extends LocalDateTime> type, ResourceBundle bundle) { try { DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toLocalDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } } }
private static LocalDate parseAsLocalDate(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyy-MM-dd"), DateTimeFormat.forPattern("yyyyMMdd"), }) { try { return formatter.parseLocalDate(dateStr); } catch (Exception e) { // continue; } } return null; }
private static LocalDateTime parseAsLocalDateTime(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyyMMddhhmmss"), DateTimeFormat.forPattern("yyyyMMddhhmm") }) { try { return formatter.parseLocalDateTime(dateStr); } catch (Exception e) { // continue; } } return null; }
private static LocalDate parseAsLocalDate(String dateStr) { for (DateTimeFormatter formatter : new DateTimeFormatter[] { DateTimeFormat.fullDateTime(), DateTimeFormat.mediumDateTime(), DateTimeFormat.shortDateTime(), DateTimeFormat.forPattern("yyyy-MM-dd"), DateTimeFormat.forPattern("yyyyMMdd"), }) { try { return formatter.parseLocalDate(dateStr); } catch (Exception e) { // continue; } } return null; }