Skip to content

Commit

Permalink
remove momentjs (#257)
Browse files Browse the repository at this point in the history
* remove momentjs

* fix date time display by format argument

Signed-off-by: Olivier Lamy <olamy@apache.org>

Signed-off-by: Olivier Lamy <olamy@apache.org>
Co-authored-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
car-roll and olamy authored Jan 17, 2023
1 parent 9e8c782 commit 64f5794
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
5 changes: 0 additions & 5 deletions ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.ui</groupId>
<artifactId>momentjs</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
Expand Down
35 changes: 18 additions & 17 deletions ui/src/main/js/view/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var mvc = require('../../mvc');
var handlebars = require('handlebars');
var jqProxy = require('../../jQuery');
var formatters = require('../../util/formatters');
var moment = require('moment-timezone');

/**
* Templating support.
Expand All @@ -50,14 +49,6 @@ var templateCache = {
// Initialise handlebars with helpers

var dateFormattingOn = true;
var formatAliases = {
short: 'HH:mm (MMM DD)',
month: 'MMM',
dom: 'DD',
time: 'HH:mm',
ISO_8601: 'YYYY-MM-DDTHH:mm:ss',
long: 'YYYY-MM-DDTHH:mm:ss'
};

function registerHBSHelper(name, helper) {
handlebars.registerHelper(name, helper);
Expand Down Expand Up @@ -87,19 +78,29 @@ registerHBSHelper('formatDate', function (date, toFormat) {
return date;
}

let momentDate
var options = { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false };
if (timeZone) {
momentDate = moment(date).tz(timeZone)
} else {
momentDate = moment(date)
options.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
}

var aliasFormat = formatAliases[toFormat];
if (aliasFormat) {
return momentDate.format(aliasFormat);
let userLocale
if (navigator.languages && navigator.languages.length) {
userLocale = navigator.languages[0]
} else {
return momentDate.format(toFormat);
userLocale = navigator.language
}

var theDate = new Date(date);
if (toFormat == 'month') {
return theDate.toLocaleDateString(userLocale, {month: 'short'});
}
if (toFormat == 'dom') {
return theDate.toLocaleDateString(userLocale, {day: '2-digit'});
}
if (toFormat == 'time') {
return theDate.toLocaleTimeString(userLocale, {hour: '2-digit',minute: '2-digit', hour12: false });
}
return theDate.toLocaleDateString(userLocale, options)
});

/**
Expand Down

0 comments on commit 64f5794

Please sign in to comment.