diff --git a/server/src/main/java/org/elasticsearch/common/joda/Joda.java b/server/src/main/java/org/elasticsearch/common/joda/Joda.java index f9998116455..265cc2edce1 100644 --- a/server/src/main/java/org/elasticsearch/common/joda/Joda.java +++ b/server/src/main/java/org/elasticsearch/common/joda/Joda.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.Writer; import java.math.BigDecimal; import java.util.Locale; +import java.util.regex.Pattern; public class Joda { @@ -321,6 +322,8 @@ public class Joda { public static class EpochTimeParser implements DateTimeParser { + private static final Pattern scientificNotation = Pattern.compile("[Ee]"); + private final boolean hasMilliSecondPrecision; public EpochTimeParser(boolean hasMilliSecondPrecision) { @@ -348,6 +351,11 @@ public class Joda { int factor = hasMilliSecondPrecision ? 1 : 1000; try { long millis = new BigDecimal(text).longValue() * factor; + // check for deprecation, but after it has parsed correctly so the "e" isn't from something else + if (scientificNotation.matcher(text).find()) { + deprecationLogger.deprecatedAndMaybeLog("epoch-scientific-notation", "Use of scientific notation" + + "in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch."); + } DateTime dt = new DateTime(millis, DateTimeZone.UTC); bucket.saveField(DateTimeFieldType.year(), dt.getYear()); bucket.saveField(DateTimeFieldType.monthOfYear(), dt.getMonthOfYear()); 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 d32824df419..c85d303cf29 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java @@ -77,13 +77,11 @@ public class JavaJodaTimeDuellingTests extends ESTestCase { assertSameDate("1", "epoch_second"); assertSameDate("-1", "epoch_second"); assertSameDate("-1522332219", "epoch_second"); - assertSameDate("1.0e3", "epoch_second"); assertSameDate("1522332219321", "epoch_millis"); assertSameDate("0", "epoch_millis"); assertSameDate("1", "epoch_millis"); assertSameDate("-1", "epoch_millis"); assertSameDate("-1522332219321", "epoch_millis"); - assertSameDate("1.0e3", "epoch_millis"); assertSameDate("20181126", "basic_date"); assertSameDate("20181126T121212.123Z", "basic_date_time"); diff --git a/server/src/test/java/org/elasticsearch/common/joda/SimpleJodaTests.java b/server/src/test/java/org/elasticsearch/common/joda/SimpleJodaTests.java index 5f0bff1abf5..2da3a08629f 100644 --- a/server/src/test/java/org/elasticsearch/common/joda/SimpleJodaTests.java +++ b/server/src/test/java/org/elasticsearch/common/joda/SimpleJodaTests.java @@ -753,6 +753,15 @@ public class SimpleJodaTests extends ESTestCase { " next major version of Elasticsearch. Prefix your date format with '8' to use the new specifier."); } + public void testDeprecatedScientificNotation() { + assertValidDateFormatParsing("epoch_second", "1.234e5", "123400"); + assertWarnings("Use of scientific notation" + + "in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch."); + assertValidDateFormatParsing("epoch_millis", "1.234e5", "123400"); + assertWarnings("Use of scientific notation" + + "in epoch time formats is deprecated and will not be supported in the next major version of Elasticsearch."); + } + private void assertValidDateFormatParsing(String pattern, String dateToParse) { assertValidDateFormatParsing(pattern, dateToParse, dateToParse); }