From 40538c57dd574d831d044cda50a8999941dc0a24 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 25 Feb 2012 08:18:22 -0500 Subject: [PATCH] Use proper timezone to generate all metrics --- src/com/gitblit/GitBlit.java | 2 +- src/com/gitblit/utils/ActivityUtils.java | 9 ++++++--- src/com/gitblit/utils/MetricUtils.java | 5 ++++- src/com/gitblit/wicket/pages/ActivityPage.java | 4 +++- src/com/gitblit/wicket/pages/MetricsPage.java | 4 ++-- src/com/gitblit/wicket/panels/ActivityPanel.html | 2 +- tests/com/gitblit/tests/MetricUtilsTest.java | 4 +++- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index a57e6055..e6f07e08 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -882,7 +882,7 @@ public class GitBlit implements ServletContextListener { if (repositoryMetricsCache.hasCurrent(model.name, model.lastChange)) { return new ArrayList(repositoryMetricsCache.getObject(model.name)); } - List metrics = MetricUtils.getDateMetrics(repository, null, true, null); + List metrics = MetricUtils.getDateMetrics(repository, null, true, null, getTimezone()); repositoryMetricsCache.updateObject(model.name, model.lastChange, metrics); return new ArrayList(metrics); } diff --git a/src/com/gitblit/utils/ActivityUtils.java b/src/com/gitblit/utils/ActivityUtils.java index 61b6242a..d603a490 100644 --- a/src/com/gitblit/utils/ActivityUtils.java +++ b/src/com/gitblit/utils/ActivityUtils.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -60,10 +61,12 @@ public class ActivityUtils { * @param objectId * the branch to retrieve. If this value is null or empty all * branches are queried. + * @param timezone + * the timezone for aggregating commits * @return */ public static List getRecentActivity(List models, int daysBack, - String objectId) { + String objectId, TimeZone timezone) { // Activity panel shows last daysBack of activity across all // repositories. @@ -72,9 +75,9 @@ public class ActivityUtils { // Build a map of DailyActivity from the available repositories for the // specified threshold date. DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); - df.setTimeZone(GitBlit.getTimezone()); + df.setTimeZone(timezone); Calendar cal = Calendar.getInstance(); - cal.setTimeZone(GitBlit.getTimezone()); + cal.setTimeZone(timezone); Map activity = new HashMap(); for (RepositoryModel model : models) { diff --git a/src/com/gitblit/utils/MetricUtils.java b/src/com/gitblit/utils/MetricUtils.java index 2919b152..e9e1fa52 100644 --- a/src/com/gitblit/utils/MetricUtils.java +++ b/src/com/gitblit/utils/MetricUtils.java @@ -24,6 +24,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TimeZone; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.Repository; @@ -84,10 +85,11 @@ public class MetricUtils { * if null or empty, HEAD is assumed. * @param includeTotal * @param dateFormat + * @param timezone * @return list of metrics */ public static List getDateMetrics(Repository repository, String objectId, - boolean includeTotal, String dateFormat) { + boolean includeTotal, String dateFormat, TimeZone timezone) { Metric total = new Metric("TOTAL"); final Map metricMap = new HashMap(); @@ -130,6 +132,7 @@ public class MetricUtils { // use specified date format df = new SimpleDateFormat(dateFormat); } + df.setTimeZone(timezone); Iterable revlog = revWalk; for (RevCommit rev : revlog) { diff --git a/src/com/gitblit/wicket/pages/ActivityPage.java b/src/com/gitblit/wicket/pages/ActivityPage.java index e59e68ee..bceac8f4 100644 --- a/src/com/gitblit/wicket/pages/ActivityPage.java +++ b/src/com/gitblit/wicket/pages/ActivityPage.java @@ -67,7 +67,8 @@ public class ActivityPage extends RootPage { // determine repositories to view and retrieve the activity List models = getRepositories(params); - List recentActivity = ActivityUtils.getRecentActivity(models, daysBack, objectId); + List recentActivity = ActivityUtils.getRecentActivity(models, + daysBack, objectId, getTimeZone()); if (recentActivity.size() == 0) { // no activity, skip graphs and activity panel @@ -173,6 +174,7 @@ public class ActivityPage extends RootPage { GoogleChart chart = new GoogleLineChart("chartDaily", getString("gb.dailyActivity"), "day", getString("gb.commits")); SimpleDateFormat df = new SimpleDateFormat("MMM dd"); + df.setTimeZone(getTimeZone()); for (Activity metric : recentActivity) { chart.addValue(df.format(metric.startDate), metric.getCommitCount()); } diff --git a/src/com/gitblit/wicket/pages/MetricsPage.java b/src/com/gitblit/wicket/pages/MetricsPage.java index 8fce27a8..7a84f76e 100644 --- a/src/com/gitblit/wicket/pages/MetricsPage.java +++ b/src/com/gitblit/wicket/pages/MetricsPage.java @@ -55,7 +55,7 @@ public class MetricsPage extends RepositoryPage { add(new Label("branchTitle", objectId)); } Metric metricsTotal = null; - List metrics = MetricUtils.getDateMetrics(r, objectId, true, null); + List metrics = MetricUtils.getDateMetrics(r, objectId, true, null, getTimeZone()); metricsTotal = metrics.remove(0); if (metricsTotal == null) { add(new Label("branchStats", "")); @@ -135,7 +135,7 @@ public class MetricsPage extends RepositoryPage { } private List getDayOfWeekMetrics(Repository repository, String objectId) { - List list = MetricUtils.getDateMetrics(repository, objectId, false, "E"); + List list = MetricUtils.getDateMetrics(repository, objectId, false, "E", getTimeZone()); SimpleDateFormat sdf = new SimpleDateFormat("E"); Calendar cal = Calendar.getInstance(); diff --git a/src/com/gitblit/wicket/panels/ActivityPanel.html b/src/com/gitblit/wicket/panels/ActivityPanel.html index 3827dc47..4c0566cf 100644 --- a/src/com/gitblit/wicket/panels/ActivityPanel.html +++ b/src/com/gitblit/wicket/panels/ActivityPanel.html @@ -15,7 +15,7 @@ - [time of day] + [time of day] [repository link] diff --git a/tests/com/gitblit/tests/MetricUtilsTest.java b/tests/com/gitblit/tests/MetricUtilsTest.java index 43d02ebe..bb8261af 100644 --- a/tests/com/gitblit/tests/MetricUtilsTest.java +++ b/tests/com/gitblit/tests/MetricUtilsTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.List; +import java.util.TimeZone; import org.eclipse.jgit.lib.Repository; import org.junit.Test; @@ -35,7 +36,8 @@ public class MetricUtilsTest { } private void testMetrics(Repository repository) throws Exception { - List metrics = MetricUtils.getDateMetrics(repository, null, true, null); + List metrics = MetricUtils.getDateMetrics(repository, null, true, null, + TimeZone.getDefault()); repository.close(); assertTrue("No date metrics found!", metrics.size() > 0); } -- 2.39.5