Skip to content
Merged
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 @@ -58,10 +58,14 @@ public class DateFormatters {

private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
.optionalStart()
.appendLiteral("-")
.appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE)
.optionalStart()
.appendLiteral('-')
.appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE)
.optionalEnd()
.optionalEnd()
.toFormatter(IsoLocale.ROOT);

private static final DateTimeFormatter STRICT_HOUR_MINUTE_SECOND_FORMATTER = new DateTimeFormatterBuilder()
Expand Down Expand Up @@ -922,12 +926,14 @@ public class DateFormatters {

private static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder()
.appendValue(ChronoField.YEAR, 1, 5, SignStyle.NORMAL)
.optionalStart()
.appendLiteral('-')
.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NOT_NEGATIVE)
.optionalStart()
.appendLiteral('-')
.appendValue(DAY_OF_MONTH, 1, 2, SignStyle.NOT_NEGATIVE)
.optionalEnd()
.optionalEnd()
.toFormatter(IsoLocale.ROOT);

private static final DateTimeFormatter HOUR_MINUTE_FORMATTER = new DateTimeFormatterBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@ public class JavaJodaTimeDuellingTests extends ESTestCase {
protected boolean enableWarningsCheck() {
return false;
}
// date_optional part of a parser names "strict_date_optional_time" or "date_optional"time
// means that date part can be partially parsed.
public void testPartialParsing() {
assertSameDateAs("2001", "strict_date_optional_time_nanos", "strict_date_optional_time");
assertSameDateAs("2001-01", "strict_date_optional_time_nanos", "strict_date_optional_time");
assertSameDateAs("2001-01-01", "strict_date_optional_time_nanos", "strict_date_optional_time");

assertSameDate("2001", "strict_date_optional_time");
assertSameDate("2001-01", "strict_date_optional_time");
assertSameDate("2001-01-01", "strict_date_optional_time");

assertSameDate("2001", "date_optional_time");
assertSameDate("2001-01", "date_optional_time");
assertSameDate("2001-01-01", "date_optional_time");


assertSameDateAs("2001", "iso8601", "strict_date_optional_time");
assertSameDateAs("2001-01", "iso8601", "strict_date_optional_time");
assertSameDateAs("2001-01-01", "iso8601", "strict_date_optional_time");

assertSameDate("9999","date_optional_time||epoch_second");
}

public void testCompositeDateMathParsing(){
//in all these examples the second pattern will be used
Expand Down Expand Up @@ -890,4 +912,10 @@ private void assertDateMathEquals(String text, String pattern) {

assertEquals(gotMillisJoda, gotMillisJava);
}

private void assertSameDateAs(String input, String javaPattern, String jodaPattern) {
DateFormatter javaFormatter = DateFormatter.forPattern(javaPattern);
DateFormatter jodaFormatter = Joda.forPattern(jodaPattern);
assertSameDate(input, javaPattern, jodaFormatter, javaFormatter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,11 @@ public void testTimestamps() {
long datetime = parser.parse("1418248078", () -> 0).toEpochMilli();
assertDateEquals(datetime, "1418248078", "2014-12-10T21:47:58.000");

// a timestamp before 10000 is a year
assertDateMathEquals("9999", "1970-01-01T00:00:09.999Z");
// 10000 is also a year, breaking bwc, used to be a timestamp
assertDateMathEquals("10000", "1970-01-01T00:00:10.000Z");
// a timestamp before 100000 is a year
assertDateMathEquals("9999", "9999-01-01T00:00:00.000");
assertDateMathEquals("10000", "10000-01-01T00:00:00.000");
assertDateMathEquals("100000", "1970-01-01T00:01:40.000");

// but 10000 with T is still a date format
assertDateMathEquals("10000-01-01T", "10000-01-01T00:00:00.000");
}
Expand Down