Skip to content

Commit c20dc02

Browse files
authored
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 07026ac commit c20dc02

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
@@ -467,7 +467,7 @@ ZoneId rewriteTimeZone(QueryShardContext context) throws IOException {
467467

468468
ZoneOffsetTransition prevOffsetTransition = tz.getRules().previousTransition(instant);
469469
final long prevTransition;
470-
if (prevOffsetTransition != null) {
470+
if (prevOffsetTransition != null) {
471471
prevTransition = prevOffsetTransition.getInstant().toEpochMilli();
472472
} else {
473473
prevTransition = instant.toEpochMilli();
@@ -477,7 +477,7 @@ ZoneId rewriteTimeZone(QueryShardContext context) throws IOException {
477477
if (nextOffsetTransition != null) {
478478
nextTransition = nextOffsetTransition.getInstant().toEpochMilli();
479479
} else {
480-
nextTransition = instant.toEpochMilli();
480+
nextTransition = Long.MAX_VALUE; // fixed time-zone after prevTransition
481481
}
482482

483483
// 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)