diff options
author | James Moger <james.moger@gitblit.com> | 2012-02-25 08:18:22 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-02-25 08:18:22 -0500 |
commit | 40538c57dd574d831d044cda50a8999941dc0a24 (patch) | |
tree | 07ab800693cfef9c81dcc295146349fe5c869d6f | |
parent | 9d921f83d48fff71762bb4a579870107c788ecf9 (diff) | |
download | gitblit-40538c57dd574d831d044cda50a8999941dc0a24.tar.gz gitblit-40538c57dd574d831d044cda50a8999941dc0a24.zip |
Use proper timezone to generate all metrics
-rw-r--r-- | src/com/gitblit/GitBlit.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/utils/ActivityUtils.java | 9 | ||||
-rw-r--r-- | src/com/gitblit/utils/MetricUtils.java | 5 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/ActivityPage.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/wicket/pages/MetricsPage.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/wicket/panels/ActivityPanel.html | 2 | ||||
-rw-r--r-- | 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<Metric>(repositoryMetricsCache.getObject(model.name));
}
- List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null);
+ List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null, getTimezone());
repositoryMetricsCache.updateObject(model.name, model.lastChange, metrics);
return new ArrayList<Metric>(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<Activity> getRecentActivity(List<RepositoryModel> 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<String, Activity> activity = new HashMap<String, Activity>();
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<Metric> getDateMetrics(Repository repository, String objectId,
- boolean includeTotal, String dateFormat) {
+ boolean includeTotal, String dateFormat, TimeZone timezone) {
Metric total = new Metric("TOTAL");
final Map<String, Metric> metricMap = new HashMap<String, Metric>();
@@ -130,6 +132,7 @@ public class MetricUtils { // use specified date format
df = new SimpleDateFormat(dateFormat);
}
+ df.setTimeZone(timezone);
Iterable<RevCommit> 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<RepositoryModel> models = getRepositories(params);
- List<Activity> recentActivity = ActivityUtils.getRecentActivity(models, daysBack, objectId);
+ List<Activity> 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<Metric> metrics = MetricUtils.getDateMetrics(r, objectId, true, null);
+ List<Metric> 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<Metric> getDayOfWeekMetrics(Repository repository, String objectId) {
- List<Metric> list = MetricUtils.getDateMetrics(repository, objectId, false, "E");
+ List<Metric> 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 @@ </div>
<wicket:fragment wicket:id="commitFragment">
- <td class="date" style="width:50px; vertical-align: middle;" ><span wicket:id="time">[time of day]</span></td>
+ <td class="date" style="width:60px; vertical-align: middle;text-align: right;padding-right:10px;" ><span wicket:id="time">[time of day]</span></td>
<td style="width:10em;text-align:left;vertical-align: middle;">
<span wicket:id="repository" class="repositorySwatch">[repository link]</span>
</td>
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<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null);
+ List<Metric> metrics = MetricUtils.getDateMetrics(repository, null, true, null,
+ TimeZone.getDefault());
repository.close();
assertTrue("No date metrics found!", metrics.size() > 0);
}
|