From 8abefd1e0cf73c63dfe98ac18939d932bc18118a Mon Sep 17 00:00:00 2001 From: John Wagster Date: Mon, 16 Dec 2024 20:43:00 -0600 Subject: [PATCH] moved around tests --- .../common/time/DateFormattersTests.java | 263 ---------------- .../common/time/EpochTimeTests.java | 291 ++++++++++++++++++ 2 files changed, 291 insertions(+), 263 deletions(-) create mode 100644 server/src/test/java/org/elasticsearch/common/time/EpochTimeTests.java diff --git a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java index d03f32d04b979..463d0d4514bac 100644 --- a/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java +++ b/server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java @@ -29,7 +29,6 @@ import java.time.temporal.TemporalAccessor; import java.util.List; import java.util.Locale; -import java.util.function.LongSupplier; import static org.elasticsearch.test.LambdaMatchers.transformedItemsMatch; import static org.hamcrest.Matchers.containsString; @@ -287,268 +286,6 @@ public void testEpochMillisParser() { assertThat(Instant.from(formatter.parse(formatter.format(instant))), is(instant)); } - // validate that negative epoch millis around rounded appropriately by the parser - LongSupplier supplier = () -> 0L; - { - Instant instant = formatter.toDateMathParser().parse("0", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("0", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("1", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.001999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-1", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("1", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.001Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-1", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("0.999999", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.999999", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999000001Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("0.999999", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.999999", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999000001Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("6250000430768", supplier, true, ZoneId.of("UTC")); - assertEquals("2168-01-20T23:13:50.768999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-6250000430768", supplier, true, ZoneId.of("UTC")); - assertEquals("1771-12-12T00:46:09.232999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("6250000430768", supplier, false, ZoneId.of("UTC")); - assertEquals("2168-01-20T23:13:50.768Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-6250000430768", supplier, false, ZoneId.of("UTC")); - assertEquals("1771-12-12T00:46:09.232Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("0.123450", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000123450Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.123450", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999876550Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("0.123450", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000123450Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.123450", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999876550Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("0.123456", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000123456Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.123456", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999876544Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("0.123456", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000123456Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.123456", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999876544Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("86400000", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-86400000", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("86400000", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-02T00:00:00Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-86400000", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T00:00:00Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("86400000.999999", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-86400000.999999", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-30T23:59:59.999000001Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("86400000.999999", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-86400000.999999", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-30T23:59:59.999000001Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("200.89", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.200890Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-200.89", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.799110Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("200.89", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.200890Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-200.89", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.799110Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("200.", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.200Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-200.", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.800Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("200.", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.200Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-200.", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.800Z", instant.toString()); - } - - { - Instant instant = formatter.toDateMathParser().parse("0.200", supplier, true, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000200Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.200", supplier, true, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999800Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("0.200", supplier, false, ZoneId.of("UTC")); - assertEquals("1970-01-01T00:00:00.000200Z", instant.toString()); - } - { - Instant instant = formatter.toDateMathParser().parse("-0.200", supplier, false, ZoneId.of("UTC")); - assertEquals("1969-12-31T23:59:59.999800Z", instant.toString()); - } - - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse(".200", supplier, true, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [.200] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("-.200", supplier, true, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [-.200] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse(".200", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [.200] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("-.200", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [-.200] with format [epoch_millis]")); - } - - // tilda was included in the parsers at one point for delineating negative and positive infinity rounding and we want to - // ensure it doesn't show up unexpectedly in the parser with its original "~" value - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~-0.200", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-0.200] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~0.200", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~0.200] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~-1", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-1] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~1", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~1] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~-1.", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-1.] with format [epoch_millis]")); - } - { - ElasticsearchParseException e = expectThrows( - ElasticsearchParseException.class, - () -> formatter.toDateMathParser().parse("~1.", supplier, false, ZoneId.of("UTC")) - ); - assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~1.] with format [epoch_millis]")); - } } /** diff --git a/server/src/test/java/org/elasticsearch/common/time/EpochTimeTests.java b/server/src/test/java/org/elasticsearch/common/time/EpochTimeTests.java new file mode 100644 index 0000000000000..59bf3958a3b26 --- /dev/null +++ b/server/src/test/java/org/elasticsearch/common/time/EpochTimeTests.java @@ -0,0 +1,291 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +package org.elasticsearch.common.time; + +import org.elasticsearch.ElasticsearchParseException; +import org.elasticsearch.test.ESTestCase; + +import java.time.Instant; +import java.time.ZoneId; +import java.util.function.LongSupplier; + +import static org.elasticsearch.common.time.EpochTime.MILLIS_FORMATTER; +import static org.hamcrest.Matchers.is; + +public class EpochTimeTests extends ESTestCase { + + public void testNegativeEpochMillis() { + DateFormatter formatter = MILLIS_FORMATTER; + + // validate that negative epoch millis around rounded appropriately by the parser + LongSupplier supplier = () -> 0L; + { + Instant instant = formatter.toDateMathParser().parse("0", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("0", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("1", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.001999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-1", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("1", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.001Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-1", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("0.999999", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.999999", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999000001Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("0.999999", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.999999", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999000001Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("6250000430768", supplier, true, ZoneId.of("UTC")); + assertEquals("2168-01-20T23:13:50.768999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-6250000430768", supplier, true, ZoneId.of("UTC")); + assertEquals("1771-12-12T00:46:09.232999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("6250000430768", supplier, false, ZoneId.of("UTC")); + assertEquals("2168-01-20T23:13:50.768Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-6250000430768", supplier, false, ZoneId.of("UTC")); + assertEquals("1771-12-12T00:46:09.232Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("0.123450", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000123450Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.123450", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999876550Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("0.123450", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000123450Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.123450", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999876550Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("0.123456", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000123456Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.123456", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999876544Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("0.123456", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000123456Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.123456", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999876544Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("86400000", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-86400000", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("86400000", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-02T00:00:00Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-86400000", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T00:00:00Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("86400000.999999", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-86400000.999999", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-30T23:59:59.999000001Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("86400000.999999", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-02T00:00:00.000999999Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-86400000.999999", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-30T23:59:59.999000001Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("200.89", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.200890Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-200.89", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.799110Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("200.89", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.200890Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-200.89", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.799110Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("200.", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.200Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-200.", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.800Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("200.", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.200Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-200.", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.800Z", instant.toString()); + } + + { + Instant instant = formatter.toDateMathParser().parse("0.200", supplier, true, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000200Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.200", supplier, true, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999800Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("0.200", supplier, false, ZoneId.of("UTC")); + assertEquals("1970-01-01T00:00:00.000200Z", instant.toString()); + } + { + Instant instant = formatter.toDateMathParser().parse("-0.200", supplier, false, ZoneId.of("UTC")); + assertEquals("1969-12-31T23:59:59.999800Z", instant.toString()); + } + + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse(".200", supplier, true, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [.200] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("-.200", supplier, true, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [-.200] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse(".200", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [.200] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("-.200", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [-.200] with format [epoch_millis]")); + } + + // tilda was included in the parsers at one point for delineating negative and positive infinity rounding and we want to + // ensure it doesn't show up unexpectedly in the parser with its original "~" value + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~-0.200", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-0.200] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~0.200", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~0.200] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~-1", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-1] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~1", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~1] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~-1.", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~-1.] with format [epoch_millis]")); + } + { + ElasticsearchParseException e = expectThrows( + ElasticsearchParseException.class, + () -> formatter.toDateMathParser().parse("~1.", supplier, false, ZoneId.of("UTC")) + ); + assertThat(e.getMessage().split(":")[0], is("failed to parse date field [~1.] with format [epoch_millis]")); + } + } + +}