@@ -86,6 +86,40 @@ public void testRangeQuery() throws Exception {
8686 );
8787 }
8888
89+ public void testDateRangeQueryDoesNotRoundupTemporals () {
90+ type = RangeType .DATE ;
91+ SearchExecutionContext context = createContext ();
92+ RangeFieldType ft = createDefaultFieldType ();
93+ ShapeRelation relation = randomFrom (ShapeRelation .values ());
94+
95+ // explicitly not using nextFrom here to provide a concrete, visual example.
96+ // see the behavioral difference compared to testRangeQueryIntersectsAdjacentDates
97+ ZonedDateTime from = ZonedDateTime .parse ("2025-05-01T14:10:00.000Z" );
98+ ZonedDateTime to = ZonedDateTime .parse ("2025-05-01T14:11:00.000Z" );
99+
100+ // usage of roundUp parsers is wrong if terms are Temporal objects, otherwise it would arbitrarily change the bounds
101+ // depending on the string representation
102+ assertEquals (
103+ getExpectedRangeQuery (relation , from , to , false , true ),
104+ ft .rangeQuery (from , to , false , true , relation , null , null , context )
105+ );
106+ }
107+
108+ public void testRangeQueryIntersectsAdjacentDates () {
109+ type = RangeType .DATE ;
110+ SearchExecutionContext context = createContext ();
111+ ShapeRelation relation = randomFrom (ShapeRelation .values ());
112+ RangeFieldType ft = createDefaultFieldType ();
113+
114+ // explicitly not using nextFrom here to provide a concrete, visual example of the roundUp behavior
115+ String from = "2025-05-01T14:10Z" ; // transformed to 2025-05-01T14:10:59.999999999Z by roundUp parser
116+ String to = "2025-05-01T14:11Z" ;
117+
118+ Query rangeQuery = ft .rangeQuery (from , to , false , false , relation , null , null , context );
119+ assertThat (rangeQuery , instanceOf (IndexOrDocValuesQuery .class ));
120+ assertThat (((IndexOrDocValuesQuery ) rangeQuery ).getIndexQuery (), instanceOf (MatchNoDocsQuery .class ));
121+ }
122+
89123 /**
90124 * test the queries are correct if from/to are adjacent and the range is exclusive of those values
91125 */
0 commit comments