@Override protected void setupFieldType(BuilderContext context) { super.setupFieldType(context); FormatDateTimeFormatter dateTimeFormatter = fieldType().dateTimeFormatter; if (!locale.equals(dateTimeFormatter.locale())) { fieldType().setDateTimeFormatter( new FormatDateTimeFormatter(dateTimeFormatter.format(), dateTimeFormatter.parser(), dateTimeFormatter.printer(), locale)); } }
DateMathParser getForceDateParser() { // pkg private for testing if (this.format != null) { return this.format.toDateMathParser(); } return null; }
return new FormatDateTimeFormatter(input, ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC), ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale); return new FormatDateTimeFormatter(input, StrictISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC), StrictISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale); formatter = forPattern(input, locale).parser(); } else { DateTimeFormatter dateTimeFormatter = null; for (int i = 0; i < formats.length; i++) { FormatDateTimeFormatter currentFormatter = forPattern(formats[i], locale); DateTimeFormatter currentParser = currentFormatter.parser(); if (dateTimeFormatter == null) { dateTimeFormatter = currentFormatter.printer(); return new FormatDateTimeFormatter(input, formatter.withZone(DateTimeZone.UTC), locale);
public static synchronized NamedAnalyzer buildNamedAnalyzer(FormatDateTimeFormatter formatter, int precisionStep) { IntObjectHashMap<NamedAnalyzer> precisionMap = globalAnalyzers.get(formatter.format()); if (precisionMap == null) { precisionMap = new IntObjectHashMap<>(); globalAnalyzers.put(formatter.format(), precisionMap); } NamedAnalyzer namedAnalyzer = precisionMap.get(precisionStep); if (namedAnalyzer == null) { String name = "_date/" + ((precisionStep == Integer.MAX_VALUE) ? "max" : precisionStep); namedAnalyzer = new NamedAnalyzer(name, AnalyzerScope.GLOBAL, new NumericDateAnalyzer(precisionStep, formatter.parser())); precisionMap.put(precisionStep, namedAnalyzer); } return namedAnalyzer; }
@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(); }
@Override public String getMaxValueAsString() { return formatter.printer().print(maxValue); }
FormatDateTimeFormatter formatter = new FormatDateTimeFormatter(dateFormatterPattern, parser, Locale.ROOT); DateMathParser dateMathParser = new DateMathParser(formatter); long millis = dateMathParser.parse(mathExpression, context::getStartTime, false, timeZone); String time = formatter.printer().print(millis); beforePlaceHolderSb.append(time); inPlaceHolderSb = new StringBuilder();
/** * Gets the format field to parse the from/to fields */ public String format() { return this.format == null ? null : this.format.format(); }
FormatDateTimeFormatter formatter = new FormatDateTimeFormatter(dateFormatterPattern, parser, Locale.ROOT); DateMathParser dateMathParser = formatter.toDateMathParser(); long millis = dateMathParser.parse(mathExpression, context::getStartTime, false, DateUtils.dateTimeZoneToZoneId(timeZone)); String time = formatter.printer().print(millis); beforePlaceHolderSb.append(time); inPlaceHolderSb = new StringBuilder();
public static FormatDateTimeFormatter getStrictStandardDateFormatter() { // 2014/10/10 DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .toFormatter() .withZoneUTC(); // 2014/10/10 12:12:12 DateTimeFormatter longFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .appendLiteral(' ') .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2) .toFormatter() .withZoneUTC(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)}); return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT); }
return new FormatDateTimeFormatter(input, ISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC), ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale); return new FormatDateTimeFormatter(input, StrictISODateTimeFormat.dateOptionalTimeParser().withZone(DateTimeZone.UTC), StrictISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC), locale); formatter = forPattern(input, locale).parser(); } else { DateTimeFormatter dateTimeFormatter = null; for (int i = 0; i < formats.length; i++) { FormatDateTimeFormatter currentFormatter = forPattern(formats[i], locale); DateTimeFormatter currentParser = currentFormatter.parser(); if (dateTimeFormatter == null) { dateTimeFormatter = currentFormatter.printer(); return new FormatDateTimeFormatter(input, formatter.withZone(DateTimeZone.UTC), locale);
private long parseDateTime(String value, DateTimeZone timeZone, boolean roundUpIfNoTime) { DateTimeFormatter parser = dateTimeFormatter.parser(); if (timeZone != null) { parser = parser.withZone(timeZone); } try { MutableDateTime date; // We use 01/01/1970 as a base date so that things keep working with date // fields that are filled with times without dates if (roundUpIfNoTime) { date = new MutableDateTime(1970, 1, 1, 23, 59, 59, 999, DateTimeZone.UTC); } else { date = new MutableDateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeZone.UTC); } final int end = parser.parseInto(date, value, 0); if (end < 0) { int position = ~end; throw new IllegalArgumentException("Parse failure at index [" + position + "] of [" + value + "]"); } else if (end != value.length()) { throw new IllegalArgumentException("Unrecognized chars at the end of [" + value + "]: [" + value.substring(end) + "]"); } return date.getMillis(); } catch (IllegalArgumentException e) { throw new ElasticsearchParseException("failed to parse date field [{}] with format [{}]", e, value, dateTimeFormatter.format()); } }
public long get(Map<String, Object> msg) { Object value = msg.get(fieldName); if (value instanceof Number) { return ((Number) value).longValue(); } return formatter.parser().parseMillis(value.toString()); } }
@Override public String getMinValueAsString() { return formatter.printer().print(minValue); }
FormatDateTimeFormatter formatter = new FormatDateTimeFormatter(dateFormatterPattern, parser, Locale.ROOT); DateMathParser dateMathParser = new DateMathParser(formatter); long millis = dateMathParser.parse(mathExpression, context::getStartTime, false, timeZone); String time = formatter.printer().print(millis); beforePlaceHolderSb.append(time); inPlaceHolderSb = new StringBuilder();
/** * Gets the format field to parse the from/to fields */ public String format() { return this.format == null ? null : this.format.format(); }
public static FormatDateTimeFormatter getStrictStandardDateFormatter() { // 2014/10/10 DateTimeFormatter shortFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .toFormatter() .withZoneUTC(); // 2014/10/10 12:12:12 DateTimeFormatter longFormatter = new DateTimeFormatterBuilder() .appendFixedDecimal(DateTimeFieldType.year(), 4) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2) .appendLiteral('/') .appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2) .appendLiteral(' ') .appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.minuteOfHour(), 2) .appendLiteral(':') .appendFixedSignedDecimal(DateTimeFieldType.secondOfMinute(), 2) .toFormatter() .withZoneUTC(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[]{longFormatter.getParser(), shortFormatter.getParser(), new EpochTimeParser(true)}); return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT); }
@Override protected void setupFieldType(BuilderContext context) { super.setupFieldType(context); FormatDateTimeFormatter dateTimeFormatter = fieldType().dateTimeFormatter; if (!locale.equals(dateTimeFormatter.locale())) { fieldType().setDateTimeFormatter( new FormatDateTimeFormatter(dateTimeFormatter.format(), dateTimeFormatter.parser(), dateTimeFormatter.printer(), locale)); } }