igniteui-i18n-core 1.0.2 → 1.0.4
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.
|
@@ -21,11 +21,24 @@ export class DateFormatter extends BaseFormatter {
|
|
|
21
21
|
if (typeof dateValue === 'string') {
|
|
22
22
|
// Workaround for ISO date without time or specified UTC explicitly
|
|
23
23
|
const match = isoRegex.exec(dateValue);
|
|
24
|
-
if (match && !match.groups?.time && !match.groups?.UTC) {
|
|
25
|
-
|
|
24
|
+
if (match?.groups && !match.groups?.time && !match.groups?.UTC) {
|
|
25
|
+
let day = '';
|
|
26
|
+
if (match.groups.day) {
|
|
27
|
+
day = `-${match.groups.day.length === 1 ? '0' : ''}${match.groups.day}`;
|
|
28
|
+
}
|
|
29
|
+
let month = '';
|
|
30
|
+
if (match.groups.month) {
|
|
31
|
+
month = `-${match.groups.month.length === 1 ? '0' : ''}${match.groups.month}`;
|
|
32
|
+
}
|
|
33
|
+
dateValue = `${match.groups.year}${month}${day}T00:00:00`;
|
|
26
34
|
}
|
|
27
35
|
}
|
|
28
|
-
|
|
36
|
+
let returnDate = new Date(dateValue);
|
|
37
|
+
if (isNaN(returnDate.getTime())) {
|
|
38
|
+
console.warn(`Invalid date entered: ${value}`);
|
|
39
|
+
returnDate = new Date(value);
|
|
40
|
+
}
|
|
41
|
+
return returnDate;
|
|
29
42
|
}
|
|
30
43
|
/**
|
|
31
44
|
* Format a date object or date number using Intl.
|
|
@@ -35,8 +48,14 @@ export class DateFormatter extends BaseFormatter {
|
|
|
35
48
|
* @returns String representing the formatted value.
|
|
36
49
|
*/
|
|
37
50
|
formatDateTime(date, locale, options) {
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
try {
|
|
52
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
53
|
+
return formatter.format(date);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.warn(e);
|
|
57
|
+
}
|
|
58
|
+
return date.toString();
|
|
40
59
|
}
|
|
41
60
|
/**
|
|
42
61
|
* Format a date object or date number using Intl.
|
|
@@ -46,8 +65,14 @@ export class DateFormatter extends BaseFormatter {
|
|
|
46
65
|
* @returns Array of strings representing the formatted value, separated in parts.
|
|
47
66
|
*/
|
|
48
67
|
formatDateTimeToParts(date, locale, options) {
|
|
49
|
-
|
|
50
|
-
|
|
68
|
+
try {
|
|
69
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
70
|
+
return formatter.formatToParts(date);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
console.warn(e);
|
|
74
|
+
}
|
|
75
|
+
return [];
|
|
51
76
|
}
|
|
52
77
|
/**
|
|
53
78
|
* Format date range using Intl.DateTimeFormat
|
|
@@ -58,8 +83,14 @@ export class DateFormatter extends BaseFormatter {
|
|
|
58
83
|
* @returns String representing the formatted range of dates
|
|
59
84
|
*/
|
|
60
85
|
formatRange(startDate, endDate, locale, options) {
|
|
61
|
-
|
|
62
|
-
|
|
86
|
+
try {
|
|
87
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
88
|
+
return formatter.formatRange(startDate, endDate);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
console.warn(e);
|
|
92
|
+
}
|
|
93
|
+
return `${startDate.toString()} - ${endDate.toString()}`;
|
|
63
94
|
}
|
|
64
95
|
/**
|
|
65
96
|
* Format date range using Intl.DateTimeFormat
|
|
@@ -70,8 +101,14 @@ export class DateFormatter extends BaseFormatter {
|
|
|
70
101
|
* @returns String representing the formatted range of dates
|
|
71
102
|
*/
|
|
72
103
|
formatRangeToParts(startDate, endDate, locale, options) {
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
try {
|
|
105
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
106
|
+
return formatter.formatRangeToParts(startDate, endDate);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.warn(e);
|
|
110
|
+
}
|
|
111
|
+
return [];
|
|
75
112
|
}
|
|
76
113
|
/**
|
|
77
114
|
* Get the format of a date, based on the options provided.
|
|
@@ -14,8 +14,14 @@ export class NumberFormatter extends BaseFormatter {
|
|
|
14
14
|
* @returns Formatted value.
|
|
15
15
|
*/
|
|
16
16
|
formatNumber(value, locale, options) {
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
try {
|
|
18
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
19
|
+
return formatter.format(value);
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
console.warn(e);
|
|
23
|
+
}
|
|
24
|
+
return String(value);
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
27
|
* Get the currency symbol for provided currency code.
|
|
@@ -31,8 +37,14 @@ export class NumberFormatter extends BaseFormatter {
|
|
|
31
37
|
currencyDisplay: currencyDisplay,
|
|
32
38
|
maximumFractionDigits: 0,
|
|
33
39
|
};
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
try {
|
|
41
|
+
const formatter = this.getIntlFormatter(locale, options);
|
|
42
|
+
return formatter.formatToParts(0).find((part) => part.type === 'currency')?.value;
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
console.warn(e);
|
|
46
|
+
}
|
|
47
|
+
return currencyCode;
|
|
36
48
|
}
|
|
37
49
|
/**
|
|
38
50
|
* Get the currency symbol/name position in formatted value.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-i18n-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "IgniteUI for Angular localization resources package",
|
|
5
5
|
"author": "Infragistics",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"igniteui-i18n-resources": "1.0.
|
|
34
|
+
"igniteui-i18n-resources": "1.0.4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependenciesMeta": {
|
|
37
37
|
"igniteui-i18n-resources": {
|