@libs-ui/services-format-date 0.2.88 → 0.2.90
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,9 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import * as en from 'dayjs/locale/en';
|
|
5
|
-
import * as vi from 'dayjs/locale/vi';
|
|
6
|
-
import plugin from 'dayjs/plugin/updateLocale';
|
|
2
|
+
import { formatDate } from '@libs-ui/utils';
|
|
7
3
|
import * as i0 from "@angular/core";
|
|
8
|
-
dayjs.extend(plugin);
|
|
9
4
|
export class FormatDateService {
|
|
10
|
-
functionFormatDate;
|
|
11
|
-
updateFunctionFormatDate(functionCustom) {
|
|
12
|
-
this.functionFormatDate = functionCustom;
|
|
13
|
-
}
|
|
14
5
|
transform(time, format = 'YYYY/MM/DD HH:mm', lang) {
|
|
15
|
-
|
|
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
|
-
}
|
|
6
|
+
return formatDate(time, format, lang) || '';
|
|
88
7
|
}
|
|
89
8
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
90
9
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, providedIn: 'root' });
|
|
@@ -93,4 +12,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
93
12
|
type: Injectable,
|
|
94
13
|
args: [{ providedIn: 'root' }]
|
|
95
14
|
}] });
|
|
96
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZm9ybWF0LWRhdGUuc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL2xpYnMtdWkvc2VydmljZXMvZm9ybWF0LWRhdGUvc3JjL2Zvcm1hdC1kYXRlLnNlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUMzQyxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZ0JBQWdCLENBQUM7O0FBSTVDLE1BQU0sT0FBTyxpQkFBaUI7SUFFckIsU0FBUyxDQUFDLElBQXNELEVBQUUsTUFBTSxHQUFHLGtCQUFrQixFQUFFLElBQWE7UUFDakgsT0FBTyxVQUFVLENBQUMsSUFBSSxFQUFFLE1BQU0sRUFBRSxJQUFJLENBQUMsSUFBSSxFQUFFLENBQUM7SUFDOUMsQ0FBQzt3R0FKVSxpQkFBaUI7NEdBQWpCLGlCQUFpQixjQURKLE1BQU07OzRGQUNuQixpQkFBaUI7a0JBRDdCLFVBQVU7bUJBQUMsRUFBRSxVQUFVLEVBQUUsTUFBTSxFQUFFIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgSW5qZWN0YWJsZSB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuaW1wb3J0IHsgZm9ybWF0RGF0ZSB9IGZyb20gJ0BsaWJzLXVpL3V0aWxzJztcbmltcG9ydCBkYXlqcyBmcm9tICdkYXlqcyc7XG5cbkBJbmplY3RhYmxlKHsgcHJvdmlkZWRJbjogJ3Jvb3QnIH0pXG5leHBvcnQgY2xhc3MgRm9ybWF0RGF0ZVNlcnZpY2Uge1xuXG4gIHB1YmxpYyB0cmFuc2Zvcm0odGltZTogc3RyaW5nIHwgbnVtYmVyIHwgZGF5anMuRGF5anMgfCB1bmRlZmluZWQgfCBudWxsLCBmb3JtYXQgPSAnWVlZWS9NTS9ERCBISDptbScsIGxhbmc/OiBzdHJpbmcpOiBzdHJpbmcge1xuICAgIHJldHVybiBmb3JtYXREYXRlKHRpbWUsIGZvcm1hdCwgbGFuZykgfHwgJyc7XG4gIH1cblxufVxuIl19
|
|
@@ -1,91 +1,10 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { Injectable } from '@angular/core';
|
|
3
|
-
import {
|
|
4
|
-
import dayjs from 'dayjs';
|
|
5
|
-
import * as en from 'dayjs/locale/en';
|
|
6
|
-
import * as vi from 'dayjs/locale/vi';
|
|
7
|
-
import plugin from 'dayjs/plugin/updateLocale';
|
|
3
|
+
import { formatDate } from '@libs-ui/utils';
|
|
8
4
|
|
|
9
|
-
dayjs.extend(plugin);
|
|
10
5
|
class FormatDateService {
|
|
11
|
-
functionFormatDate;
|
|
12
|
-
updateFunctionFormatDate(functionCustom) {
|
|
13
|
-
this.functionFormatDate = functionCustom;
|
|
14
|
-
}
|
|
15
6
|
transform(time, format = 'YYYY/MM/DD HH:mm', lang) {
|
|
16
|
-
|
|
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
|
-
}
|
|
7
|
+
return formatDate(time, format, lang) || '';
|
|
89
8
|
}
|
|
90
9
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: FormatDateService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
91
10
|
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 { formatDate } from '@libs-ui/utils';\nimport dayjs from 'dayjs';\n\n@Injectable({ providedIn: 'root' })\nexport class FormatDateService {\n\n public transform(time: string | number | dayjs.Dayjs | undefined | null, format = 'YYYY/MM/DD HH:mm', lang?: string): string {\n return formatDate(time, format, lang) || '';\n }\n\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAKa,iBAAiB,CAAA;AAErB,IAAA,SAAS,CAAC,IAAsD,EAAE,MAAM,GAAG,kBAAkB,EAAE,IAAa,EAAA;QACjH,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE;;wGAHlC,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;;;ACJlC;;AAEG;;;;"}
|
package/format-date.service.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
export declare class FormatDateService {
|
|
4
|
-
private functionFormatDate;
|
|
5
|
-
updateFunctionFormatDate(functionCustom: (time: string | number | dayjs.Dayjs | undefined | null, format: string, lang?: string) => string): void;
|
|
6
4
|
transform(time: string | number | dayjs.Dayjs | undefined | null, format?: string, lang?: string): string;
|
|
7
|
-
private updateLocale;
|
|
8
|
-
private getTypeByFormat;
|
|
9
|
-
private getFormatData;
|
|
10
5
|
static ɵfac: i0.ɵɵFactoryDeclaration<FormatDateService, never>;
|
|
11
6
|
static ɵprov: i0.ɵɵInjectableDeclaration<FormatDateService>;
|
|
12
7
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libs-ui/services-format-date",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.90",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"@angular/common": "^18.2.0",
|
|
6
|
-
"@angular/core": "^18.2.0"
|
|
6
|
+
"@angular/core": "^18.2.0",
|
|
7
|
+
"dayjs": "1.11.5"
|
|
7
8
|
},
|
|
8
9
|
"sideEffects": false,
|
|
9
10
|
"module": "fesm2022/libs-ui-services-format-date.mjs",
|