diff --git a/ui/src/main/java/com/cloudbees/workflow/ui/view/WorkflowStageViewAction.java b/ui/src/main/java/com/cloudbees/workflow/ui/view/WorkflowStageViewAction.java index a726b68f..103882a4 100644 --- a/ui/src/main/java/com/cloudbees/workflow/ui/view/WorkflowStageViewAction.java +++ b/ui/src/main/java/com/cloudbees/workflow/ui/view/WorkflowStageViewAction.java @@ -12,6 +12,8 @@ import java.util.Collection; import java.util.Collections; +import java.util.Date; +import java.util.TimeZone; /** * {@link WorkflowJob} ui extension point {@link Action}. @@ -54,4 +56,18 @@ public Collection extends Action> createFor(WorkflowJob target) { return Collections.singleton(new WorkflowStageViewAction(target)); } } + + public String getTimeZone() { + return System.getProperty("user.timezone"); + } + + // Time zone offset right now in HH:MM format + public String getTimeZoneOffset() { + TimeZone tz = TimeZone.getTimeZone(getTimeZone()); + int offsetTotalMin = tz.getOffset(new Date().getTime()) / (1000*60) ; + int absOffsetMin = Math.abs(offsetTotalMin); + int offsetHours = absOffsetMin/60; + int offsetRealMin = absOffsetMin-(offsetHours*60); + return ((offsetTotalMin>0) ? '+' : '-') + offsetHours + ":" + offsetRealMin; + } } diff --git a/ui/src/main/js/model/runs-stage-grouped.js b/ui/src/main/js/model/runs-stage-grouped.js index 82eb62cb..4decc118 100644 --- a/ui/src/main/js/model/runs-stage-grouped.js +++ b/ui/src/main/js/model/runs-stage-grouped.js @@ -181,14 +181,14 @@ function addStageTotals(runGroup) { var run = runGroup.runs[i]; if (run.stages && (run.status === 'IN_PROGRESS' || run.status === 'PAUSED_PENDING_INPUT')) { - addCompletionEstimates(run, runGroup.avgDurationMillisNoPause, runGroup.runs.length); + addCompletionEstimates(run, runGroup.avgDurationMillisNoPause, endToEndRuns); for (var ii = 0; ii < run.stages.length; ii++) { var stage = run.stages[ii]; var stageData = getStageData(stage.name, runGroup); if (stage.percentCompleteEstimate === undefined) { if (stage.status === 'IN_PROGRESS' || stage.status === 'PAUSED_PENDING_INPUT') { - addCompletionEstimates(stage, stageData.avgDurationMillisNoPause, runGroup.runs.length); + addCompletionEstimates(stage, stageData.avgDurationMillisNoPause, endToEndRuns); } } } @@ -225,7 +225,7 @@ function addEndTimes(jobRunsData) { time.setEndTime(run); if (run.stages) { for (var ii = 0; ii < run.stages.length; ii++) { - time.setEndTime(run.stages[ii]); + time.setEndTime(run.stages[ii]); } } } @@ -238,8 +238,8 @@ function addEndTimes(jobRunsData) { * (i.e. a run, a runGroup or a stage). */ function addCompletionEstimates(timedObject, avgDurationMillis, averagedOver) { - if (averagedOver === 0) { - // If no runs have completed yet, then we can't make an estimate, so just mark it at 50%. + if (averagedOver === 0 || !(avgDurationMillis > 0)) { + // If no runs have completed yet, then we can't make an estimate, so just mark it undefined timedObject.percentCompleteEstimate = 50; } else { timedObject.percentCompleteEstimate = (timedObject.durationMillisNoPause / avgDurationMillis * 100); diff --git a/ui/src/main/js/view/templates/index.js b/ui/src/main/js/view/templates/index.js index 3f7c0b29..55c189ae 100644 --- a/ui/src/main/js/view/templates/index.js +++ b/ui/src/main/js/view/templates/index.js @@ -28,6 +28,10 @@ var jqProxy = require('../../jQuery'); var formatters = require('../../util/formatters'); var moment = require('moment'); +// Fix date formatting - set moment locale to UTC to match normal display +// Needs to get the Jenkins locale here, probably from jelly +// Moment._locale + /** * Templating support. */ @@ -87,6 +91,10 @@ registerHBSHelper('formatDate', function (date, toFormat) { return date; } + if (myTimeZoneOffset) { // Do time zone conversion using parseData *sigh.* + //moment.locale(myTimeZone); + } + var aliasFormat = formatAliases[toFormat]; if (aliasFormat) { return moment(date).format(aliasFormat); diff --git a/ui/src/main/js/view/templates/pipeline-staged.hbs b/ui/src/main/js/view/templates/pipeline-staged.hbs index 70995a84..f88d584a 100644 --- a/ui/src/main/js/view/templates/pipeline-staged.hbs +++ b/ui/src/main/js/view/templates/pipeline-staged.hbs @@ -21,16 +21,18 @@