Skip to content

Allow more digits in the year part of dates #72190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ public class DateFormatters {
/////////////////////////////////////////

private static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR, 1, 5, SignStyle.NORMAL)
.appendValue(ChronoField.YEAR, 1, 9, SignStyle.NORMAL)
.optionalStart()
.appendLiteral('-')
.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NOT_NEGATIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,22 @@ public void testCustomLocales() {
assertSamePrinterOutput("E, d MMM yyyy HH:mm:ss Z", javaTimeNow, dateTimeNow, LocaleUtils.parse("de"));
}

public void testDateOptionalTimeYearsWithManyDigits() {
assertSameDateAs("2018-12-31T10:15:30", "yyyy-MM-dd'T'HH:mm:ss", "date_optional_time");
assertSameDateAs("12018-12-31T10:15:30", "yyyyy-MM-dd'T'HH:mm:ss", "date_optional_time");
assertSameDateAs("122018-12-31T10:15:30", "yyyyyy-MM-dd'T'HH:mm:ss", "date_optional_time");
assertSameDateAs("1232018-12-31T10:15:30", "yyyyyyy-MM-dd'T'HH:mm:ss", "date_optional_time");
assertSameDateAs("12342018-12-31T10:15:30", "yyyyyyyy-MM-dd'T'HH:mm:ss", "date_optional_time");
assertSameDateAs("123452018-12-31T10:15:30", "yyyyyyyyy-MM-dd'T'HH:mm:ss", "date_optional_time");

assertSameDate("2018-12-31T10:15:30", "date_optional_time");
assertSameDate("12018-12-31T10:15:30", "date_optional_time");
assertSameDate("122018-12-31T10:15:30", "date_optional_time");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests fail here without any code changes - output:

  2> java.lang.IllegalArgumentException: failed to parse date field [122018-12-31T10:15:30] with format [date_optional_time]
        at __randomizedtesting.SeedInfo.seed([3F1FADBA0ED58CED:34814355688917EA]:0)
        at org.elasticsearch.common.time.JavaDateFormatter.parse(JavaDateFormatter.java:170)
        at org.elasticsearch.common.joda.JavaJodaTimeDuellingTests.assertSameDate(JavaJodaTimeDuellingTests.java:887)
        at org.elasticsearch.common.joda.JavaJodaTimeDuellingTests.assertSameDate(JavaJodaTimeDuellingTests.java:875)
        at org.elasticsearch.common.joda.JavaJodaTimeDuellingTests.testDateOptionalTimeYearsWithManyDigits(JavaJodaTimeDuellingTests.java:228)

        Caused by:
        java.time.format.DateTimeParseException: Text '122018-12-31T10:15:30' could not be parsed, unparsed text found at index 5
            at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2055)
            at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1880)
            at org.elasticsearch.common.time.JavaDateFormatter.doParse(JavaDateFormatter.java:199)
            at org.elasticsearch.common.time.JavaDateFormatter.parse(JavaDateFormatter.java:168)
            ... 3 more

assertSameDate("1232018-12-31T10:15:30", "date_optional_time");
assertSameDate("12342018-12-31T10:15:30", "date_optional_time");
assertSameDate("123452018-12-31T10:15:30", "date_optional_time");
}

public void testDuellingFormatsValidParsing() {
assertSameDate("1522332219", "epoch_second");
assertSameDate("0", "epoch_second");
Expand Down