diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java index fe3fbcb1b95..819f1e239f1 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramAggregationBuilder.java @@ -469,7 +469,7 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil ZoneOffsetTransition prevOffsetTransition = tz.getRules().previousTransition(instant); final long prevTransition; - if (prevOffsetTransition != null) { + if (prevOffsetTransition != null) { prevTransition = prevOffsetTransition.getInstant().toEpochMilli(); } else { prevTransition = instant.toEpochMilli(); @@ -479,7 +479,7 @@ public class DateHistogramAggregationBuilder extends ValuesSourceAggregationBuil if (nextOffsetTransition != null) { nextTransition = nextOffsetTransition.getInstant().toEpochMilli(); } else { - nextTransition = instant.toEpochMilli(); + nextTransition = Long.MAX_VALUE; // fixed time-zone after prevTransition } // We need all not only values but also rounded values to be within diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramTests.java index 373df3e5f26..06ea9a37ba2 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/DateHistogramTests.java @@ -170,6 +170,18 @@ public class DateHistogramTests extends BaseAggregationTestCase always rewrite + tz = ZoneId.of("Australia/Brisbane"); + builder.timeZone(tz); + assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatCrosses)); + + // another timeZone without DST => always rewrite + tz = ZoneId.of("Asia/Katmandu"); + builder.timeZone(tz); + assertSame(ZoneOffset.ofHoursMinutes(5, 45), builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(ZoneOffset.ofHoursMinutes(5, 45), builder.rewriteTimeZone(shardContextThatCrosses)); + // daylight-saving-times => rewrite if doesn't cross tz = ZoneId.of("Europe/Paris"); builder.timeZone(tz);