Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove momentjs #257

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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