@servicetitan/datetime-utils 31.2.0 → 31.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +142 -285
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/__tests__/index.test.js +0 -95
- package/dist/__tests__/index.test.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
2
15
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
16
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
18
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
|
|
19
|
+
}
|
|
20
|
+
function _ts_metadata(k, v) {
|
|
8
21
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return function
|
|
12
|
-
|
|
22
|
+
}
|
|
23
|
+
function _ts_param(paramIndex, decorator) {
|
|
24
|
+
return function(target, key) {
|
|
25
|
+
decorator(target, key, paramIndex);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
13
28
|
import { injectable, inject } from '@servicetitan/react-ioc';
|
|
14
|
-
import { CULTURE_TOKEN } from '@servicetitan/culture';
|
|
29
|
+
import { CULTURE_TOKEN, Culture } from '@servicetitan/culture';
|
|
15
30
|
function ordinalString(num) {
|
|
16
|
-
switch
|
|
31
|
+
switch(num % 100){
|
|
17
32
|
case 11:
|
|
18
33
|
case 12:
|
|
19
34
|
case 13:
|
|
20
35
|
return num.toString() + 'th';
|
|
21
36
|
default:
|
|
22
|
-
switch
|
|
37
|
+
switch(num % 10){
|
|
23
38
|
case 1:
|
|
24
39
|
return num.toString() + 'st';
|
|
25
40
|
case 2:
|
|
@@ -31,347 +46,189 @@ function ordinalString(num) {
|
|
|
31
46
|
}
|
|
32
47
|
}
|
|
33
48
|
}
|
|
34
|
-
|
|
35
|
-
constructor(culture)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(this, "dateFullFormatter", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
configurable: true,
|
|
51
|
-
writable: true,
|
|
52
|
-
value: void 0
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(this, "shortTimeFormatter", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
configurable: true,
|
|
57
|
-
writable: true,
|
|
58
|
-
value: void 0
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(this, "fullTimeFormatter", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
configurable: true,
|
|
63
|
-
writable: true,
|
|
64
|
-
value: void 0
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(this, "shortWeekdayFormatter", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
configurable: true,
|
|
69
|
-
writable: true,
|
|
70
|
-
value: void 0
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(this, "shortMonthFormatter", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
configurable: true,
|
|
75
|
-
writable: true,
|
|
76
|
-
value: void 0
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(this, "shortMonthDateFormatter", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
configurable: true,
|
|
81
|
-
writable: true,
|
|
82
|
-
value: void 0
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(this, "fullMonthFormatter", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
configurable: true,
|
|
87
|
-
writable: true,
|
|
88
|
-
value: void 0
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(this, "fullMonthDateFormatter", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(this, "short24HourTimeFormatter", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: void 0
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(this, "medium24HourTimeFormatter", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
configurable: true,
|
|
105
|
-
writable: true,
|
|
106
|
-
value: void 0
|
|
107
|
-
});
|
|
49
|
+
export class DateTimeUtils {
|
|
50
|
+
constructor(culture){
|
|
51
|
+
_define_property(this, "locale", void 0);
|
|
52
|
+
_define_property(this, "dateFormatter", void 0);
|
|
53
|
+
_define_property(this, "dateFullFormatter", void 0);
|
|
54
|
+
_define_property(this, "shortTimeFormatter", void 0);
|
|
55
|
+
_define_property(this, "fullTimeFormatter", void 0);
|
|
56
|
+
_define_property(this, "shortWeekdayFormatter", void 0);
|
|
57
|
+
_define_property(this, "shortMonthFormatter", void 0);
|
|
58
|
+
_define_property(this, "shortMonthDateFormatter", void 0);
|
|
59
|
+
_define_property(this, "fullMonthFormatter", void 0);
|
|
60
|
+
_define_property(this, "fullMonthDateFormatter", void 0);
|
|
61
|
+
_define_property(this, "short24HourTimeFormatter", void 0);
|
|
62
|
+
_define_property(this, "medium24HourTimeFormatter", void 0);
|
|
108
63
|
/**
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
enumerable: true,
|
|
120
|
-
configurable: true,
|
|
121
|
-
writable: true,
|
|
122
|
-
value: (date, options) => {
|
|
123
|
-
return date.toLocaleDateString(this.locale, options);
|
|
124
|
-
}
|
|
64
|
+
* General date formatting.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* format(date, {
|
|
68
|
+
* weekday: 'long',
|
|
69
|
+
* month: 'long',
|
|
70
|
+
* day: 'numeric'
|
|
71
|
+
* }); // Tuesday, December 3
|
|
72
|
+
*/ _define_property(this, "format", (date, options)=>{
|
|
73
|
+
return date.toLocaleDateString(this.locale, options);
|
|
125
74
|
});
|
|
126
75
|
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
enumerable: true,
|
|
132
|
-
configurable: true,
|
|
133
|
-
writable: true,
|
|
134
|
-
value: (date) => {
|
|
135
|
-
return this.dateFormatter.format(date);
|
|
136
|
-
}
|
|
76
|
+
* Equals moment format: 'M/D/YY'
|
|
77
|
+
* Returns: 1/2/20
|
|
78
|
+
*/ _define_property(this, "formatDate", (date)=>{
|
|
79
|
+
return this.dateFormatter.format(date);
|
|
137
80
|
});
|
|
138
81
|
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
enumerable: true,
|
|
144
|
-
configurable: true,
|
|
145
|
-
writable: true,
|
|
146
|
-
value: (date) => {
|
|
147
|
-
return this.shortMonthDateFormatter.format(date);
|
|
148
|
-
}
|
|
82
|
+
* Equals moment format: 'MMM DY'
|
|
83
|
+
* Returns: Dec 2
|
|
84
|
+
*/ _define_property(this, "formatDateShort", (date)=>{
|
|
85
|
+
return this.shortMonthDateFormatter.format(date);
|
|
149
86
|
});
|
|
150
87
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
enumerable: true,
|
|
156
|
-
configurable: true,
|
|
157
|
-
writable: true,
|
|
158
|
-
value: (date) => {
|
|
159
|
-
return this.dateFullFormatter.format(date);
|
|
160
|
-
}
|
|
88
|
+
* Equals moment format: 'MM/DD/YYYY', 'MM/DD/Y', with US locale - 'L'
|
|
89
|
+
* Returns: 01/02/2020
|
|
90
|
+
*/ _define_property(this, "formatDateFull", (date)=>{
|
|
91
|
+
return this.dateFullFormatter.format(date);
|
|
161
92
|
});
|
|
162
93
|
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
enumerable: true,
|
|
168
|
-
configurable: true,
|
|
169
|
-
writable: true,
|
|
170
|
-
value: (date) => {
|
|
171
|
-
return `${this.formatDateFull(date)} ${this.formatFullTime(date)}`;
|
|
172
|
-
}
|
|
94
|
+
* Equals moment format: 'MM/DD/YYYY hh:mm A', with US locale - 'L LT'
|
|
95
|
+
* Returns: 01/02/2020 03:47 AM
|
|
96
|
+
*/ _define_property(this, "formatDateTimeFull", (date)=>{
|
|
97
|
+
return `${this.formatDateFull(date)} ${this.formatFullTime(date)}`;
|
|
173
98
|
});
|
|
174
99
|
/**
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
enumerable: true,
|
|
180
|
-
configurable: true,
|
|
181
|
-
writable: true,
|
|
182
|
-
value: (date) => {
|
|
183
|
-
return `${this.formatDate(date)} ${this.formatShortTime(date)}`;
|
|
184
|
-
}
|
|
100
|
+
* Equals moment format: 'M/D/YY hh:mm A', with US locale - 'L LT'
|
|
101
|
+
* Returns: 1/2/20 3:47 AM
|
|
102
|
+
*/ _define_property(this, "formatDateTimeShort", (date)=>{
|
|
103
|
+
return `${this.formatDate(date)} ${this.formatShortTime(date)}`;
|
|
185
104
|
});
|
|
186
105
|
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
enumerable: true,
|
|
192
|
-
configurable: true,
|
|
193
|
-
writable: true,
|
|
194
|
-
value: (date) => {
|
|
195
|
-
return `${this.formatDateShort(date)} ${this.formatShortTime(date)}`;
|
|
196
|
-
}
|
|
106
|
+
* Equals moment format: 'MMM D, hh:mm A', with US locale - 'L LT'
|
|
107
|
+
* Returns: Dec 2 3:47 AM
|
|
108
|
+
*/ _define_property(this, "formatDateTimeShortest", (date)=>{
|
|
109
|
+
return `${this.formatDateShort(date)} ${this.formatShortTime(date)}`;
|
|
197
110
|
});
|
|
198
111
|
/**
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
enumerable: true,
|
|
204
|
-
configurable: true,
|
|
205
|
-
writable: true,
|
|
206
|
-
value: (date) => {
|
|
207
|
-
return this.shortTimeFormatter.format(date);
|
|
208
|
-
}
|
|
112
|
+
* Equals moment format: 'h:mm A', with US locale - 'LT'
|
|
113
|
+
* Returns: 3:00 PM
|
|
114
|
+
*/ _define_property(this, "formatShortTime", (date)=>{
|
|
115
|
+
return this.shortTimeFormatter.format(date);
|
|
209
116
|
});
|
|
210
117
|
/**
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
enumerable: true,
|
|
216
|
-
configurable: true,
|
|
217
|
-
writable: true,
|
|
218
|
-
value: (date) => {
|
|
219
|
-
return this.fullTimeFormatter.format(date);
|
|
220
|
-
}
|
|
118
|
+
* Equals moment format: 'hh:mm A'
|
|
119
|
+
* Returns: 03:00 PM
|
|
120
|
+
*/ _define_property(this, "formatFullTime", (date)=>{
|
|
121
|
+
return this.fullTimeFormatter.format(date);
|
|
221
122
|
});
|
|
222
123
|
/**
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
enumerable: true,
|
|
228
|
-
configurable: true,
|
|
229
|
-
writable: true,
|
|
230
|
-
value: (date) => {
|
|
231
|
-
return this.short24HourTimeFormatter.format(date);
|
|
232
|
-
}
|
|
124
|
+
* Equals moment format: 'hh:mm'
|
|
125
|
+
* Returns: 15:00
|
|
126
|
+
*/ _define_property(this, "formatShort24HourTime", (date)=>{
|
|
127
|
+
return this.short24HourTimeFormatter.format(date);
|
|
233
128
|
});
|
|
234
129
|
/**
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
enumerable: true,
|
|
240
|
-
configurable: true,
|
|
241
|
-
writable: true,
|
|
242
|
-
value: (date) => {
|
|
243
|
-
return this.medium24HourTimeFormatter.format(date);
|
|
244
|
-
}
|
|
130
|
+
* Equals moment format: 'hh:mm:ss'
|
|
131
|
+
* Returns: 15:00:00
|
|
132
|
+
*/ _define_property(this, "formatMedium24HourTime", (date)=>{
|
|
133
|
+
return this.medium24HourTimeFormatter.format(date);
|
|
245
134
|
});
|
|
246
135
|
/**
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
enumerable: true,
|
|
252
|
-
configurable: true,
|
|
253
|
-
writable: true,
|
|
254
|
-
value: (date) => {
|
|
255
|
-
return this.shortWeekdayFormatter.format(date);
|
|
256
|
-
}
|
|
136
|
+
* Equals moment format: 'ddd'
|
|
137
|
+
* Returns: Thu
|
|
138
|
+
*/ _define_property(this, "formatShortWeekday", (date)=>{
|
|
139
|
+
return this.shortWeekdayFormatter.format(date);
|
|
257
140
|
});
|
|
258
141
|
/**
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
enumerable: true,
|
|
264
|
-
configurable: true,
|
|
265
|
-
writable: true,
|
|
266
|
-
value: (date) => {
|
|
267
|
-
return this.shortMonthFormatter.format(date);
|
|
268
|
-
}
|
|
142
|
+
* Equals moment format: 'MMM'
|
|
143
|
+
* Returns: Jan
|
|
144
|
+
*/ _define_property(this, "formatShortMonth", (date)=>{
|
|
145
|
+
return this.shortMonthFormatter.format(date);
|
|
269
146
|
});
|
|
270
147
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
enumerable: true,
|
|
276
|
-
configurable: true,
|
|
277
|
-
writable: true,
|
|
278
|
-
value: (date) => {
|
|
279
|
-
return this.fullMonthFormatter.format(date);
|
|
280
|
-
}
|
|
148
|
+
* Equals moment format: 'MMMM'
|
|
149
|
+
* Returns: January
|
|
150
|
+
*/ _define_property(this, "formatFullMonth", (date)=>{
|
|
151
|
+
return this.fullMonthFormatter.format(date);
|
|
281
152
|
});
|
|
282
153
|
/**
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
enumerable: true,
|
|
288
|
-
configurable: true,
|
|
289
|
-
writable: true,
|
|
290
|
-
value: (date) => {
|
|
291
|
-
return this.fullMonthDateFormatter.format(date);
|
|
292
|
-
}
|
|
154
|
+
* Equals moment format: 'MMMM D, YYYY', with US locale - 'LL'
|
|
155
|
+
* Returns: January 2, 2020
|
|
156
|
+
*/ _define_property(this, "formatFullMonthDate", (date)=>{
|
|
157
|
+
return this.fullMonthDateFormatter.format(date);
|
|
293
158
|
});
|
|
294
159
|
/**
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
configurable: true,
|
|
301
|
-
writable: true,
|
|
302
|
-
value: (date) => {
|
|
303
|
-
const ordinalDate = ordinalString(date.getDate());
|
|
304
|
-
return `${this.formatShortMonth(date)} ${ordinalDate}, ${date.getFullYear()}`;
|
|
305
|
-
}
|
|
160
|
+
* Equals moment format: 'MMM Do, YYYY'
|
|
161
|
+
* Returns: Jan 2nd, 2020
|
|
162
|
+
*/ _define_property(this, "formatShortMonthOrdinalDate", (date)=>{
|
|
163
|
+
const ordinalDate = ordinalString(date.getDate());
|
|
164
|
+
return `${this.formatShortMonth(date)} ${ordinalDate}, ${date.getFullYear()}`;
|
|
306
165
|
});
|
|
307
166
|
/**
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
enumerable: true,
|
|
313
|
-
configurable: true,
|
|
314
|
-
writable: true,
|
|
315
|
-
value: (date) => {
|
|
316
|
-
return `${this.formatShortMonth(date)} ${date.getDate()} ${date.getFullYear()}`;
|
|
317
|
-
}
|
|
167
|
+
* Equals moment format: 'MMM D YYYY'
|
|
168
|
+
* Returns: Jan 2 2020
|
|
169
|
+
*/ _define_property(this, "formatShortMonthDate", (date)=>{
|
|
170
|
+
return `${this.formatShortMonth(date)} ${date.getDate()} ${date.getFullYear()}`;
|
|
318
171
|
});
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
configurable: true,
|
|
322
|
-
writable: true,
|
|
323
|
-
value: () => {
|
|
324
|
-
return this.locale;
|
|
325
|
-
}
|
|
172
|
+
_define_property(this, "getLocale", ()=>{
|
|
173
|
+
return this.locale;
|
|
326
174
|
});
|
|
327
175
|
this.locale = culture.Name;
|
|
328
176
|
this.dateFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
329
177
|
day: 'numeric',
|
|
330
178
|
month: 'numeric',
|
|
331
|
-
year: '2-digit'
|
|
179
|
+
year: '2-digit'
|
|
332
180
|
});
|
|
333
181
|
this.dateFullFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
334
182
|
day: '2-digit',
|
|
335
183
|
month: '2-digit',
|
|
336
|
-
year: 'numeric'
|
|
184
|
+
year: 'numeric'
|
|
337
185
|
});
|
|
338
186
|
this.shortTimeFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
339
187
|
hour: 'numeric',
|
|
340
|
-
minute: '2-digit'
|
|
188
|
+
minute: '2-digit'
|
|
341
189
|
});
|
|
342
190
|
this.fullTimeFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
343
191
|
hour: '2-digit',
|
|
344
|
-
minute: '2-digit'
|
|
192
|
+
minute: '2-digit'
|
|
345
193
|
});
|
|
346
194
|
this.short24HourTimeFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
347
195
|
hour: '2-digit',
|
|
348
196
|
minute: '2-digit',
|
|
349
|
-
hourCycle: 'h23'
|
|
197
|
+
hourCycle: 'h23'
|
|
350
198
|
});
|
|
351
199
|
this.medium24HourTimeFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
352
200
|
hour: '2-digit',
|
|
353
201
|
minute: '2-digit',
|
|
354
202
|
second: '2-digit',
|
|
355
|
-
hourCycle: 'h23'
|
|
203
|
+
hourCycle: 'h23'
|
|
204
|
+
});
|
|
205
|
+
this.shortWeekdayFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
206
|
+
weekday: 'short'
|
|
207
|
+
});
|
|
208
|
+
this.shortMonthFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
209
|
+
month: 'short'
|
|
356
210
|
});
|
|
357
|
-
this.shortWeekdayFormatter = new Intl.DateTimeFormat(this.locale, { weekday: 'short' });
|
|
358
|
-
this.shortMonthFormatter = new Intl.DateTimeFormat(this.locale, { month: 'short' });
|
|
359
211
|
this.shortMonthDateFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
360
212
|
month: 'short',
|
|
361
|
-
day: 'numeric'
|
|
213
|
+
day: 'numeric'
|
|
214
|
+
});
|
|
215
|
+
this.fullMonthFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
216
|
+
month: 'long'
|
|
362
217
|
});
|
|
363
|
-
this.fullMonthFormatter = new Intl.DateTimeFormat(this.locale, { month: 'long' });
|
|
364
218
|
this.fullMonthDateFormatter = new Intl.DateTimeFormat(this.locale, {
|
|
365
219
|
month: 'long',
|
|
366
220
|
day: 'numeric',
|
|
367
|
-
year: 'numeric'
|
|
221
|
+
year: 'numeric'
|
|
368
222
|
});
|
|
369
223
|
}
|
|
370
|
-
}
|
|
371
|
-
DateTimeUtils =
|
|
224
|
+
}
|
|
225
|
+
DateTimeUtils = _ts_decorate([
|
|
372
226
|
injectable(),
|
|
373
|
-
|
|
374
|
-
|
|
227
|
+
_ts_param(0, inject(CULTURE_TOKEN)),
|
|
228
|
+
_ts_metadata("design:type", Function),
|
|
229
|
+
_ts_metadata("design:paramtypes", [
|
|
230
|
+
typeof Culture === "undefined" ? Object : Culture
|
|
231
|
+
])
|
|
375
232
|
], DateTimeUtils);
|
|
376
|
-
|
|
233
|
+
|
|
377
234
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAW,MAAM,uBAAuB,CAAC;AAE/D,SAAS,aAAa,CAAC,GAAW;IAC9B,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAC;QAChB,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,KAAK,EAAE;YACH,OAAO,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;QACjC;YACI,QAAQ,GAAG,GAAG,EAAE,EAAE,CAAC;gBACf,KAAK,CAAC;oBACF,OAAO,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;gBACjC,KAAK,CAAC;oBACF,OAAO,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;gBACjC,KAAK,CAAC;oBACF,OAAO,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;gBACjC;oBACI,OAAO,GAAG,CAAC,QAAQ,EAAE,GAAG,IAAI,CAAC;YACrC,CAAC;IACT,CAAC;AACL,CAAC;AAGM,IAAM,aAAa,GAAnB,MAAM,aAAa;IActB,YAAmC,OAAgB;QAb3C;;;;;WAAe;QACf;;;;;WAAmC;QACnC;;;;;WAAuC;QACvC;;;;;WAAwC;QACxC;;;;;WAAuC;QACvC;;;;;WAA2C;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import { injectable, inject } from '@servicetitan/react-ioc';\nimport { CULTURE_TOKEN, Culture } from '@servicetitan/culture';\n\nfunction ordinalString(num: number): string {\n switch (num % 100) {\n case 11:\n case 12:\n case 13:\n return num.toString() + 'th';\n default:\n switch (num % 10) {\n case 1:\n return num.toString() + 'st';\n case 2:\n return num.toString() + 'nd';\n case 3:\n return num.toString() + 'rd';\n default:\n return num.toString() + 'th';\n }\n }\n}\n\n@injectable()\nexport class DateTimeUtils {\n private locale: string;\n private dateFormatter: Intl.DateTimeFormat;\n private dateFullFormatter: Intl.DateTimeFormat;\n private shortTimeFormatter: Intl.DateTimeFormat;\n private fullTimeFormatter: Intl.DateTimeFormat;\n private shortWeekdayFormatter: Intl.DateTimeFormat;\n private shortMonthFormatter: Intl.DateTimeFormat;\n private shortMonthDateFormatter: Intl.DateTimeFormat;\n private fullMonthFormatter: Intl.DateTimeFormat;\n private fullMonthDateFormatter: Intl.DateTimeFormat;\n private short24HourTimeFormatter: Intl.DateTimeFormat;\n private medium24HourTimeFormatter: Intl.DateTimeFormat;\n\n constructor(@inject(CULTURE_TOKEN) culture: Culture) {\n this.locale = culture.Name;\n\n this.dateFormatter = new Intl.DateTimeFormat(this.locale, {\n day: 'numeric',\n month: 'numeric',\n year: '2-digit',\n });\n this.dateFullFormatter = new Intl.DateTimeFormat(this.locale, {\n day: '2-digit',\n month: '2-digit',\n year: 'numeric',\n });\n this.shortTimeFormatter = new Intl.DateTimeFormat(this.locale, {\n hour: 'numeric',\n minute: '2-digit',\n });\n this.fullTimeFormatter = new Intl.DateTimeFormat(this.locale, {\n hour: '2-digit',\n minute: '2-digit',\n });\n this.short24HourTimeFormatter = new Intl.DateTimeFormat(this.locale, {\n hour: '2-digit',\n minute: '2-digit',\n hourCycle: 'h23',\n } as Intl.DateTimeFormatOptions);\n this.medium24HourTimeFormatter = new Intl.DateTimeFormat(this.locale, {\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit',\n hourCycle: 'h23',\n } as Intl.DateTimeFormatOptions);\n this.shortWeekdayFormatter = new Intl.DateTimeFormat(this.locale, { weekday: 'short' });\n this.shortMonthFormatter = new Intl.DateTimeFormat(this.locale, { month: 'short' });\n this.shortMonthDateFormatter = new Intl.DateTimeFormat(this.locale, {\n month: 'short',\n day: 'numeric',\n });\n this.fullMonthFormatter = new Intl.DateTimeFormat(this.locale, { month: 'long' });\n this.fullMonthDateFormatter = new Intl.DateTimeFormat(this.locale, {\n month: 'long',\n day: 'numeric',\n year: 'numeric',\n });\n }\n\n /**\n * General date formatting.\n *\n * @example\n * format(date, {\n * weekday: 'long',\n * month: 'long',\n * day: 'numeric'\n * }); // Tuesday, December 3\n */\n format = (date: Date, options?: Intl.DateTimeFormatOptions): string => {\n return date.toLocaleDateString(this.locale, options);\n };\n\n /**\n * Equals moment format: 'M/D/YY'\n * Returns: 1/2/20\n */\n formatDate = (date: Date): string => {\n return this.dateFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MMM DY'\n * Returns: Dec 2\n */\n formatDateShort = (date: Date): string => {\n return this.shortMonthDateFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MM/DD/YYYY', 'MM/DD/Y', with US locale - 'L'\n * Returns: 01/02/2020\n */\n formatDateFull = (date: Date): string => {\n return this.dateFullFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MM/DD/YYYY hh:mm A', with US locale - 'L LT'\n * Returns: 01/02/2020 03:47 AM\n */\n formatDateTimeFull = (date: Date): string => {\n return `${this.formatDateFull(date)} ${this.formatFullTime(date)}`;\n };\n\n /**\n * Equals moment format: 'M/D/YY hh:mm A', with US locale - 'L LT'\n * Returns: 1/2/20 3:47 AM\n */\n formatDateTimeShort = (date: Date): string => {\n return `${this.formatDate(date)} ${this.formatShortTime(date)}`;\n };\n\n /**\n * Equals moment format: 'MMM D, hh:mm A', with US locale - 'L LT'\n * Returns: Dec 2 3:47 AM\n */\n formatDateTimeShortest = (date: Date): string => {\n return `${this.formatDateShort(date)} ${this.formatShortTime(date)}`;\n };\n\n /**\n * Equals moment format: 'h:mm A', with US locale - 'LT'\n * Returns: 3:00 PM\n */\n formatShortTime = (date: Date): string => {\n return this.shortTimeFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'hh:mm A'\n * Returns: 03:00 PM\n */\n formatFullTime = (date: Date): string => {\n return this.fullTimeFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'hh:mm'\n * Returns: 15:00\n */\n formatShort24HourTime = (date: Date): string => {\n return this.short24HourTimeFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'hh:mm:ss'\n * Returns: 15:00:00\n */\n formatMedium24HourTime = (date: Date): string => {\n return this.medium24HourTimeFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'ddd'\n * Returns: Thu\n */\n formatShortWeekday = (date: Date): string => {\n return this.shortWeekdayFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MMM'\n * Returns: Jan\n */\n formatShortMonth = (date: Date): string => {\n return this.shortMonthFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MMMM'\n * Returns: January\n */\n formatFullMonth = (date: Date): string => {\n return this.fullMonthFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MMMM D, YYYY', with US locale - 'LL'\n * Returns: January 2, 2020\n */\n formatFullMonthDate = (date: Date): string => {\n return this.fullMonthDateFormatter.format(date);\n };\n\n /**\n * Equals moment format: 'MMM Do, YYYY'\n * Returns: Jan 2nd, 2020\n */\n formatShortMonthOrdinalDate = (date: Date): string => {\n const ordinalDate = ordinalString(date.getDate());\n return `${this.formatShortMonth(date)} ${ordinalDate}, ${date.getFullYear()}`;\n };\n\n /**\n * Equals moment format: 'MMM D YYYY'\n * Returns: Jan 2 2020\n */\n formatShortMonthDate = (date: Date): string => {\n return `${this.formatShortMonth(date)} ${date.getDate()} ${date.getFullYear()}`;\n };\n\n getLocale = (): string => {\n return this.locale;\n };\n}\n"],"names":["injectable","inject","CULTURE_TOKEN","Culture","ordinalString","num","toString","DateTimeUtils","constructor","culture","locale","dateFormatter","dateFullFormatter","shortTimeFormatter","fullTimeFormatter","shortWeekdayFormatter","shortMonthFormatter","shortMonthDateFormatter","fullMonthFormatter","fullMonthDateFormatter","short24HourTimeFormatter","medium24HourTimeFormatter","format","date","options","toLocaleDateString","formatDate","formatDateShort","formatDateFull","formatDateTimeFull","formatFullTime","formatDateTimeShort","formatShortTime","formatDateTimeShortest","formatShort24HourTime","formatMedium24HourTime","formatShortWeekday","formatShortMonth","formatFullMonth","formatFullMonthDate","formatShortMonthOrdinalDate","ordinalDate","getDate","getFullYear","formatShortMonthDate","getLocale","Name","Intl","DateTimeFormat","day","month","year","hour","minute","hourCycle","second","weekday"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,UAAU,EAAEC,MAAM,QAAQ,0BAA0B;AAC7D,SAASC,aAAa,EAAEC,OAAO,QAAQ,wBAAwB;AAE/D,SAASC,cAAcC,GAAW;IAC9B,OAAQA,MAAM;QACV,KAAK;QACL,KAAK;QACL,KAAK;YACD,OAAOA,IAAIC,QAAQ,KAAK;QAC5B;YACI,OAAQD,MAAM;gBACV,KAAK;oBACD,OAAOA,IAAIC,QAAQ,KAAK;gBAC5B,KAAK;oBACD,OAAOD,IAAIC,QAAQ,KAAK;gBAC5B,KAAK;oBACD,OAAOD,IAAIC,QAAQ,KAAK;gBAC5B;oBACI,OAAOD,IAAIC,QAAQ,KAAK;YAChC;IACR;AACJ;AAGA,OAAO,MAAMC;IAcTC,YAAY,AAAuBC,OAAgB,CAAE;QAbrD,uBAAQC,UAAR,KAAA;QACA,uBAAQC,iBAAR,KAAA;QACA,uBAAQC,qBAAR,KAAA;QACA,uBAAQC,sBAAR,KAAA;QACA,uBAAQC,qBAAR,KAAA;QACA,uBAAQC,yBAAR,KAAA;QACA,uBAAQC,uBAAR,KAAA;QACA,uBAAQC,2BAAR,KAAA;QACA,uBAAQC,sBAAR,KAAA;QACA,uBAAQC,0BAAR,KAAA;QACA,uBAAQC,4BAAR,KAAA;QACA,uBAAQ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AACtC,MAAM,EAAE;YAC3D0C,MAAM;YACNC,QAAQ;QACZ;QACA,IAAI,CAACvC,iBAAiB,GAAG,IAAIiC,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAC1D0C,MAAM;YACNC,QAAQ;QACZ;QACA,IAAI,CAACjC,wBAAwB,GAAG,IAAI2B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YACjE0C,MAAM;YACNC,QAAQ;YACRC,WAAW;QACf;QACA,IAAI,CAACjC,yBAAyB,GAAG,IAAI0B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAClE0C,MAAM;YACNC,QAAQ;YACRE,QAAQ;YACRD,WAAW;QACf;QACA,IAAI,CAACvC,qBAAqB,GAAG,IAAIgC,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAAE8C,SAAS;QAAQ;QACrF,IAAI,CAACxC,mBAAmB,GAAG,IAAI+B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAAEwC,OAAO;QAAQ;QACjF,IAAI,CAACjC,uBAAuB,GAAG,IAAI8B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAChEwC,OAAO;YACPD,KAAK;QACT;QACA,IAAI,CAAC/B,kBAAkB,GAAG,IAAI6B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAAEwC,OAAO;QAAO;QAC/E,IAAI,CAAC/B,sBAAsB,GAAG,IAAI4B,KAAKC,cAAc,CAAC,IAAI,CAACtC,MAAM,EAAE;YAC/DwC,OAAO;YACPD,KAAK;YACLE,MAAM;QACV;IACJ;AAoJJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/datetime-utils",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/date-time-formatting",
|
|
6
6
|
"repository": {
|
|
@@ -16,11 +16,11 @@
|
|
|
16
16
|
"src"
|
|
17
17
|
],
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@servicetitan/culture": "^31.
|
|
20
|
-
"@servicetitan/react-ioc": "^
|
|
19
|
+
"@servicetitan/culture": "^31.3.0",
|
|
20
|
+
"@servicetitan/react-ioc": "^31.3.2"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@servicetitan/culture": "^31.
|
|
23
|
+
"@servicetitan/culture": "^31.3.0",
|
|
24
24
|
"@servicetitan/react-ioc": ">21.0.0"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"cli": {
|
|
30
30
|
"webpack": false
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "7fc7b9cbf766fe23879ae81831f28bdd96559bce"
|
|
33
33
|
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { Container } from '@servicetitan/react-ioc';
|
|
2
|
-
import { CULTURE_TOKEN } from '@servicetitan/culture';
|
|
3
|
-
import { DateTimeUtils } from '..';
|
|
4
|
-
const rootContainer = new Container();
|
|
5
|
-
rootContainer.bind(DateTimeUtils).toSelf();
|
|
6
|
-
const initContainer = () => {
|
|
7
|
-
const container = new Container();
|
|
8
|
-
container.parent = rootContainer;
|
|
9
|
-
container.bind(CULTURE_TOKEN).toConstantValue({
|
|
10
|
-
Name: 'en-US',
|
|
11
|
-
DateTimeFormat: {
|
|
12
|
-
DateSeparator: '/',
|
|
13
|
-
LongDatePattern: 'dddd, MMMM d, yyyy',
|
|
14
|
-
ShortDatePattern: 'M/d/yyyy',
|
|
15
|
-
ShortTimePattern: 'h:mm tt',
|
|
16
|
-
},
|
|
17
|
-
NumberFormat: {
|
|
18
|
-
CurrencyPositivePattern: '%s%v',
|
|
19
|
-
CurrencyNegativePattern: '%s-%v',
|
|
20
|
-
CurrencySymbol: '$',
|
|
21
|
-
CurrencyDecimalSeparator: '.',
|
|
22
|
-
CurrencyGroupSeparator: ',',
|
|
23
|
-
CurrencyDecimalDigits: 2,
|
|
24
|
-
NumberDecimalSeparator: '.',
|
|
25
|
-
NumberGroupSeparator: ',',
|
|
26
|
-
NumberDecimalDigits: 2,
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
return { container };
|
|
30
|
-
};
|
|
31
|
-
const dateTimeSpaceSafe = (dateTime) => dateTime.replace(' ', ' '); // Node 18.13+ uses NNBSP before "AM"/"PM" https://github.com/nodejs/node/issues/46123 we replace it with regular whitespace for test compatibility purposes
|
|
32
|
-
describe('DateTimeUtils', () => {
|
|
33
|
-
let dateUtils;
|
|
34
|
-
let date;
|
|
35
|
-
beforeEach(() => {
|
|
36
|
-
const { container } = initContainer();
|
|
37
|
-
dateUtils = container.get(DateTimeUtils);
|
|
38
|
-
date = new Date(2020, 0, 9, 21, 41, 54);
|
|
39
|
-
});
|
|
40
|
-
test('getLocale', () => {
|
|
41
|
-
expect(dateUtils.getLocale()).toEqual('en-US');
|
|
42
|
-
});
|
|
43
|
-
test('format', () => {
|
|
44
|
-
expect(dateUtils.format(date, {
|
|
45
|
-
weekday: 'short',
|
|
46
|
-
month: 'long',
|
|
47
|
-
day: 'numeric',
|
|
48
|
-
})).toEqual('Thu, January 9');
|
|
49
|
-
expect(dateUtils.format(date, {
|
|
50
|
-
weekday: 'long',
|
|
51
|
-
month: 'long',
|
|
52
|
-
day: 'numeric',
|
|
53
|
-
})).toEqual('Thursday, January 9');
|
|
54
|
-
});
|
|
55
|
-
test('formatDate', () => {
|
|
56
|
-
expect(dateUtils.formatDate(date)).toEqual('1/9/20');
|
|
57
|
-
});
|
|
58
|
-
test('formatDateShort', () => {
|
|
59
|
-
expect(dateUtils.formatDateShort(date)).toEqual('Jan 9');
|
|
60
|
-
});
|
|
61
|
-
test('formatDateFull', () => {
|
|
62
|
-
expect(dateUtils.formatDateFull(date)).toEqual('01/09/2020');
|
|
63
|
-
});
|
|
64
|
-
test('formatDateTimeFull', () => {
|
|
65
|
-
expect(dateTimeSpaceSafe(dateUtils.formatDateTimeFull(date))).toEqual('01/09/2020 09:41 PM');
|
|
66
|
-
});
|
|
67
|
-
test('formatDateTimeShort', () => {
|
|
68
|
-
expect(dateTimeSpaceSafe(dateUtils.formatDateTimeShort(date))).toEqual('1/9/20 9:41 PM');
|
|
69
|
-
});
|
|
70
|
-
test('formatDateTimeShortest', () => {
|
|
71
|
-
expect(dateTimeSpaceSafe(dateUtils.formatDateTimeShortest(date))).toEqual('Jan 9 9:41 PM');
|
|
72
|
-
});
|
|
73
|
-
test('formatShortTime', () => {
|
|
74
|
-
expect(dateTimeSpaceSafe(dateUtils.formatShortTime(date))).toEqual('9:41 PM');
|
|
75
|
-
});
|
|
76
|
-
test('formatFullTime', () => {
|
|
77
|
-
expect(dateTimeSpaceSafe(dateUtils.formatFullTime(date))).toEqual('09:41 PM');
|
|
78
|
-
});
|
|
79
|
-
test('formatShortWeekday', () => {
|
|
80
|
-
expect(dateUtils.formatShortWeekday(date)).toEqual('Thu');
|
|
81
|
-
});
|
|
82
|
-
test('formatShortMonth', () => {
|
|
83
|
-
expect(dateUtils.formatShortMonth(date)).toEqual('Jan');
|
|
84
|
-
});
|
|
85
|
-
test('formatFullMonth', () => {
|
|
86
|
-
expect(dateUtils.formatFullMonth(date)).toEqual('January');
|
|
87
|
-
});
|
|
88
|
-
test('formatFullMonthDate', () => {
|
|
89
|
-
expect(dateUtils.formatFullMonthDate(date)).toEqual('January 9, 2020');
|
|
90
|
-
});
|
|
91
|
-
test('formatShortMonthOrdinalDate', () => {
|
|
92
|
-
expect(dateUtils.formatShortMonthOrdinalDate(date)).toEqual('Jan 9th, 2020');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["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