Core: Fix Java Time DateFormatter printers (#32592)

A bug in the test suite prevented to properly check that all date
formatters printed the date the same way like joda time does.

This fixes the test and thus also a fair share of formats, that
now use the strict parser for printing.
This commit is contained in:
Alexander Reelsen 2018-08-09 10:01:40 +02:00 committed by GitHub
parent 9b00f095b9
commit 823d40e19b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 991 additions and 579 deletions

View File

@ -70,4 +70,5 @@ public class CompoundDateTimeFormatter {
public String format(TemporalAccessor accessor) {
return printer.format(accessor);
}
}

View File

@ -453,10 +453,12 @@ public class JavaJodaTimeDuellingTests extends ESTestCase {
}
private void assertSamePrinterOutput(String format, ZonedDateTime javaDate, DateTime jodaDate) {
assertThat(jodaDate.getMillis(), is(javaDate.toEpochSecond() * 1000));
String javaTimeOut = DateFormatters.forPattern("dateOptionalTime").format(javaDate);
String jodaTimeOut = Joda.forPattern("dateOptionalTime").printer().print(jodaDate);
assertThat(javaTimeOut, is(jodaTimeOut));
assertThat(jodaDate.getMillis(), is(javaDate.toInstant().toEpochMilli()));
String javaTimeOut = DateFormatters.forPattern(format).format(javaDate);
String jodaTimeOut = Joda.forPattern(format).printer().print(jodaDate);
String message = String.format(Locale.ROOT, "expected string representation to be equal for format [%s]: joda [%s], java [%s]",
format, jodaTimeOut, javaTimeOut);
assertThat(message, javaTimeOut, is(jodaTimeOut));
}
private void assertSameDate(String input, String format) {