aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>2017-10-20 10:37:54 +0200
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>2017-10-24 17:40:56 +0200
commit60b4ef64ff2668e808081457d4a80bac06679ba8 (patch)
tree2aa5eeb608121fcf76da33cab3c8ec47f07cfc5b
parent333feeb200ced5246182208bc72944cd4e11ce85 (diff)
downloadsonarqube-60b4ef64ff2668e808081457d4a80bac06679ba8.tar.gz
sonarqube-60b4ef64ff2668e808081457d4a80bac06679ba8.zip
SONAR-10008 Make issue search date histogram use server time zone
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java9
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java77
2 files changed, 40 insertions, 46 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
index 98028816725..d053608417c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java
@@ -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);
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
index 4272c3a0fcf..18acde0f685 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java
@@ -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