4141import java .time .Instant ;
4242import java .time .ZoneOffset ;
4343import java .time .ZonedDateTime ;
44+ import java .time .format .DateTimeFormatter ;
45+ import java .time .temporal .ChronoUnit ;
4446import java .util .Collections ;
4547import java .util .List ;
4648import java .util .Map ;
@@ -86,10 +88,21 @@ public void testRangeQuery() throws Exception {
8688 );
8789 }
8890
91+ private static String dateTimeString (long epochMillis , int increment , ChronoUnit precision ) {
92+ var dateTime = ZonedDateTime .ofInstant (Instant .ofEpochMilli (epochMillis ), ZoneOffset .UTC )
93+ .plus (increment , precision )
94+ .truncatedTo (precision );
95+ return switch (precision ) {
96+ case MILLIS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ).format (dateTime );
97+ case SECONDS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss'Z'" ).format (dateTime );
98+ case MINUTES -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm'Z'" ).format (dateTime );
99+ default -> dateTime .toString ();
100+ };
101+ }
102+
89103 /**
90104 * test the queries are correct if from/to are adjacent and the range is exclusive of those values
91105 */
92- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
93106 public void testRangeQueryIntersectsAdjacentValues () throws Exception {
94107 SearchExecutionContext context = createContext ();
95108 ShapeRelation relation = randomFrom (ShapeRelation .values ());
@@ -105,8 +118,9 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
105118 }
106119 case DATE -> {
107120 long fromValue = randomInt ();
108- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
109- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue + 1 ), ZoneOffset .UTC );
121+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
122+ from = dateTimeString (fromValue , 0 , precision );
123+ to = dateTimeString (fromValue , 1 , precision );
110124 }
111125 case INTEGER -> {
112126 int fromValue = randomInt ();
@@ -143,7 +157,6 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
143157 /**
144158 * check that we catch cases where the user specifies larger "from" than "to" value, not counting the include upper/lower settings
145159 */
146- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
147160 public void testFromLargerToErrors () throws Exception {
148161 SearchExecutionContext context = createContext ();
149162 RangeFieldType ft = createDefaultFieldType ();
@@ -159,8 +172,9 @@ public void testFromLargerToErrors() throws Exception {
159172 }
160173 case DATE : {
161174 long fromValue = randomInt ();
162- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
163- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue - 1 ), ZoneOffset .UTC );
175+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
176+ from = dateTimeString (fromValue , 0 , precision );
177+ to = dateTimeString (fromValue , -1 , precision );
164178 break ;
165179 }
166180 case INTEGER : {
0 commit comments