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 06ea9a37ba2..7d583d11d8f 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 @@ -29,6 +29,7 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.time.DateFormatters; +import org.elasticsearch.common.time.DateUtils; import org.elasticsearch.index.query.QueryShardContext; import org.elasticsearch.search.aggregations.BaseAggregationTestCase; import org.elasticsearch.search.aggregations.BucketOrder; @@ -130,85 +131,97 @@ public class DateHistogramTests extends BaseAggregationTestCase no rewrite + assertNull(builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertNull(builder.rewriteTimeZone(shardContextThatCrosses)); - // no timeZone => no rewrite - assertNull(builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertNull(builder.rewriteTimeZone(shardContextThatCrosses)); + // fixed timeZone => no rewrite + ZoneId tz = ZoneOffset.ofHours(1); + builder.timeZone(tz); + assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); - // fixed timeZone => no rewrite - ZoneId tz = ZoneOffset.ofHours(1); - builder.timeZone(tz); - assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); + // timeZone without DST => always rewrite + tz = ZoneId.of("Australia/Brisbane"); + builder.timeZone(tz); + assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(ZoneOffset.ofHours(10), builder.rewriteTimeZone(shardContextThatCrosses)); - // timeZone without DST => 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)); - // 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); + assertEquals(ZoneOffset.ofHours(1), builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); - // daylight-saving-times => rewrite if doesn't cross - tz = ZoneId.of("Europe/Paris"); - builder.timeZone(tz); - assertEquals(ZoneOffset.ofHours(1), builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); + // Rounded values are no longer all within the same transitions => no rewrite + builder.calendarInterval(DateHistogramInterval.MONTH); + assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); - // Rounded values are no longer all within the same transitions => no rewrite - builder.calendarInterval(DateHistogramInterval.MONTH); - assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); + builder = new DateHistogramAggregationBuilder("my_date_histo"); + builder.field(fieldName); + builder.timeZone(tz); - builder = new DateHistogramAggregationBuilder("my_date_histo"); - builder.field(DATE_FIELD_NAME); - builder.timeZone(tz); + builder.fixedInterval(new DateHistogramInterval(1000L * 60 * 60 * 24 + "ms")); // ~ 1 day + assertEquals(ZoneOffset.ofHours(1), builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); - builder.fixedInterval(new DateHistogramInterval(1000L * 60 * 60 * 24 + "ms")); // ~ 1 day - assertEquals(ZoneOffset.ofHours(1), builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); - - // Because the interval is large, rounded values are not - // within the same transitions as the values => no rewrite - builder.fixedInterval(new DateHistogramInterval(1000L * 60 * 60 * 24 * 30 + "ms")); // ~ 1 month - assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); - assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); + // Because the interval is large, rounded values are not + // within the same transitions as the values => no rewrite + builder.fixedInterval(new DateHistogramInterval(1000L * 60 * 60 * 24 * 30 + "ms")); // ~ 1 month + assertSame(tz, builder.rewriteTimeZone(shardContextThatDoesntCross)); + assertSame(tz, builder.rewriteTimeZone(shardContextThatCrosses)); + } } } } } - }