Skip to content

Commit

Permalink
Fixes inconsistent timezone display (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdougal authored Aug 25, 2022
1 parent 3b56814 commit 3992948
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@jenkins-cd/js-modules": "^0.0.10",
"jenkins-js-extp": "0.0.2",
"jquery": "^3.5.1",
"moment": "~2.29.4",
"moment-timezone": "0.5.34",
"window-handle": "^1.0.0"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ public Collection<? extends Action> createFor(WorkflowJob target) {
return Collections.singleton(new WorkflowStageViewAction(target));
}
}

public String getTimeZone() {
return System.getProperty("user.timezone");
}
}
13 changes: 10 additions & 3 deletions ui/src/main/js/view/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var mvc = require('../../mvc');
var handlebars = require('handlebars');
var jqProxy = require('../../jQuery');
var formatters = require('../../util/formatters');
var moment = require('moment');
var moment = require('moment-timezone');

/**
* Templating support.
Expand Down Expand Up @@ -87,11 +87,18 @@ registerHBSHelper('formatDate', function (date, toFormat) {
return date;
}

let momentDate
if (timeZone) {
momentDate = moment(date).tz(timeZone)
} else {
momentDate = moment(date)
}

var aliasFormat = formatAliases[toFormat];
if (aliasFormat) {
return moment(date).format(aliasFormat);
return momentDate.format(aliasFormat);
} else {
return moment(date).format(toFormat);
return momentDate.format(toFormat);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Optional fragment caption, passed through to the controller.
</st:attribute>
</st:documentation>
<script>var timeZone = '${it.timeZone}';</script>
<div class="cbwf-stage-view">
<div cbwf-controller="${name}" objectUrl="${rootURL}/${it.target.url}" fragCaption="${fragCaption}" />
<st:adjunct includes="org.jenkinsci.pipeline.stageview_adjunct"/>
Expand Down

0 comments on commit 3992948

Please sign in to comment.