@Override @Nullable public Object convert(@Nullable String value) { if (isNullOrEmpty(value)) { return null; } LOG.debug("Trying to parse date <{}> with pattern <{}>, locale <{}>, and timezone <{}>.", value, dateFormat, locale, timeZone); final DateTimeFormatter formatter; if (containsTimeZone) { formatter = DateTimeFormat .forPattern(dateFormat) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withLocale(locale); } else { formatter = DateTimeFormat .forPattern(dateFormat) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withLocale(locale) .withZone(timeZone); } return DateTime.parse(value, formatter); } }
public TimestampParser(String[] formatStrings) { this.formatStrings = formatStrings; // create formatter that includes all of the input patterns if (formatStrings != null && formatStrings.length > 0) { DateTimeParser[] parsers = new DateTimeParser[formatStrings.length]; for (int idx = 0; idx < formatStrings.length; ++idx) { String formatString = formatStrings[idx]; if (formatString.equalsIgnoreCase(millisFormatString)) { // Use milliseconds parser if pattern matches our special-case millis pattern string parsers[idx] = new MillisDateFormatParser(); } else { parsers[idx] = DateTimeFormat.forPattern(formatString).getParser(); } } fmt = new DateTimeFormatterBuilder() .append(null, parsers) .toFormatter() .withDefaultYear(1970); } }
public JodaDateFormatter(String pattern, DateTimeFormatter parser, DateTimeFormatter printer) { this.pattern = pattern; this.printer = printer.withDefaultYear(1970); this.parser = parser.withDefaultYear(1970); }
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) { this.format = format; this.locale = locale; this.printer = locale == null ? printer.withDefaultYear(1970) : printer.withLocale(locale).withDefaultYear(1970); this.parser = locale == null ? parser.withDefaultYear(1970) : parser.withLocale(locale).withDefaultYear(1970); }
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) { this.format = format; this.locale = Objects.requireNonNull(locale, "A locale is required as JODA otherwise uses the default locale"); this.printer = printer.withLocale(locale).withDefaultYear(1970); this.parser = parser.withLocale(locale).withDefaultYear(1970); }
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) { this.format = format; this.locale = Objects.requireNonNull(locale, "A locale is required as JODA otherwise uses the default locale"); this.printer = printer.withLocale(locale).withDefaultYear(1970); this.parser = parser.withLocale(locale).withDefaultYear(1970); }
@Override Function<String, DateTime> getFunction(String format, DateTimeZone timezone, Locale locale) { DateTimeFormatter parser = DateTimeFormat.forPattern(format).withZone(timezone).withLocale(locale); return text -> parser.withDefaultYear((new DateTime(DateTimeZone.UTC)).getYear()).parseDateTime(text); } };
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) { this.format = format; this.locale = Objects.requireNonNull(locale, "A locale is required as JODA otherwise uses the default locale"); this.printer = printer.withLocale(locale).withDefaultYear(1970); this.parser = parser.withLocale(locale).withDefaultYear(1970); }
public FormatDateTimeFormatter(String format, DateTimeFormatter parser, DateTimeFormatter printer, Locale locale) { this.format = format; this.locale = Objects.requireNonNull(locale, "A locale is required as JODA otherwise uses the default locale"); this.printer = printer.withLocale(locale).withDefaultYear(1970); this.parser = parser.withLocale(locale).withDefaultYear(1970); }
protected DateTimeFormatter getDateTimeFormatter(final String pattern, final Locale locale) { return DateTimeFormat.forPattern(pattern).withLocale(locale).withZone(timeZone).withPivotYear(PIVOT_YEAR).withDefaultYear(currentYear); }
@Override @Nullable public Object convert(@Nullable String value) { if (isNullOrEmpty(value)) { return null; } LOG.debug("Trying to parse date <{}> with pattern <{}> and timezone <{}>.", value, dateFormat, timeZone); final DateTimeFormatter formatter = DateTimeFormat .forPattern(dateFormat) .withLocale(locale) .withDefaultYear(YearMonth.now(timeZone).getYear()) .withZone(timeZone); return DateTime.parse(value, formatter); } }
public static String transformPathString(String input) { String output = input; String datePattern = "DATE\\(([^)]+)\\)"; String varPattern = "\\$\\{(.*)}"; if (output == null) { return null; } while (output.matches("(.*)" + datePattern + "(.*)")) { String format = output.split("DATE\\(")[1].split("\\)")[0].trim(); String value = DateTimeFormat.forPattern(format) .withDefaultYear(new DateTime().get(DateTimeFieldType.yearOfEra())).withLocale(Locale.US) .print(new DateTime()); output = output.replaceFirst(datePattern, value); } while (output.matches("(.*)" + varPattern + "(.*)")) { String name = output.split("\\$\\{")[1].split("}")[0].trim(); if (StringUtils.isNotBlank(System.getProperty(name))) { output = output.replaceFirst(varPattern, System.getProperty(name)); } else { output = output.replaceFirst(varPattern, System.getenv(name)); } } return output; } public static String replaceHtmlEntitiesWithCodes(String input) throws IOException {
public TimestampParser(String[] formatStrings) { this.formatStrings = formatStrings; // create formatter that includes all of the input patterns if (formatStrings != null && formatStrings.length > 0) { DateTimeParser[] parsers = new DateTimeParser[formatStrings.length]; for (int idx = 0; idx < formatStrings.length; ++idx) { String formatString = formatStrings[idx]; if (formatString.equalsIgnoreCase(millisFormatString)) { // Use milliseconds parser if pattern matches our special-case millis pattern string parsers[idx] = new MillisDateFormatParser(); } else { parsers[idx] = DateTimeFormat.forPattern(formatString).getParser(); } } fmt = new DateTimeFormatterBuilder() .append(null, parsers) .toFormatter() .withDefaultYear(1970); } }