Skip to content

Commit

Permalink
Add millisecond parser for dynamic date fields mapped from "yyyy/MM/dd"
Browse files Browse the repository at this point in the history
This commit backports commit 4c9327d,
the fix #12977 for #12873 from master to 2.0.
  • Loading branch information
jasontedor committed Aug 19, 2015
1 parent 50d4bca commit 71ec82d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/elasticsearch/common/joda/Joda.java
Expand Up @@ -275,9 +275,9 @@ public static FormatDateTimeFormatter getStrictStandardDateFormatter() {
.toFormatter()
.withZoneUTC();

DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder().append(longFormatter.withZone(DateTimeZone.UTC).getPrinter(), new DateTimeParser[] {longFormatter.getParser(), shortFormatter.getParser()});
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", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
return new FormatDateTimeFormatter("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", builder.toFormatter().withZone(DateTimeZone.UTC), Locale.ROOT);
}


Expand Down
Expand Up @@ -83,6 +83,9 @@ public void testAutomaticDateParser() throws Exception {

FieldMapper fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field1");
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));
DateFieldMapper dateFieldMapper = (DateFieldMapper)fieldMapper;
assertEquals("yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis", dateFieldMapper.fieldType().dateTimeFormatter().format());
assertEquals(1265587200000L, dateFieldMapper.fieldType().dateTimeFormatter().parser().parseMillis("1265587200000"));
fieldMapper = defaultMapper.mappers().smartNameFieldMapper("date_field2");
assertThat(fieldMapper, instanceOf(DateFieldMapper.class));

Expand Down

0 comments on commit 71ec82d

Please sign in to comment.