@@ -78,11 +78,10 @@ registerHBSHelper('formatDate', function (date, toFormat) {
78
78
return date ;
79
79
}
80
80
81
- var theDate = new Date ( date ) ;
82
- var now = new Date ( ) ;
83
- var diff = now - theDate ; // Difference in milliseconds
84
- var oneDay = 24 * 60 * 60 * 1000 ; // milliseconds in one day
85
- var oneYear = 365 * oneDay ; // milliseconds in one year
81
+ var options = { month : 'short' , day : '2-digit' , hour : '2-digit' , minute : '2-digit' , hour12 : false } ;
82
+ if ( timeZone ) {
83
+ options . timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
84
+ }
86
85
87
86
let userLocale
88
87
if ( navigator . languages && navigator . languages . length ) {
@@ -91,45 +90,17 @@ registerHBSHelper('formatDate', function (date, toFormat) {
91
90
userLocale = navigator . language
92
91
}
93
92
94
- var options = { } ;
95
-
96
- // Determine which components to display based on the age of the job
97
- var showYear = diff >= oneYear ;
98
- var showDate = diff >= oneDay ;
99
- var showTime = true ; // Always show time if requested
100
-
101
- if ( toFormat === 'month' ) {
102
- if ( showDate ) {
103
- options . month = 'short' ;
104
- } else {
105
- return '' ; // Do not display month
106
- }
107
- } else if ( toFormat === 'dom' ) {
108
- if ( showDate ) {
109
- options . day = '2-digit' ;
110
- } else {
111
- return '' ; // Do not display day
112
- }
113
- } else if ( toFormat === 'year' ) {
114
- if ( showYear ) {
115
- options . year = 'numeric' ;
116
- } else {
117
- return '' ; // Do not display year
118
- }
119
- } else if ( toFormat === 'time' ) {
120
- if ( showTime ) {
121
- options . hour = '2-digit' ;
122
- options . minute = '2-digit' ;
123
- options . hour12 = false ;
124
- } else {
125
- return '' ; // This case won't occur since we always show time
126
- }
127
- } else {
128
- // Default case: return full date if needed
129
- return theDate . toLocaleString ( userLocale ) ;
93
+ var theDate = new Date ( date ) ;
94
+ if ( toFormat == 'month' ) {
95
+ return theDate . toLocaleDateString ( userLocale , { month : 'short' } ) ;
130
96
}
131
-
132
- return theDate . toLocaleString ( userLocale , options ) ;
97
+ if ( toFormat == 'dom' ) {
98
+ return theDate . toLocaleDateString ( userLocale , { day : '2-digit' } ) ;
99
+ }
100
+ if ( toFormat == 'time' ) {
101
+ return theDate . toLocaleTimeString ( userLocale , { hour : '2-digit' , minute : '2-digit' , hour12 : false } ) ;
102
+ }
103
+ return theDate . toLocaleDateString ( userLocale , options )
133
104
} ) ;
134
105
135
106
/**
@@ -177,7 +148,7 @@ function getTemplate(templateName) {
177
148
if ( ! templateInstance ) {
178
149
throw 'No template by the name "' + templateName + '". Check ui/src/main/js/view/templates/index.js and make sure the template is registered in the templateCache.' ;
179
150
}
180
-
151
+
181
152
// handles precompiled and compiled templates
182
153
return templateInstance . default || templateInstance ;
183
154
}
@@ -226,4 +197,4 @@ exports.apply = function (templateName, dataModel, divWrap) {
226
197
*/
227
198
exports . dateFormatting = function ( on ) {
228
199
dateFormattingOn = on ;
229
- }
200
+ }
0 commit comments