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 c8aa15d9b92..601bb7fff96 100644 --- a/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java +++ b/server/src/main/java/org/elasticsearch/common/time/DateFormatters.java @@ -112,6 +112,10 @@ public class DateFormatters { .optionalStart() .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() + .optionalStart() + .appendLiteral(',') + .appendFraction(NANO_OF_SECOND, 1, 9, false) + .optionalEnd() .optionalEnd() .optionalStart() .appendZoneOrOffsetId() @@ -139,6 +143,10 @@ public class DateFormatters { .appendFraction(NANO_OF_SECOND, 3, 9, true) .optionalEnd() .optionalStart() + .appendLiteral(',') + .appendFraction(NANO_OF_SECOND, 3, 9, false) + .optionalEnd() + .optionalStart() .appendZoneOrOffsetId() .optionalEnd() .optionalStart() @@ -940,6 +948,10 @@ public class DateFormatters { .optionalStart() .appendFraction(NANO_OF_SECOND, 1, 9, true) .optionalEnd() + .optionalStart() + .appendLiteral(',') + .appendFraction(NANO_OF_SECOND, 1, 9, false) + .optionalEnd() .optionalStart().appendZoneOrOffsetId().optionalEnd() .optionalStart().appendOffset("+HHmm", "Z").optionalEnd() .optionalEnd() diff --git a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java index 16ff794979e..9e2a6de5b64 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -40,6 +40,26 @@ import static org.hamcrest.Matchers.is; public class JavaJodaTimeDuellingTests extends ESTestCase { + //these parsers should allow both ',' and '.' as a decimal point + public void testDecimalPointParsing(){ + assertSameDate("2001-01-01T00:00:00.123Z", "strict_date_optional_time"); + assertSameDate("2001-01-01T00:00:00,123Z", "strict_date_optional_time"); + + assertSameDate("2001-01-01T00:00:00.123Z", "date_optional_time"); + assertSameDate("2001-01-01T00:00:00,123Z", "date_optional_time"); + + // only java.time has nanos parsing, but the results for 3digits should be the same + DateFormatter jodaFormatter = Joda.forPattern("strict_date_optional_time"); + DateFormatter javaFormatter = DateFormatter.forPattern("strict_date_optional_time_nanos"); + assertSameDate("2001-01-01T00:00:00.123Z", "strict_date_optional_time_nanos", jodaFormatter, javaFormatter); + assertSameDate("2001-01-01T00:00:00,123Z", "strict_date_optional_time_nanos", jodaFormatter, javaFormatter); + + assertParseException("2001-01-01T00:00:00.123,456Z", "strict_date_optional_time"); + assertParseException("2001-01-01T00:00:00.123,456Z", "date_optional_time"); + //This should fail, but java is ok with this because the field has the same value +// assertJavaTimeParseException("2001-01-01T00:00:00.123,123Z", "strict_date_optional_time_nanos"); + } + public void testIncompatiblePatterns() { // in joda 'y' means year, this is changed to 'u' in java.time. difference is in before era yeaers assertSameMillis("-0001-01-01", "yyyy-MM-dd", "8uuuu-MM-dd");