James Moger
2012-02-25 40538c57dd574d831d044cda50a8999941dc0a24
Use proper timezone to generate all metrics
7 files modified
30 ■■■■■ changed files
src/com/gitblit/GitBlit.java 2 ●●● patch | view | raw | blame | history
src/com/gitblit/utils/ActivityUtils.java 9 ●●●●● patch | view | raw | blame | history
src/com/gitblit/utils/MetricUtils.java 5 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/ActivityPage.java 4 ●●● patch | view | raw | blame | history
src/com/gitblit/wicket/pages/MetricsPage.java 4 ●●●● patch | view | raw | blame | history
src/com/gitblit/wicket/panels/ActivityPanel.html 2 ●●● patch | view | raw | blame | history
tests/com/gitblit/tests/MetricUtilsTest.java 4 ●●● patch | view | raw | blame | history
src/com/gitblit/GitBlit.java
@@ -882,7 +882,7 @@
        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);
    }
src/com/gitblit/utils/ActivityUtils.java
@@ -27,6 +27,7 @@
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 @@
     * @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 @@
        // 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) {
src/com/gitblit/utils/MetricUtils.java
@@ -24,6 +24,7 @@
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 @@
     *            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 @@
                    // use specified date format
                    df = new SimpleDateFormat(dateFormat);
                }
                df.setTimeZone(timezone);
                Iterable<RevCommit> revlog = revWalk;
                for (RevCommit rev : revlog) {
src/com/gitblit/wicket/pages/ActivityPage.java
@@ -67,7 +67,8 @@
        // 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 @@
        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());
        }
src/com/gitblit/wicket/pages/MetricsPage.java
@@ -55,7 +55,7 @@
            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 @@
    }
    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();
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>
tests/com/gitblit/tests/MetricUtilsTest.java
@@ -19,6 +19,7 @@
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 @@
    }
    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);
    }