]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10008 Make issue search date histogram use server time zone
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Fri, 20 Oct 2017 08:37:54 +0000 (10:37 +0200)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Tue, 24 Oct 2017 15:40:56 +0000 (17:40 +0200)
server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java

index 98028816725a9f27d68ddd21b1a775ae8baf54d1..d053608417c25ce7e6baf1783b527fa035607cd8 100644 (file)
@@ -30,7 +30,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Optional;
-import java.util.TimeZone;
 import java.util.regex.Pattern;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
@@ -537,18 +536,14 @@ public class IssueIndex {
       bucketSize = DateHistogramInterval.MONTH;
     }
 
-    // from GMT to server TZ
-    int offsetInSeconds = -system.getDefaultTimeZone().getRawOffset() / 1_000;
-
     AggregationBuilder dateHistogram = AggregationBuilders.dateHistogram(PARAM_CREATED_AT)
       .field(IssueIndexDefinition.FIELD_ISSUE_FUNC_CREATED_AT)
       .dateHistogramInterval(bucketSize)
       .minDocCount(0L)
       .format(DateUtils.DATETIME_FORMAT)
-      .timeZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT")))
-      .offset(offsetInSeconds + "s")
+      .timeZone(DateTimeZone.forOffsetMillis(system.getDefaultTimeZone().getRawOffset()))
       // ES dateHistogram bounds are inclusive while createdBefore parameter is exclusive
-      .extendedBounds(new ExtendedBounds(startTime, endTime - (offsetInSeconds * 1_000L) - 1L));
+      .extendedBounds(new ExtendedBounds(startTime, endTime - 1L));
     addEffortAggregationIfNeeded(query, dateHistogram);
     return Optional.of(dateHistogram);
   }
index 4272c3a0fcfa969f4d858da1beedd4b566e61927..18acde0f685074c91cd45b0498892b48e42df291 100644 (file)
@@ -787,14 +787,14 @@ public class IssueIndexTest {
     SearchResponse result = underTest.search(query, options);
     Map<String, Long> buckets = new Facets(result).get("createdAt");
     assertThat(buckets).containsOnly(
-      entry("2014-08-31T01:00:00+0000", 0L),
-      entry("2014-09-01T01:00:00+0000", 2L),
-      entry("2014-09-02T01:00:00+0000", 1L),
-      entry("2014-09-03T01:00:00+0000", 0L),
-      entry("2014-09-04T01:00:00+0000", 0L),
-      entry("2014-09-05T01:00:00+0000", 1L),
-      entry("2014-09-06T01:00:00+0000", 0L),
-      entry("2014-09-07T01:00:00+0000", 0L));
+      entry("2014-08-31T00:00:00-0100", 0L),
+      entry("2014-09-01T00:00:00-0100", 2L),
+      entry("2014-09-02T00:00:00-0100", 1L),
+      entry("2014-09-03T00:00:00-0100", 0L),
+      entry("2014-09-04T00:00:00-0100", 0L),
+      entry("2014-09-05T00:00:00-0100", 1L),
+      entry("2014-09-06T00:00:00-0100", 0L),
+      entry("2014-09-07T00:00:00-0100", 0L));
   }
 
   @Test
@@ -807,10 +807,10 @@ public class IssueIndexTest {
       options);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2014-08-25T01:00:00+0000", 0L),
-      entry("2014-09-01T01:00:00+0000", 4L),
-      entry("2014-09-08T01:00:00+0000", 0L),
-      entry("2014-09-15T01:00:00+0000", 1L));
+      entry("2014-08-25T00:00:00-0100", 0L),
+      entry("2014-09-01T00:00:00-0100", 4L),
+      entry("2014-09-08T00:00:00-0100", 0L),
+      entry("2014-09-15T00:00:00-0100", 1L));
   }
 
   @Test
@@ -823,12 +823,12 @@ public class IssueIndexTest {
       options);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2014-08-01T01:00:00+0000", 0L),
