@bbn/bbn 2.0.42 → 2.0.43
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/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/functions/buildLocaleFromIntl.js +15 -19
- package/package.json +1 -1
|
@@ -9,14 +9,17 @@ function partsToPattern(parts, resolved, requestedOpts) {
|
|
|
9
9
|
const hourCycle = resolved.hourCycle;
|
|
10
10
|
const hasDayPeriod = parts.some(p => p.type === 'dayPeriod');
|
|
11
11
|
const is12h = hasDayPeriod || hourCycle === 'h12' || hourCycle === 'h11';
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const hasYear = !!requestedOpts.year;
|
|
13
|
+
const hasMonth = !!requestedOpts.month;
|
|
14
|
+
const hasDay = !!requestedOpts.day;
|
|
15
|
+
const hasWeekday = !!requestedOpts.weekday;
|
|
16
|
+
const hasTextMonth = requestedOpts.month === 'short' || requestedOpts.month === 'long';
|
|
17
|
+
// "Whole numeric date" = year+month+day, all numeric, no weekday, no text month
|
|
18
|
+
const isWholeNumericDate = hasYear && hasMonth && hasDay && !hasWeekday && !hasTextMonth;
|
|
16
19
|
for (const p of parts) {
|
|
17
20
|
switch (p.type) {
|
|
18
21
|
case 'year': {
|
|
19
|
-
//
|
|
22
|
+
// Keep YY when the locale actually resolved to 2-digit
|
|
20
23
|
if (resolved.year === '2-digit') {
|
|
21
24
|
pattern += 'YY';
|
|
22
25
|
}
|
|
@@ -31,24 +34,23 @@ function partsToPattern(parts, resolved, requestedOpts) {
|
|
|
31
34
|
pattern += requestedOpts.month === 'long' ? 'MMMM' : 'MMM';
|
|
32
35
|
break;
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
if (isWholeNumericDate) {
|
|
38
|
+
// whole numeric date → always use M (accepts 1–2 digits)
|
|
36
39
|
pattern += 'M';
|
|
37
40
|
break;
|
|
38
41
|
}
|
|
39
|
-
// numeric
|
|
42
|
+
// other numeric month cases (e.g. year–month or month–day)
|
|
40
43
|
if (/^\d+$/.test(p.value)) {
|
|
41
44
|
pattern += p.value.length === 2 ? 'MM' : 'M';
|
|
42
45
|
}
|
|
43
46
|
else {
|
|
44
|
-
// fallback (shouldn't really happen without text month)
|
|
45
47
|
pattern += p.value.length > 3 ? 'MMMM' : 'MMM';
|
|
46
48
|
}
|
|
47
49
|
break;
|
|
48
50
|
}
|
|
49
51
|
case 'day': {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
if (isWholeNumericDate) {
|
|
53
|
+
// whole numeric date → always use D (accepts 1–2 digits)
|
|
52
54
|
pattern += 'D';
|
|
53
55
|
break;
|
|
54
56
|
}
|
|
@@ -89,15 +91,9 @@ function partsToPattern(parts, resolved, requestedOpts) {
|
|
|
89
91
|
pattern += 'z';
|
|
90
92
|
break;
|
|
91
93
|
case 'literal': {
|
|
92
|
-
// Wrap literals in [ ... ] so your parser won't confuse them with tokens
|
|
93
94
|
if (p.value.length) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
pattern += `[${v}]`;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
pattern += p.value;
|
|
100
|
-
}
|
|
95
|
+
const v = p.value.replace(/]/g, '\\]');
|
|
96
|
+
pattern += `[${v}]`;
|
|
101
97
|
}
|
|
102
98
|
break;
|
|
103
99
|
}
|