@libs-ui/services-format-date 0.2.48 → 0.2.50
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.
|
@@ -1,90 +1,13 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { LibsUiPipesFormatDatePipe } from '@libs-ui/pipes-format-date';
|
|
3
3
|
import * as dayjs from 'dayjs';
|
|
4
|
-
import * as en from 'dayjs/locale/en';
|
|
5
|
-
import * as vi from 'dayjs/locale/vi';
|
|
6
4
|
import * as updateLocale from 'dayjs/plugin/updateLocale';
|
|
7
5
|
import * as i0 from "@angular/core";
|
|
8
6
|
dayjs.extend(updateLocale);
|
|
9
7
|
export class FormatDateService {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.
|
|
13
|
-
}
|
|
14
|
-
transform(time, format = 'YYYY/MM/DD HH:mm', lang) {
|
|
15
|
-
if (!time) {
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
lang = lang || UtilsCache.getLang();
|
|
19
|
-
if (this.functionFormatDate) {
|
|
20
|
-
return this.functionFormatDate(time, format, lang);
|
|
21
|
-
}
|
|
22
|
-
if (formatDate()) {
|
|
23
|
-
return formatDate()?.(time, format, lang) || '';
|
|
24
|
-
}
|
|
25
|
-
time = typeof time === 'number' ? dayjs.unix(time).locale(lang) : dayjs(time).locale(lang);
|
|
26
|
-
this.updateLocale(lang);
|
|
27
|
-
if (typeof time === 'number') {
|
|
28
|
-
return dayjs.unix(time).format(this.getFormatData(this.getTypeByFormat(format), lang));
|
|
29
|
-
}
|
|
30
|
-
return dayjs(time).format(this.getFormatData(this.getTypeByFormat(format), lang));
|
|
31
|
-
}
|
|
32
|
-
updateLocale(lang) {
|
|
33
|
-
if (lang === 'vi') {
|
|
34
|
-
dayjs.locale(vi);
|
|
35
|
-
dayjs.updateLocale('vi', {
|
|
36
|
-
monthsShort: 'Thg 1_Thg 2_Thg 3_Thg 4_Thg 5_Thg 6_Thg 7_Thg 8_Thg 9_Thg 10_Thg 11_Thg 12'.split('_')
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
dayjs.locale(en);
|
|
41
|
-
}
|
|
42
|
-
getTypeByFormat(format) {
|
|
43
|
-
if (format === 'dm' || format === 'dmy' || format === 'dmy hm' || format === 'my') {
|
|
44
|
-
return format;
|
|
45
|
-
}
|
|
46
|
-
if (format === 'DD/MM/YYYY' || format === 'YYYY-MM-DD' || format === 'dd/MM/yyyy' || format === 'dd-MM-yyyy' || format === 'dd/mm/yyyy') {
|
|
47
|
-
return 'dmy';
|
|
48
|
-
}
|
|
49
|
-
if (format === 'MM-DD' || format === 'dd/MM' || format === 'dd/mm') {
|
|
50
|
-
return 'dm';
|
|
51
|
-
}
|
|
52
|
-
if (format === 'M/YYYY' || format === 'YYYY-MM' || format === 'MM/yyyy') {
|
|
53
|
-
return 'my';
|
|
54
|
-
}
|
|
55
|
-
if (format === 'YYYY/MM/DD hh:mm:ss' || format === 'dmy hms' || format === 'dd/mm/yyyy hh:mm:ss') {
|
|
56
|
-
return 'dmy hms';
|
|
57
|
-
}
|
|
58
|
-
return 'dmy hm';
|
|
59
|
-
}
|
|
60
|
-
getFormatData(type, lang) {
|
|
61
|
-
switch (type) {
|
|
62
|
-
case 'dm':
|
|
63
|
-
if (lang === 'vi') {
|
|
64
|
-
return 'D MMM';
|
|
65
|
-
}
|
|
66
|
-
return 'MMM D';
|
|
67
|
-
case 'dmy':
|
|
68
|
-
if (lang === 'vi') {
|
|
69
|
-
return 'D MMM, YYYY';
|
|
70
|
-
}
|
|
71
|
-
return 'MMM D, YYYY';
|
|
72
|
-
case 'dmy hm':
|
|
73
|
-
if (lang === 'vi') {
|
|
74
|
-
return 'D MMM, YYYY HH:mm';
|
|
75
|
-
}
|
|
76
|
-
return 'MMM D, YYYY HH:mm';
|
|
77
|
-
case 'my':
|
|
78
|
-
if (lang === 'vi') {
|
|
79
|
-
return 'MMM, YYYY';
|
|
80
|
-
}
|
|
81
|
-
return 'MMM YYYY ';
|
|
82
|
-
case 'dmy hms':
|
|
83
|
-
if (lang === 'vi') {
|
|
84
|
-
return 'D MMM, YYYY HH:mm:ss';
|
|
85
|
-
}
|
|
86
|
-
return 'MMM D, YYYY HH:mm:ss';
|
|
87
|
-
}
|
|
8
|
+
formatDate = new LibsUiPipesFormatDatePipe();
|
|
9
|
+
transform(time, format = 'YYYY/MM/DD HH:mm', lang, functionCustomFormat) {
|
|
10
|
+
return this.formatDate.transform(time, format, lang, functionCustomFormat);
|
|
88
11
|
}
|
|
89
12
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
90
13
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, providedIn: 'root' });
|
|
@@ -93,4 +16,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
93
16
|
type: Injectable,
|
|
94
17
|
args: [{ providedIn: 'root' }]
|
|
95
18
|
}] });
|
|
96
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
19
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybWF0LWRhdGUuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL2xpYnMtdWkvc2VydmljZXMvZm9ybWF0LWRhdGUvc3JjL2Zvcm1hdC1kYXRlLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUMzQyxPQUFPLEVBQUUseUJBQXlCLEVBQUUsTUFBTSw0QkFBNEIsQ0FBQztBQUV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ydCBjbGFzcyBGb3JtYXREYXRlU2VydmljZSB7XG5cbiAgcHJpdmF0ZSBmb3JtYXREYXRlID0gbmV3IExpYnNVaVBpcGVzRm9ybWF0RGF0ZVBpcGUoKTtcblxuICBwdWJsaWMgdHJhbnNmb3JtKHRpbWU6IHN0cmluZyB8IG51bWJlciB8IGRheWpzLkRheWpzIHwgdW5kZWZpbmVkIHwgbnVsbCwgZm9ybWF0ID0gJ1lZWVkvTU0vREQgSEg6bW0nLCBsYW5nPzogc3RyaW5nLCBmdW5jdGlvbkN1c3RvbUZvcm1hdD86IFRZUEVfRlVOQ1RJT05fRk9STUFUX0RBVEUpOiBzdHJpbmcge1xuICAgIHJldHVybiB0aGlzLmZvcm1hdERhdGUudHJhbnNmb3JtKHRpbWUsIGZvcm1hdCwgbGFuZywgZnVuY3Rpb25DdXN0b21Gb3JtYXQpO1xuICB9XG5cblxufVxuIl19
|
|
@@ -1,91 +1,14 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable } from '@angular/core';
|
|
3
|
-
import {
|
|
3
|
+
import { LibsUiPipesFormatDatePipe } from '@libs-ui/pipes-format-date';
|
|
4
4
|
import * as dayjs from 'dayjs';
|
|
5
|
-
import * as en from 'dayjs/locale/en';
|
|
6
|
-
import * as vi from 'dayjs/locale/vi';
|
|
7
5
|
import * as updateLocale from 'dayjs/plugin/updateLocale';
|
|
8
6
|
|
|
9
7
|
dayjs.extend(updateLocale);
|
|
10
8
|
class FormatDateService {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.
|
|
14
|
-
}
|
|
15
|
-
transform(time, format = 'YYYY/MM/DD HH:mm', lang) {
|
|
16
|
-
if (!time) {
|
|
17
|
-
return '';
|
|
18
|
-
}
|
|
19
|
-
lang = lang || UtilsCache.getLang();
|
|
20
|
-
if (this.functionFormatDate) {
|
|
21
|
-
return this.functionFormatDate(time, format, lang);
|
|
22
|
-
}
|
|
23
|
-
if (formatDate()) {
|
|
24
|
-
return formatDate()?.(time, format, lang) || '';
|
|
25
|
-
}
|
|
26
|
-
time = typeof time === 'number' ? dayjs.unix(time).locale(lang) : dayjs(time).locale(lang);
|
|
27
|
-
this.updateLocale(lang);
|
|
28
|
-
if (typeof time === 'number') {
|
|
29
|
-
return dayjs.unix(time).format(this.getFormatData(this.getTypeByFormat(format), lang));
|
|
30
|
-
}
|
|
31
|
-
return dayjs(time).format(this.getFormatData(this.getTypeByFormat(format), lang));
|
|
32
|
-
}
|
|
33
|
-
updateLocale(lang) {
|
|
34
|
-
if (lang === 'vi') {
|
|
35
|
-
dayjs.locale(vi);
|
|
36
|
-
dayjs.updateLocale('vi', {
|
|
37
|
-
monthsShort: 'Thg 1_Thg 2_Thg 3_Thg 4_Thg 5_Thg 6_Thg 7_Thg 8_Thg 9_Thg 10_Thg 11_Thg 12'.split('_')
|
|
38
|
-
});
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
dayjs.locale(en);
|
|
42
|
-
}
|
|
43
|
-
getTypeByFormat(format) {
|
|
44
|
-
if (format === 'dm' || format === 'dmy' || format === 'dmy hm' || format === 'my') {
|
|
45
|
-
return format;
|
|
46
|
-
}
|
|
47
|
-
if (format === 'DD/MM/YYYY' || format === 'YYYY-MM-DD' || format === 'dd/MM/yyyy' || format === 'dd-MM-yyyy' || format === 'dd/mm/yyyy') {
|
|
48
|
-
return 'dmy';
|
|
49
|
-
}
|
|
50
|
-
if (format === 'MM-DD' || format === 'dd/MM' || format === 'dd/mm') {
|
|
51
|
-
return 'dm';
|
|
52
|
-
}
|
|
53
|
-
if (format === 'M/YYYY' || format === 'YYYY-MM' || format === 'MM/yyyy') {
|
|
54
|
-
return 'my';
|
|
55
|
-
}
|
|
56
|
-
if (format === 'YYYY/MM/DD hh:mm:ss' || format === 'dmy hms' || format === 'dd/mm/yyyy hh:mm:ss') {
|
|
57
|
-
return 'dmy hms';
|
|
58
|
-
}
|
|
59
|
-
return 'dmy hm';
|
|
60
|
-
}
|
|
61
|
-
getFormatData(type, lang) {
|
|
62
|
-
switch (type) {
|
|
63
|
-
case 'dm':
|
|
64
|
-
if (lang === 'vi') {
|
|
65
|
-
return 'D MMM';
|
|
66
|
-
}
|
|
67
|
-
return 'MMM D';
|
|
68
|
-
case 'dmy':
|
|
69
|
-
if (lang === 'vi') {
|
|
70
|
-
return 'D MMM, YYYY';
|
|
71
|
-
}
|
|
72
|
-
return 'MMM D, YYYY';
|
|
73
|
-
case 'dmy hm':
|
|
74
|
-
if (lang === 'vi') {
|
|
75
|
-
return 'D MMM, YYYY HH:mm';
|
|
76
|
-
}
|
|
77
|
-
return 'MMM D, YYYY HH:mm';
|
|
78
|
-
case 'my':
|
|
79
|
-
if (lang === 'vi') {
|
|
80
|
-
return 'MMM, YYYY';
|
|
81
|
-
}
|
|
82
|
-
return 'MMM YYYY ';
|
|
83
|
-
case 'dmy hms':
|
|
84
|
-
if (lang === 'vi') {
|
|
85
|
-
return 'D MMM, YYYY HH:mm:ss';
|
|
86
|
-
}
|
|
87
|
-
return 'MMM D, YYYY HH:mm:ss';
|
|
88
|
-
}
|
|
9
|
+
formatDate = new LibsUiPipesFormatDatePipe();
|
|
10
|
+
transform(time, format = 'YYYY/MM/DD HH:mm', lang, functionCustomFormat) {
|
|
11
|
+
return this.formatDate.transform(time, format, lang, functionCustomFormat);
|
|
89
12
|
}
|
|
90
13
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
91
14
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, providedIn: 'root' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"libs-ui-services-format-date.mjs","sources":["../../../../../libs-ui/services/format-date/src/format-date.service.ts","../../../../../libs-ui/services/format-date/src/libs-ui-services-format-date.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport {
|
|
1
|
+
{"version":3,"file":"libs-ui-services-format-date.mjs","sources":["../../../../../libs-ui/services/format-date/src/format-date.service.ts","../../../../../libs-ui/services/format-date/src/libs-ui-services-format-date.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { LibsUiPipesFormatDatePipe } from '@libs-ui/pipes-format-date';\nimport { TYPE_FUNCTION_FORMAT_DATE } from '@libs-ui/utils';\nimport * as dayjs from 'dayjs';\nimport * as updateLocale from 'dayjs/plugin/updateLocale';\ndayjs.extend(updateLocale);\n\n@Injectable({ providedIn: 'root' })\nexport class FormatDateService {\n\n private formatDate = new LibsUiPipesFormatDatePipe();\n\n public transform(time: string | number | dayjs.Dayjs | undefined | null, format = 'YYYY/MM/DD HH:mm', lang?: string, functionCustomFormat?: TYPE_FUNCTION_FORMAT_DATE): string {\n return this.formatDate.transform(time, format, lang, functionCustomFormat);\n }\n\n\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAKA,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC;MAGb,iBAAiB,CAAA;AAEpB,IAAA,UAAU,GAAG,IAAI,yBAAyB,EAAE;IAE7C,SAAS,CAAC,IAAsD,EAAE,MAAM,GAAG,kBAAkB,EAAE,IAAa,EAAE,oBAAgD,EAAA;AACnK,QAAA,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,CAAC;;wGALjE,iBAAiB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAjB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,iBAAiB,cADJ,MAAM,EAAA,CAAA;;4FACnB,iBAAiB,EAAA,UAAA,EAAA,CAAA;kBAD7B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACPlC;;AAEG;;;;"}
|
package/format-date.service.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
import { TYPE_FUNCTION_FORMAT_DATE } from '@libs-ui/utils';
|
|
1
2
|
import * as dayjs from 'dayjs';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
3
4
|
export declare class FormatDateService {
|
|
4
|
-
private
|
|
5
|
-
|
|
6
|
-
transform(time: string | number | dayjs.Dayjs | undefined | null, format?: string, lang?: string): string;
|
|
7
|
-
private updateLocale;
|
|
8
|
-
private getTypeByFormat;
|
|
9
|
-
private getFormatData;
|
|
5
|
+
private formatDate;
|
|
6
|
+
transform(time: string | number | dayjs.Dayjs | undefined | null, format?: string, lang?: string, functionCustomFormat?: TYPE_FUNCTION_FORMAT_DATE): string;
|
|
10
7
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormatDateService, never>;
|
|
11
8
|
static ɵprov: i0.ɵɵInjectableDeclaration<FormatDateService>;
|
|
12
9
|
}
|