-      entry("2014-09-01T01:00:00+0000", 5L),
-      entry("2014-10-01T01:00:00+0000", 0L),
-      entry("2014-11-01T01:00:00+0000", 0L),
-      entry("2014-12-01T01:00:00+0000", 0L),
-      entry("2015-01-01T01:00:00+0000", 1L));
+      entry("2014-08-01T00:00:00-0100", 0L),
+      entry("2014-09-01T00:00:00-0100", 5L),
+      entry("2014-10-01T00:00:00-0100", 0L),
+      entry("2014-11-01T00:00:00-0100", 0L),
+      entry("2014-12-01T00:00:00-0100", 0L),
+      entry("2015-01-01T00:00:00-0100", 1L));
   }
 
   @Test
@@ -841,13 +841,12 @@ public class IssueIndexTest {
       options);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2010-01-01T01:00:00+0000", 0L),
-      entry("2011-01-01T01:00:00+0000", 1L),
-      entry("2012-01-01T01:00:00+0000", 0L),
-      entry("2013-01-01T01:00:00+0000", 0L),
-      entry("2014-01-01T01:00:00+0000", 5L),
-      entry("2015-01-01T01:00:00+0000", 1L));
-
+      entry("2010-01-01T00:00:00-0100", 0L),
+      entry("2011-01-01T00:00:00-0100", 1L),
+      entry("2012-01-01T00:00:00-0100", 0L),
+      entry("2013-01-01T00:00:00-0100", 0L),
+      entry("2014-01-01T00:00:00-0100", 5L),
+      entry("2015-01-01T00:00:00-0100", 1L));
   }
 
   @Test
@@ -860,7 +859,7 @@ public class IssueIndexTest {
       options);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2014-09-01T01:00:00+0000", 2L));
+      entry("2014-09-01T00:00:00-0100", 2L));
   }
 
   @Test
@@ -873,14 +872,14 @@ public class IssueIndexTest {
       .build(), options);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2008-01-01T01:00:00+0000", 0L),
-      entry("2009-01-01T01:00:00+0000", 0L),
-      entry("2010-01-01T01:00:00+0000", 0L),
-      entry("2011-01-01T01:00:00+0000", 1L),
-      entry("2012-01-01T01:00:00+0000", 0L),
-      entry("2013-01-01T01:00:00+0000", 0L),
-      entry("2014-01-01T01:00:00+0000", 5L),
-      entry("2015-01-01T01:00:00+0000", 1L));
+      entry("2008-01-01T00:00:00-0100", 0L),
+      entry("2009-01-01T00:00:00-0100", 0L),
+      entry("2010-01-01T00:00:00-0100", 0L),
+      entry("2011-01-01T00:00:00-0100", 1L),
+      entry("2012-01-01T00:00:00-0100", 0L),
+      entry("2013-01-01T00:00:00-0100", 0L),
+      entry("2014-01-01T00:00:00-0100", 5L),
+      entry("2015-01-01T00:00:00-0100", 1L));
   }
 
   @Test
@@ -892,11 +891,11 @@ public class IssueIndexTest {
       searchOptions);
     Map<String, Long> createdAt = new Facets(result).get("createdAt");
     assertThat(createdAt).containsOnly(
-      entry("2011-01-01T01:00:00+0000", 1L),
-      entry("2012-01-01T01:00:00+0000", 0L),
-      entry("2013-01-01T01:00:00+0000", 0L),
-      entry("2014-01-01T01:00:00+0000", 5L),
-      entry("2015-01-01T01:00:00+0000", 1L));
+      entry("2011-01-01T00:00:00-0100", 1L),
+      entry("2012-01-01T00:00:00-0100", 0L),
+      entry("2013-01-01T00:00:00-0100", 0L),
+      entry("2014-01-01T00:00:00-0100", 5L),
+      entry("2015-01-01T00:00:00-0100", 1L));
   }
 
   @Test