diff --git a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java index b8425baa017..1f67b90db2e 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -159,11 +159,11 @@ public class DateFormatters { .appendLiteral('T') .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) .optionalStart() - .appendFraction(NANO_OF_SECOND, 3, 9, true) + .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() .optionalStart() .appendLiteral(',') - .appendFraction(NANO_OF_SECOND, 3, 9, false) + .appendFraction(NANO_OF_SECOND, 1, 9, false) .optionalEnd() .optionalStart() .appendZoneOrOffsetId() diff --git a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java index b7da30a18f0..bfcb0b65b17 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -145,6 +145,15 @@ public class DateFormattersTests extends ESTestCase { assertThat(first, is(second)); } + public void testNanoOfSecondWidth() throws Exception { + ZonedDateTime first = DateFormatters.from( + DateFormatters.forPattern("strict_date_optional_time_nanos").parse("1970-01-01T00:00:00.1")); + assertThat(first.getNano(), is(100000000)); + ZonedDateTime second = DateFormatters.from( + DateFormatters.forPattern("strict_date_optional_time_nanos").parse("1970-01-01T00:00:00.000000001")); + assertThat(second.getNano(), is(1)); + } + public void testLocales() { assertThat(DateFormatters.forPattern("strict_date_optional_time").locale(), is(Locale.ROOT)); Locale locale = randomLocale(random());