@bbn/bbn 2.0.47 → 2.0.49
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,10 +1,9 @@
|
|
|
1
1
|
import extend from "../../fn/object/extend.js";
|
|
2
|
-
import numProperties from "../../fn/object/numProperties.js";
|
|
3
2
|
/**
|
|
4
3
|
* Build a token pattern (YYYY, MM, DD, dddd, HH, II, SS, A, z) from Intl parts.
|
|
5
4
|
* Uses Intl options to distinguish MMM vs MMMM, ddd vs dddd, etc.
|
|
6
5
|
*/
|
|
7
|
-
|
|
6
|
+
const partsToPattern = (parts, resolved, requestedOpts) => {
|
|
8
7
|
let pattern = '';
|
|
9
8
|
const hourCycle = resolved.hourCycle;
|
|
10
9
|
const hasDayPeriod = parts.some(p => p.type === 'dayPeriod');
|
|
@@ -115,7 +114,7 @@ function partsToPattern(parts, resolved, requestedOpts) {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
return pattern;
|
|
118
|
-
}
|
|
117
|
+
};
|
|
119
118
|
/**
|
|
120
119
|
* Get a curated set of *common* date, time and datetime formats
|
|
121
120
|
* for the given locale, without exploding into thousands of combos.
|
|
@@ -218,7 +217,7 @@ export function getCommonFormatsForLocale(lng) {
|
|
|
218
217
|
return { date, time, datetime };
|
|
219
218
|
}
|
|
220
219
|
export default function buildLocaleFromIntl() {
|
|
221
|
-
if (
|
|
220
|
+
if (Object.keys(bbn.dt.locales).length) {
|
|
222
221
|
return;
|
|
223
222
|
}
|
|
224
223
|
const langs = [bbn.env.lang, ...navigator.languages];
|
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
import parse from './parse.js';
|
|
2
2
|
import { getCommonFormatsForLocale } from './buildLocaleFromIntl.js';
|
|
3
|
+
// Common MySQL & native JS string formats – tried first in guessFormat
|
|
4
|
+
const MYSQL_AND_NATIVE_FORMATS = [
|
|
5
|
+
// --- MySQL / MariaDB classic ---
|
|
6
|
+
// Date
|
|
7
|
+
'YYYY-MM-DD',
|
|
8
|
+
// Date + time
|
|
9
|
+
'YYYY-MM-DD HH:II:SS.ms',
|
|
10
|
+
'YYYY-MM-DD HH:II:SS',
|
|
11
|
+
'YYYY-MM-DD HH:II',
|
|
12
|
+
// Time only
|
|
13
|
+
'HH:II:SS',
|
|
14
|
+
'HH:II',
|
|
15
|
+
// --- ISO 8601 / JS toISOString() ---
|
|
16
|
+
// 2025-11-22T14:30:00.123Z
|
|
17
|
+
'YYYY-MM-DDTHH:II:SS.msZ',
|
|
18
|
+
// 2025-11-22T14:30:00Z
|
|
19
|
+
'YYYY-MM-DDTHH:II:SSZ',
|
|
20
|
+
// 2025-11-22T14:30:00
|
|
21
|
+
'YYYY-MM-DDTHH:II:SS',
|
|
22
|
+
// 2025-11-22T14:30
|
|
23
|
+
'YYYY-MM-DDTHH:II',
|
|
24
|
+
// --- JS toUTCString() ---
|
|
25
|
+
// Tue, 29 Oct 2024 14:30:00 GMT
|
|
26
|
+
'ddd[, ]DD MMM YYYY HH:II:SS[ GMT]',
|
|
27
|
+
// --- JS toString() (without the parenthesized TZ name) ---
|
|
28
|
+
// Tue Oct 29 2024 14:30:00 GMT+0200
|
|
29
|
+
'ddd MMM DD YYYY HH:II:SS[ GMT]Z',
|
|
30
|
+
// Tue Oct 29 2024 14:30:00
|
|
31
|
+
'ddd MMM DD YYYY HH:II:SS'
|
|
32
|
+
];
|
|
3
33
|
const isPureNumericDateFormat = (fmt) => {
|
|
4
34
|
// Only Y/M/D tokens and literal separators, no time or AM/PM tokens
|
|
5
35
|
if (/[HhI SAz]/.test(fmt)) {
|
|
@@ -90,9 +120,29 @@ export default function guessFormat(input, formats, lng) {
|
|
|
90
120
|
? navigator.language
|
|
91
121
|
: Intl.DateTimeFormat().resolvedOptions().locale);
|
|
92
122
|
const common = getCommonFormatsForLocale(resolvedLocale);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
123
|
+
// Avoid trivial duplicates
|
|
124
|
+
const seen = new Set();
|
|
125
|
+
const mysqlNativeCandidates = MYSQL_AND_NATIVE_FORMATS.filter(fmt => {
|
|
126
|
+
if (seen.has(fmt))
|
|
127
|
+
return false;
|
|
128
|
+
seen.add(fmt);
|
|
129
|
+
return true;
|
|
130
|
+
});
|
|
131
|
+
const localeCandidates = [
|
|
132
|
+
...common.datetime.map(f => f.pattern),
|
|
133
|
+
...common.date.map(f => f.pattern),
|
|
134
|
+
...common.time.map(f => f.pattern)
|
|
135
|
+
].filter(fmt => {
|
|
136
|
+
if (seen.has(fmt))
|
|
137
|
+
return false;
|
|
138
|
+
seen.add(fmt);
|
|
139
|
+
return true;
|
|
140
|
+
});
|
|
141
|
+
// MySQL & native JS patterns are checked FIRST
|
|
142
|
+
const candidates = [
|
|
143
|
+
...mysqlNativeCandidates,
|
|
144
|
+
...localeCandidates
|
|
145
|
+
];
|
|
96
146
|
const fmt = tryFormats(candidates);
|
|
97
147
|
if (fmt) {
|
|
98
148
|
return fmt;
|