static DateFormatter forPattern(String input) { if (Strings.hasLength(input) == false) { throw new IllegalArgumentException("No date pattern provided"); } if (input.startsWith("8") == false) { return Joda.forPattern(input); } // force java 8 date format List<DateFormatter> formatters = new ArrayList<>(); for (String pattern : Strings.delimitedListToStringArray(input.substring(1), "||")) { if (Strings.hasLength(pattern) == false) { throw new IllegalArgumentException("Cannot have empty element in multi date format pattern: " + input); } formatters.add(DateFormatters.forPattern(pattern)); } if (formatters.size() == 1) { return formatters.get(0); } return new DateFormatters.MergedDateFormatter(input, formatters); } }
formatter = forPattern(input).parser; } else { DateTimeFormatter dateTimeFormatter = null; for (int i = 0; i < formats.length; i++) { JodaDateFormatter currentFormatter = forPattern(formats[i]); DateTimeFormatter currentParser = currentFormatter.parser; if (dateTimeFormatter == null) {
public Timestamp(boolean enabled, String format, String defaultTimestamp, Boolean ignoreMissing) { this.enabled = enabled; this.format = format; this.dateTimeFormatter = Joda.forPattern(format); this.defaultTimestamp = defaultTimestamp; this.ignoreMissing = ignoreMissing; }
public DateTime(String format, DateTimeZone timezone) { this.formatter = Joda.forPattern(format); this.timeZone = timezone != null ? timezone : DateTimeZone.UTC; }
/** * In case of format field, we can parse the from/to fields using this time format */ public RangeQueryBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("format cannot be null"); } this.format = Joda.forPattern(format); return this; }
/** * In case of format field, we can parse the from/to fields using this time format */ public RangeQueryBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("format cannot be null"); } this.format = Joda.forPattern(format); return this; }
/** * In case of format field, we can parse the from/to fields using this time format */ public RangeQueryBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("format cannot be null"); } this.format = Joda.forPattern(format); return this; }
public static FormatDateTimeFormatter parseDateTimeFormatter(Object node) { if (node instanceof String) { return Joda.forPattern((String) node); } throw new IllegalArgumentException("Invalid format: [" + node.toString() + "]: expected string value"); }
@JsonCreator public TimestampField(@JsonProperty("field") String fieldName, @JsonProperty("format") String format) { if (format == null) { format = "dateOptionalTime"; } this.fieldName = fieldName; this.formatter = Joda.forPattern(format); }
@Override public java.lang.Long valueOf(String value, String fmt) { FormatDateTimeFormatter f = formatter; if (fmt != null) { f = Joda.forPattern(fmt); } return f.parser().parseDateTime(value).getMillis(); }
public Timestamp(boolean enabled, String path, String format, String defaultTimestamp, Boolean ignoreMissing) { this.enabled = enabled; this.path = path; if (path == null) { pathElements = Strings.EMPTY_ARRAY; } else { pathElements = Strings.delimitedListToStringArray(path, "."); } this.format = format; this.dateTimeFormatter = Joda.forPattern(format); this.defaultTimestamp = defaultTimestamp; this.ignoreMissing = ignoreMissing; }
public DateTime(StreamInput in) throws IOException { this(Joda.forPattern(in.readString()), DateTimeZone.forID(in.readString())); }
@Override public DocValueFormat docValueFormat(@Nullable String format, DateTimeZone timeZone) { FormatDateTimeFormatter dateTimeFormatter = this.dateTimeFormatter; if (format != null) { dateTimeFormatter = Joda.forPattern(format); } if (timeZone == null) { timeZone = DateTimeZone.UTC; } return new DocValueFormat.DateTime(dateTimeFormatter, timeZone); } }
@Override public DocValueFormat docValueFormat(@Nullable String format, DateTimeZone timeZone) { FormatDateTimeFormatter dateTimeFormatter = this.dateTimeFormatter; if (format != null) { dateTimeFormatter = Joda.forPattern(format); } if (timeZone == null) { timeZone = DateTimeZone.UTC; } return new DocValueFormat.DateTime(dateTimeFormatter, timeZone); } }
@Override public DocValueFormat docValueFormat(@Nullable String format, DateTimeZone timeZone) { FormatDateTimeFormatter dateTimeFormatter = this.dateTimeFormatter; if (format != null) { dateTimeFormatter = Joda.forPattern(format); } if (timeZone == null) { timeZone = DateTimeZone.UTC; } return new DocValueFormat.DateTime(dateTimeFormatter, timeZone); } }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); dateFormatter = Joda.forPattern(in.readString()); }
@Override protected java.lang.Long valueOf(String value, String optionalFormat) { FormatDateTimeFormatter dateFormatter = this.dateFormatter; if (optionalFormat != null) { dateFormatter = Joda.forPattern(optionalFormat); } return dateFormatter.parser().parseMillis(value); }
@Override public DocValueFormat docValueFormat(@Nullable String format, DateTimeZone timeZone) { FormatDateTimeFormatter dateTimeFormatter = this.dateTimeFormatter; if (format != null) { dateTimeFormatter = Joda.forPattern(format); } if (timeZone == null) { timeZone = DateTimeZone.UTC; } return new DocValueFormat.DateTime(dateTimeFormatter, timeZone); } }
@Override public void readFrom(StreamInput in) throws IOException { formatter = Joda.forPattern(in.readString()); timeZone = DateTimeZone.forID(in.readString()); }
private static DocValueFormat resolveFormat(@Nullable String format, @Nullable ValueType valueType, @Nullable DateTimeZone tz) { if (valueType == null) { return DocValueFormat.RAW; // we can't figure it out } DocValueFormat valueFormat = valueType.defaultFormat; if (valueFormat instanceof DocValueFormat.Decimal && format != null) { valueFormat = new DocValueFormat.Decimal(format); } if (valueFormat instanceof DocValueFormat.DateTime && format != null) { valueFormat = new DocValueFormat.DateTime(Joda.forPattern(format), tz != null ? tz : DateTimeZone.UTC); } return valueFormat; }