ect-date-formatter 1.15.0 → 1.16.1
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/README.md +2 -2
- package/{esm2020 → esm2022}/ect-date-formatter.mjs +4 -4
- package/esm2022/lib/ect-date-formatter.module.mjs +28 -0
- package/esm2022/lib/ect-date-formatter.service.mjs +307 -0
- package/{esm2020 → esm2022}/public-api.mjs +23 -23
- package/{fesm2015 → fesm2022}/ect-date-formatter.mjs +345 -346
- package/{fesm2020 → fesm2022}/ect-date-formatter.mjs.map +1 -1
- package/index.d.ts +5 -5
- package/lib/ect-date-formatter.module.d.ts +7 -7
- package/lib/ect-date-formatter.service.d.ts +44 -44
- package/package.json +9 -15
- package/public-api.d.ts +2 -2
- package/esm2020/lib/ect-date-formatter.module.mjs +0 -27
- package/esm2020/lib/ect-date-formatter.service.mjs +0 -306
- package/fesm2015/ect-date-formatter.mjs.map +0 -1
- package/fesm2020/ect-date-formatter.mjs +0 -360
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, LOCALE_ID, NgModule } from '@angular/core';
|
|
3
|
-
import { HttpClientModule } from '@angular/common/http';
|
|
4
|
-
|
|
5
|
-
class EctDateFormatterService {
|
|
6
|
-
getISO8601DateFormat(date) {
|
|
7
|
-
return this.get4DigitYear(date) + '-' + this.get2DigitMonth(date) + '-' + this.get2DigitDay(date);
|
|
8
|
-
}
|
|
9
|
-
getISO8601TimeFormat(date) {
|
|
10
|
-
return this.get2Digit24Hours(date) + ':' + this.get2DigitMinutes(date) + ':' + this.get2DigitSeconds(date);
|
|
11
|
-
}
|
|
12
|
-
getISO8601DateAndTimeFormat(date) {
|
|
13
|
-
return this.getISO8601DateFormat(date) + 'T' + this.getISO8601TimeFormat(date);
|
|
14
|
-
}
|
|
15
|
-
getFormatPartsByDivider(input) {
|
|
16
|
-
if (input.indexOf(' ') > 0) {
|
|
17
|
-
return {
|
|
18
|
-
parts: input.split(' '),
|
|
19
|
-
divider: ' '
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
if (input.indexOf('/') > 0) {
|
|
23
|
-
return {
|
|
24
|
-
parts: input.split('/'),
|
|
25
|
-
divider: '/'
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (input.indexOf(':') > 0) {
|
|
29
|
-
return {
|
|
30
|
-
parts: input.split(':'),
|
|
31
|
-
divider: ':'
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
if (input.indexOf(';') > 0) {
|
|
35
|
-
return {
|
|
36
|
-
parts: input.split(';'),
|
|
37
|
-
divider: ';'
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
if (input.indexOf('.') > 0) {
|
|
41
|
-
return {
|
|
42
|
-
parts: input.split('.'),
|
|
43
|
-
divider: '.'
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
if (input.indexOf(',') > 0) {
|
|
47
|
-
return {
|
|
48
|
-
parts: input.split(','),
|
|
49
|
-
divider: ','
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
if (input.indexOf('-') > 0) {
|
|
53
|
-
return {
|
|
54
|
-
parts: input.split('-'),
|
|
55
|
-
divider: '-'
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (input.indexOf('_') > 0) {
|
|
59
|
-
return {
|
|
60
|
-
parts: input.split('_'),
|
|
61
|
-
divider: '_'
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
return { parts: [], divider: '' };
|
|
65
|
-
}
|
|
66
|
-
/*
|
|
67
|
-
Date Formatting Rules
|
|
68
|
-
|
|
69
|
-
yy/YY – two-digit year, e.g. 21
|
|
70
|
-
yyyy/YYYY – four-digit year, e.g. 2021
|
|
71
|
-
m/M – one-digit month for months below 10, e.g. 3
|
|
72
|
-
mm/MM – two-digit month, e.g. 03
|
|
73
|
-
mmm/MMM – three-letter abbreviation for month, e.g. Mar
|
|
74
|
-
mmmm/MMMM – month spelled out in full, e.g. March
|
|
75
|
-
d/D – one-digit day of the month for days below 10, e.g. 2
|
|
76
|
-
dd/DD – two-digit day of the month, e.g. 02
|
|
77
|
-
ddd/DDD – three-letter abbreviation for day of the week, e.g. Fri
|
|
78
|
-
dddd/DDDD – day of the week spelled out in full, e.g. Friday
|
|
79
|
-
|
|
80
|
-
*/
|
|
81
|
-
formatDate(date, format) {
|
|
82
|
-
const formatPartsAndDivider = this.getFormatPartsByDivider(format);
|
|
83
|
-
let dateValue = '';
|
|
84
|
-
formatPartsAndDivider.parts.forEach(part => {
|
|
85
|
-
if (dateValue !== '')
|
|
86
|
-
dateValue += formatPartsAndDivider.divider;
|
|
87
|
-
switch (part) {
|
|
88
|
-
case 'yy':
|
|
89
|
-
case 'YY':
|
|
90
|
-
dateValue += this.get2DigitYear(date);
|
|
91
|
-
break;
|
|
92
|
-
case 'yyyy':
|
|
93
|
-
case 'YYYY':
|
|
94
|
-
dateValue += this.get4DigitYear(date);
|
|
95
|
-
break;
|
|
96
|
-
case 'm':
|
|
97
|
-
case 'M':
|
|
98
|
-
dateValue += this.get1DigitMonth(date);
|
|
99
|
-
break;
|
|
100
|
-
case 'mm':
|
|
101
|
-
case 'MM':
|
|
102
|
-
dateValue += this.get2DigitMonth(date);
|
|
103
|
-
break;
|
|
104
|
-
case 'mmm':
|
|
105
|
-
case 'MMM':
|
|
106
|
-
dateValue += this.get3DigitMonth(date);
|
|
107
|
-
break;
|
|
108
|
-
case 'mmmm':
|
|
109
|
-
case 'MMMM':
|
|
110
|
-
dateValue += this.get4DigitMonth(date);
|
|
111
|
-
break;
|
|
112
|
-
case 'd':
|
|
113
|
-
case 'D':
|
|
114
|
-
dateValue += this.get1DigitDay(date);
|
|
115
|
-
break;
|
|
116
|
-
case 'dd':
|
|
117
|
-
case 'DD':
|
|
118
|
-
dateValue += this.get2DigitDay(date);
|
|
119
|
-
break;
|
|
120
|
-
case 'ddd':
|
|
121
|
-
case 'DDD':
|
|
122
|
-
dateValue += this.get3DigitDay(date);
|
|
123
|
-
break;
|
|
124
|
-
case 'dddd':
|
|
125
|
-
case 'DDDD':
|
|
126
|
-
dateValue += this.get4DigitDay(date);
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
return dateValue;
|
|
131
|
-
}
|
|
132
|
-
/*
|
|
133
|
-
Time Formatting Rules
|
|
134
|
-
|
|
135
|
-
h - hour to 1 digit on 12 hour clock - without leading 0
|
|
136
|
-
hh - hour to 2 digits on 12 hour clock - with leading 0
|
|
137
|
-
H - hour to 1 digit on 24 hour clock - without leading 0
|
|
138
|
-
HH - hour to 2 digits on 24 hour clock - with leading 0
|
|
139
|
-
m - minute to 1 digit - without leading 0
|
|
140
|
-
mm/mi/MI - minute to 2 digits - with leading 0
|
|
141
|
-
s/S - second to 1 digit - without leading 0
|
|
142
|
-
ss/SS - second to 2 digits - with leading 0
|
|
143
|
-
f/F - tenth of a second e.g. 2009-06-15T13:45:30.6170000 -> 6
|
|
144
|
-
ff/FF - hundredths of a second e.g. 2009-06-15T13:45:30.6170000 -> 61
|
|
145
|
-
fff/FFF - milliseconds e.g. 6/15/2009 13:45:30.617 -> 617
|
|
146
|
-
ffff/FFFF - ten thousandths of a second e.g. 2009-06-15T13:45:30.6175000 -> 6175
|
|
147
|
-
fffff/FFFFF - hundred thousandths of a second e.g. 2009-06-15T13:45:30.6175400 -> 61754
|
|
148
|
-
ffffff/FFFFFF - millionths of a second e.g. 2009-06-15T13:45:30.6175420 -> 617542
|
|
149
|
-
t/T - first character of AM/PM
|
|
150
|
-
tt/TT - both characters of AM/PM
|
|
151
|
-
|
|
152
|
-
*/
|
|
153
|
-
formatTime(date, format) {
|
|
154
|
-
const formatPartsAndDivider = this.getFormatPartsByDivider(format);
|
|
155
|
-
let timeValue = '';
|
|
156
|
-
formatPartsAndDivider.parts.forEach(part => {
|
|
157
|
-
if (timeValue !== '')
|
|
158
|
-
timeValue += formatPartsAndDivider.divider;
|
|
159
|
-
switch (part) {
|
|
160
|
-
case 'h':
|
|
161
|
-
timeValue += this.get1Digit12Hours(date);
|
|
162
|
-
break;
|
|
163
|
-
case 'hh':
|
|
164
|
-
timeValue += this.get2Digit12Hours(date);
|
|
165
|
-
break;
|
|
166
|
-
case 'H':
|
|
167
|
-
timeValue += this.get1Digit24Hours(date);
|
|
168
|
-
break;
|
|
169
|
-
case 'HH':
|
|
170
|
-
timeValue += this.get2Digit24Hours(date);
|
|
171
|
-
break;
|
|
172
|
-
case 'm':
|
|
173
|
-
timeValue += this.get1DigitMinutes(date);
|
|
174
|
-
break;
|
|
175
|
-
case 'mi':
|
|
176
|
-
case 'mm':
|
|
177
|
-
case 'MI':
|
|
178
|
-
timeValue += this.get2DigitMinutes(date);
|
|
179
|
-
break;
|
|
180
|
-
case 's':
|
|
181
|
-
case 'S':
|
|
182
|
-
timeValue += this.get1DigitSeconds(date);
|
|
183
|
-
break;
|
|
184
|
-
case 'ss':
|
|
185
|
-
case 'SS':
|
|
186
|
-
timeValue += this.get2DigitSeconds(date);
|
|
187
|
-
break;
|
|
188
|
-
case 't':
|
|
189
|
-
case 'T':
|
|
190
|
-
timeValue += this.get1DigitAmPm(date);
|
|
191
|
-
break;
|
|
192
|
-
case 'tt':
|
|
193
|
-
case 'TT':
|
|
194
|
-
timeValue += this.get2DigitAmPm(date);
|
|
195
|
-
break;
|
|
196
|
-
case 'f':
|
|
197
|
-
case 'F':
|
|
198
|
-
timeValue += this.getXDigitMillisecond(date, 'f');
|
|
199
|
-
break;
|
|
200
|
-
case 'ff':
|
|
201
|
-
case 'FF':
|
|
202
|
-
timeValue += this.getXDigitMillisecond(date, 'fff');
|
|
203
|
-
break;
|
|
204
|
-
case 'fff':
|
|
205
|
-
case 'FFF':
|
|
206
|
-
timeValue += this.getXDigitMillisecond(date, 'fff');
|
|
207
|
-
break;
|
|
208
|
-
case 'ffff':
|
|
209
|
-
case 'FFFF':
|
|
210
|
-
timeValue += this.getXDigitMillisecond(date, 'ffff');
|
|
211
|
-
break;
|
|
212
|
-
case 'fffff':
|
|
213
|
-
case 'FFFFF':
|
|
214
|
-
timeValue += this.getXDigitMillisecond(date, 'fffff');
|
|
215
|
-
break;
|
|
216
|
-
case 'ffffff':
|
|
217
|
-
case 'FFFFFF':
|
|
218
|
-
timeValue += this.getXDigitMillisecond(date, 'ffffff');
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
return timeValue;
|
|
223
|
-
}
|
|
224
|
-
get1DigitDay(date) {
|
|
225
|
-
const day = date.getDate();
|
|
226
|
-
return '' + day;
|
|
227
|
-
}
|
|
228
|
-
get2DigitDay(date) {
|
|
229
|
-
const day = date.getDate();
|
|
230
|
-
return this.padDateElement(day);
|
|
231
|
-
}
|
|
232
|
-
get3DigitDay(date) {
|
|
233
|
-
return date.toLocaleString('default', { weekday: 'short' });
|
|
234
|
-
}
|
|
235
|
-
get4DigitDay(date) {
|
|
236
|
-
return date.toLocaleString('default', { weekday: 'long' });
|
|
237
|
-
}
|
|
238
|
-
get1DigitMonth(date) {
|
|
239
|
-
const month = date.getMonth() + 1;
|
|
240
|
-
return '' + month;
|
|
241
|
-
}
|
|
242
|
-
get2DigitMonth(date) {
|
|
243
|
-
const month = date.getMonth() + 1;
|
|
244
|
-
return this.padDateElement(month);
|
|
245
|
-
}
|
|
246
|
-
get3DigitMonth(date) {
|
|
247
|
-
return date.toLocaleString('default', { month: 'long' }).substring(0, 3);
|
|
248
|
-
}
|
|
249
|
-
get4DigitMonth(date) {
|
|
250
|
-
return date.toLocaleString('default', { month: 'long' });
|
|
251
|
-
}
|
|
252
|
-
get2DigitYear(date) {
|
|
253
|
-
const fullYear = '' + date.getFullYear();
|
|
254
|
-
return fullYear[2];
|
|
255
|
-
}
|
|
256
|
-
get4DigitYear(date) {
|
|
257
|
-
return date.getFullYear().toString();
|
|
258
|
-
}
|
|
259
|
-
get1Digit12Hours(date) {
|
|
260
|
-
return date.getHours().toString();
|
|
261
|
-
}
|
|
262
|
-
get2Digit12Hours(date) {
|
|
263
|
-
const hours = date.getHours();
|
|
264
|
-
return this.padDateElement(hours);
|
|
265
|
-
}
|
|
266
|
-
get1Digit24Hours(date) {
|
|
267
|
-
return date.getHours().toString();
|
|
268
|
-
}
|
|
269
|
-
get2Digit24Hours(date) {
|
|
270
|
-
const hours = date.getHours();
|
|
271
|
-
return this.padDateElement(hours);
|
|
272
|
-
}
|
|
273
|
-
get1DigitMinutes(date) {
|
|
274
|
-
return date.getMinutes().toString();
|
|
275
|
-
}
|
|
276
|
-
get2DigitMinutes(date) {
|
|
277
|
-
const minutes = date.getMinutes();
|
|
278
|
-
return this.padDateElement(minutes);
|
|
279
|
-
}
|
|
280
|
-
get1DigitSeconds(date) {
|
|
281
|
-
return date.getSeconds().toString();
|
|
282
|
-
}
|
|
283
|
-
get2DigitSeconds(date) {
|
|
284
|
-
const seconds = date.getSeconds();
|
|
285
|
-
return this.padDateElement(seconds);
|
|
286
|
-
}
|
|
287
|
-
get1DigitAmPm(date) {
|
|
288
|
-
return date.toLocaleDateString('t');
|
|
289
|
-
}
|
|
290
|
-
get2DigitAmPm(date) {
|
|
291
|
-
return date.toLocaleDateString('tt');
|
|
292
|
-
}
|
|
293
|
-
getXDigitMillisecond(date, format) {
|
|
294
|
-
return date.toLocaleDateString(format);
|
|
295
|
-
}
|
|
296
|
-
padDateElement(value) {
|
|
297
|
-
return (value < 10) ? '0' + value : '' + value;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
EctDateFormatterService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
301
|
-
EctDateFormatterService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterService, providedIn: 'root' });
|
|
302
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterService, decorators: [{
|
|
303
|
-
type: Injectable,
|
|
304
|
-
args: [{
|
|
305
|
-
providedIn: 'root'
|
|
306
|
-
}]
|
|
307
|
-
}] });
|
|
308
|
-
|
|
309
|
-
class EctDateFormatterModule {
|
|
310
|
-
}
|
|
311
|
-
EctDateFormatterModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
312
|
-
EctDateFormatterModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterModule, imports: [HttpClientModule] });
|
|
313
|
-
EctDateFormatterModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterModule, providers: [
|
|
314
|
-
EctDateFormatterService,
|
|
315
|
-
{ provide: LOCALE_ID, useValue: 'en-GB' }
|
|
316
|
-
], imports: [HttpClientModule] });
|
|
317
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: EctDateFormatterModule, decorators: [{
|
|
318
|
-
type: NgModule,
|
|
319
|
-
args: [{
|
|
320
|
-
declarations: [],
|
|
321
|
-
imports: [
|
|
322
|
-
HttpClientModule
|
|
323
|
-
],
|
|
324
|
-
exports: [],
|
|
325
|
-
providers: [
|
|
326
|
-
EctDateFormatterService,
|
|
327
|
-
{ provide: LOCALE_ID, useValue: 'en-GB' }
|
|
328
|
-
]
|
|
329
|
-
}]
|
|
330
|
-
}] });
|
|
331
|
-
|
|
332
|
-
/*
|
|
333
|
-
Copyright (c) 2023 Exodus Cloud Technology Solutions Ltd
|
|
334
|
-
|
|
335
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
336
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
337
|
-
in the Software without restriction, including without limitation the rights
|
|
338
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
339
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
340
|
-
furnished to do so, subject to the following conditions:
|
|
341
|
-
|
|
342
|
-
The above copyright notice and this permission notice shall be included in all
|
|
343
|
-
copies or substantial portions of the Software.
|
|
344
|
-
|
|
345
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
346
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
347
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
348
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
349
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
350
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
351
|
-
SOFTWARE.
|
|
352
|
-
*/
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Generated bundle index. Do not edit.
|
|
356
|
-
*/
|
|
357
|
-
|
|
358
|
-
export { EctDateFormatterModule, EctDateFormatterService };
|
|
359
|
-
//# sourceMappingURL=ect-date-formatter.mjs.map
|
|
360
|
-
//# sourceMappingURL=ect-date-formatter.mjs.map
|