diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-20 15:08:26 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-06-20 15:08:39 +0200 |
commit | 87f1cd0960598af76b04faefe6a8c7fc5b54c874 (patch) | |
tree | c5cbcb2a2756883d742116d2d80c34dc3d95746e /sonar-server/src | |
parent | b32fa65e763b16e9dd00d31c8c0ce46a00286cc3 (diff) | |
download | sonarqube-87f1cd0960598af76b04faefe6a8c7fc5b54c874.tar.gz sonarqube-87f1cd0960598af76b04faefe6a8c7fc5b54c874.zip |
SONAR-5329 - Convert ES time to current timeZones
Diffstat (limited to 'sonar-server/src')
-rw-r--r-- | sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java | 5 | ||||
-rw-r--r-- | sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java | 9 |
2 files changed, 14 insertions, 0 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java b/sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java index 02d69bb96ce..bba38b2afe1 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java +++ b/sonar-server/src/main/java/org/sonar/server/search/IndexUtils.java @@ -25,6 +25,7 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.TimeZone; public class IndexUtils { @@ -38,8 +39,12 @@ public class IndexUtils { return null; } try { + + // ES times are in UTC DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + sdf.setTimeZone(TimeZone.getTimeZone("UTC")); return sdf.parse(s); + } catch (ParseException e) { throw new IllegalArgumentException("Cannot parse ES date: " + s, e); } diff --git a/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java b/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java index 9c3dc5e7deb..c20b68b8ddd 100644 --- a/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java +++ b/sonar-server/src/test/java/org/sonar/server/activity/ActivityBackendMediumTest.java @@ -131,4 +131,13 @@ public class ActivityBackendMediumTest { } assertThat(count).isEqualTo(max); } + + @Test + public void current_time_zone() { + service.write(dbSession, Activity.Type.QPROFILE, "now"); + dbSession.commit(); + + Activity activity = service.search(new ActivityQuery(), new QueryOptions()).getHits().get(0); + assertThat(System.currentTimeMillis() - activity.time().getTime()).isLessThan(1000L); + } } |