Skip to content

Commit 2dfb024

Browse files
committed
Fixed rewrite of time zone without DST (#54398)
We try to rewrite time zones to fixed offsets in the date histogram aggregation if the data in the shard is within a single transition. However this optimization is not applied on time zones that don't apply daylight saving changes but had some random transitions in the past (e.g. Australia/Brisbane or Asia/Katmandu). This changes fixes the rewrite of such time zones to fixed offsets.
1 parent 5a6ef63 commit 2dfb024

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ ZoneId rewriteTimeZone(QueryShardContext context) throws IOException {
469469

470470
ZoneOffsetTransition prevOffsetTransition = tz.getRules().previousTransition(instant);
471471
final long prevTransition;
472-
if (prevOffsetTransition != null) {
472+
if (prevOffsetTransition != null) {
473473
prevTransition = prevOffsetTransition.getInstant().toEpochMilli();
474474
} else {
475475
prevTransition = instant.toEpochMilli();
@@ -479,7 +479,7 @@ ZoneId rewriteTimeZone(QueryShardContext context) throws IOException {
479479
if (nextOffsetTransition != null) {
480480
nextTransition = nextOffsetTransition.getInstant().toEpochMilli();
481481
} else {
482-
nextTransition = instant.toEpochMilli();
482+
nextTransition = Long.MAX_VALUE; // fixed time-zone after prevTransition
483483
}
484484

485485
// We need all not only values but also rounded values to be within

server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ public void testRewriteTimeZone() throws IOException {
170170
assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross));
171171
assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses));
172172

173+
// timeZone without DST => always rewrite
174+
tz = ZoneId.of("Australia/Brisbane");
175+
builder.timeZone(tz);
176+
assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatDoesntCross));
177+
assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatCrosses));
178+
179+
// another timeZone without DST => always rewrite
180+
tz = ZoneId.of("Asia/Katmandu");
181+
builder.timeZone(tz);
182+
assertSame(ZoneOffset.ofHoursMinutes(5, 45), builder.rewriteTimeZone(shardContextThatDoesntCross));
183+
assertSame(ZoneOffset.ofHoursMinutes(5, 45), builder.rewriteTimeZone(shardContextThatCrosses));
184+
173185
// daylight-saving-times => rewrite if doesn't cross
174186
tz = ZoneId.of("Europe/Paris");
175187
builder.timeZone(tz);

0 commit comments

Comments
 (0)