strict_date_optional_time_nanos with width 1 on nanos part (#63117) (#63387)

This formatter should allow parsing fraction of a second with minimum
width of 1. The same is allowed for strict_date_optional_time
closes #61357
This commit is contained in:
Przemyslaw Gomulka 2020-10-07 14:12:04 +02:00 committed by GitHub
parent 244f1a60f9
commit 5534a60fa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -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()

View File

@ -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());