@bbn/bbn 2.0.35 → 2.0.36
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.
|
@@ -23,6 +23,12 @@ type CommonFormats = {
|
|
|
23
23
|
* - Date: only sensible combos (Y-M-D ± weekday, Y-M, M-D).
|
|
24
24
|
* - Time: hour / hour:minute / hour:minute:second (+ optional TZ).
|
|
25
25
|
* - Datetime: only full dates (Y-M-D ± weekday) combined with time.
|
|
26
|
+
*
|
|
27
|
+
* Fully numeric date forms (like "1/1/1970") are explicitly included via:
|
|
28
|
+
* { year: 'numeric', month: 'numeric', day: 'numeric' }
|
|
29
|
+
* { year: '2-digit', month: 'numeric', day: 'numeric' }
|
|
30
|
+
* { year: 'numeric', month: '2-digit', day: '2-digit' }
|
|
31
|
+
* { year: '2-digit', month: '2-digit', day: '2-digit' }
|
|
26
32
|
*/
|
|
27
33
|
export declare function getCommonFormatsForLocale(lng: string | string[]): CommonFormats;
|
|
28
34
|
export default function buildLocaleFromIntl(): void;
|
|
@@ -3,6 +3,8 @@ import numProperties from "../../fn/object/numProperties.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* Build a token pattern (YYYY, MM, DD, dddd, HH, II, SS, A, z) from Intl parts.
|
|
5
5
|
* Uses Intl options to distinguish MMM vs MMMM, ddd vs dddd, etc.
|
|
6
|
+
* All literal chunks are wrapped in square brackets so they can't be mistaken
|
|
7
|
+
* for tokens by the parser.
|
|
6
8
|
*/
|
|
7
9
|
function partsToPattern(parts, hourCycle, opts) {
|
|
8
10
|
let pattern = '';
|
|
@@ -21,10 +23,11 @@ function partsToPattern(parts, hourCycle, opts) {
|
|
|
21
23
|
pattern += 'MMMM';
|
|
22
24
|
}
|
|
23
25
|
else if (opts.month === 'numeric' || opts.month === '2-digit') {
|
|
26
|
+
// numeric month
|
|
24
27
|
pattern += /^\d{2}$/.test(p.value) ? 'MM' : 'M';
|
|
25
28
|
}
|
|
26
29
|
else {
|
|
27
|
-
// Fallback
|
|
30
|
+
// Fallback: infer from value
|
|
28
31
|
if (/^\d+$/.test(p.value)) {
|
|
29
32
|
pattern += p.value.length === 2 ? 'MM' : 'M';
|
|
30
33
|
}
|
|
@@ -67,8 +70,16 @@ function partsToPattern(parts, hourCycle, opts) {
|
|
|
67
70
|
case 'timeZoneName':
|
|
68
71
|
pattern += 'z';
|
|
69
72
|
break;
|
|
70
|
-
case 'literal':
|
|
73
|
+
case 'literal': {
|
|
74
|
+
// Wrap ALL literals into [ ... ] to avoid confusion with tokens
|
|
75
|
+
if (p.value.length) {
|
|
76
|
+
const v = p.value.replace(/]/g, '\\]');
|
|
77
|
+
pattern += `[${v}]`;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
71
81
|
default:
|
|
82
|
+
// Fallback, should be rare
|
|
72
83
|
pattern += p.value;
|
|
73
84
|
break;
|
|
74
85
|
}
|
|
@@ -83,6 +94,12 @@ function partsToPattern(parts, hourCycle, opts) {
|
|
|
83
94
|
* - Date: only sensible combos (Y-M-D ± weekday, Y-M, M-D).
|
|
84
95
|
* - Time: hour / hour:minute / hour:minute:second (+ optional TZ).
|
|
85
96
|
* - Datetime: only full dates (Y-M-D ± weekday) combined with time.
|
|
97
|
+
*
|
|
98
|
+
* Fully numeric date forms (like "1/1/1970") are explicitly included via:
|
|
99
|
+
* { year: 'numeric', month: 'numeric', day: 'numeric' }
|
|
100
|
+
* { year: '2-digit', month: 'numeric', day: 'numeric' }
|
|
101
|
+
* { year: 'numeric', month: '2-digit', day: '2-digit' }
|
|
102
|
+
* { year: '2-digit', month: '2-digit', day: '2-digit' }
|
|
86
103
|
*/
|
|
87
104
|
export function getCommonFormatsForLocale(lng) {
|
|
88
105
|
const sample = new Date(Date.UTC(2000, 0, 2, 13, 45, 30));
|
|
@@ -93,11 +110,14 @@ export function getCommonFormatsForLocale(lng) {
|
|
|
93
110
|
const seenTimePatterns = new Set();
|
|
94
111
|
const seenDateTimePatterns = new Set();
|
|
95
112
|
// ---- 1) DATE: curated list of useful patterns ----
|
|
96
|
-
//
|
|
113
|
+
// Numeric full dates (this covers "1/1/1970"-style formats as masks like D/M/YYYY or DD/MM/YYYY).
|
|
97
114
|
const dateOptionsList = [
|
|
98
|
-
//
|
|
99
|
-
{ year: 'numeric', month: '2-digit', day: '2-digit' },
|
|
115
|
+
// Fully numeric YYYY-M-D variants
|
|
100
116
|
{ year: 'numeric', month: 'numeric', day: 'numeric' },
|
|
117
|
+
{ year: 'numeric', month: '2-digit', day: '2-digit' },
|
|
118
|
+
{ year: '2-digit', month: 'numeric', day: 'numeric' },
|
|
119
|
+
{ year: '2-digit', month: '2-digit', day: '2-digit' },
|
|
120
|
+
// Full dates with textual month
|
|
101
121
|
{ year: 'numeric', month: 'short', day: 'numeric' },
|
|
102
122
|
{ year: 'numeric', month: 'long', day: 'numeric' },
|
|
103
123
|
// Full dates with weekday
|
|
@@ -111,7 +131,7 @@ export function getCommonFormatsForLocale(lng) {
|
|
|
111
131
|
// Month–day (no year)
|
|
112
132
|
{ month: 'numeric', day: 'numeric' },
|
|
113
133
|
{ month: '2-digit', day: '2-digit' },
|
|
114
|
-
{ month: 'short', day: 'numeric' },
|
|
134
|
+
{ month: 'short', day: 'numeric' },
|
|
115
135
|
{ month: 'long', day: 'numeric' }
|
|
116
136
|
];
|
|
117
137
|
const fullDateOptions = []; // Y+M+D (± weekday)
|
|
@@ -156,7 +176,7 @@ export function getCommonFormatsForLocale(lng) {
|
|
|
156
176
|
});
|
|
157
177
|
}
|
|
158
178
|
}
|
|
159
|
-
// ---- 3) DATETIME: only full dates (Y-M-D ± weekday) × time
|
|
179
|
+
// ---- 3) DATETIME: only full dates (Y-M-D ± weekday) × time ----
|
|
160
180
|
for (const dOpts of fullDateOptions) {
|
|
161
181
|
for (const tOpts of timeOptionsList) {
|
|
162
182
|
const opts = Object.assign(Object.assign({}, dOpts), tOpts);
|