Skip to content

Commit

Permalink
fix date time display by format argument
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy committed Jan 17, 2023
1 parent ba26f8f commit 474b2ec
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/src/main/js/view/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ registerHBSHelper('formatDate', function (date, toFormat) {
return date;
}

var options = { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }
var options = { month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false };
if (timeZone) {
options.timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
}
Expand All @@ -90,7 +90,17 @@ registerHBSHelper('formatDate', function (date, toFormat) {
userLocale = navigator.language
}

return new Date().toLocaleDateString(userLocale, options)
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 474b2ec

Please sign in to comment.