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 ;
48+ import java .util .Locale ;
4649import java .util .Map ;
4750
4851import static org .hamcrest .Matchers .containsString ;
@@ -86,10 +89,21 @@ public void testRangeQuery() throws Exception {
8689 );
8790 }
8891
92+ private static String dateTimeString (long epochMillis , int increment , ChronoUnit precision ) {
93+ var dateTime = ZonedDateTime .ofInstant (Instant .ofEpochMilli (epochMillis ), ZoneOffset .UTC )
94+ .plus (increment , precision )
95+ .truncatedTo (precision );
96+ return switch (precision ) {
97+ case MILLIS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" , Locale .ROOT ).format (dateTime );
98+ case SECONDS -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss'Z'" , Locale .ROOT ).format (dateTime );
99+ case MINUTES -> DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm'Z'" , Locale .ROOT ).format (dateTime );
100+ default -> dateTime .toString ();
101+ };
102+ }
103+
89104 /**
90105 * test the queries are correct if from/to are adjacent and the range is exclusive of those values
91106 */
92- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
93107 public void testRangeQueryIntersectsAdjacentValues () throws Exception {
94108 SearchExecutionContext context = createContext ();
95109 ShapeRelation relation = randomFrom (ShapeRelation .values ());
@@ -105,8 +119,9 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
105119 }
106120 case DATE -> {
107121 long fromValue = randomInt ();
108- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
109- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue + 1 ), ZoneOffset .UTC );
122+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
123+ from = dateTimeString (fromValue , 0 , precision );
124+ to = dateTimeString (fromValue , 1 , precision );
110125 }
111126 case INTEGER -> {
112127 int fromValue = randomInt ();
@@ -143,7 +158,6 @@ public void testRangeQueryIntersectsAdjacentValues() throws Exception {
143158 /**
144159 * check that we catch cases where the user specifies larger "from" than "to" value, not counting the include upper/lower settings
145160 */
146- @ AwaitsFix (bugUrl = "https://github.com/elastic/elasticsearch/issues/86284" )
147161 public void testFromLargerToErrors () throws Exception {
148162 SearchExecutionContext context = createContext ();
149163 RangeFieldType ft = createDefaultFieldType ();
@@ -159,8 +173,9 @@ public void testFromLargerToErrors() throws Exception {
159173 }
160174 case DATE : {
161175 long fromValue = randomInt ();
162- from = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue ), ZoneOffset .UTC );
163- to = ZonedDateTime .ofInstant (Instant .ofEpochMilli (fromValue - 1 ), ZoneOffset .UTC );
176+ var precision = randomFrom (ChronoUnit .MILLIS , ChronoUnit .SECONDS , ChronoUnit .MINUTES );
177+ from = dateTimeString (fromValue , 0 , precision );
178+ to = dateTimeString (fromValue , -1 , precision );
164179 break ;
165180 }
166181 case INTEGER : {
0 commit comments