@bbn/bbn 1.0.461 → 1.0.463
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/date.d.ts +2 -1
- package/dist/date.js +27 -4
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
|
@@ -43,7 +43,8 @@ declare class bbnDateTool {
|
|
|
43
43
|
guessUnit(valueInMs: number): string | null;
|
|
44
44
|
diff(date: any, unit?: string, abs?: boolean): number;
|
|
45
45
|
calendar(format: string): string;
|
|
46
|
-
|
|
46
|
+
getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): any;
|
|
47
|
+
getWeekdayIndex(name: string, locale?: string): number;
|
|
47
48
|
copy(): Date;
|
|
48
49
|
/**
|
|
49
50
|
* Returns a NEW bbnDateTool at the start of the given unit.
|
package/dist/date.js
CHANGED
|
@@ -185,6 +185,7 @@ const unitsCorrespondence = {
|
|
|
185
185
|
'mm': 'i',
|
|
186
186
|
'min': 'i',
|
|
187
187
|
'n': 'i',
|
|
188
|
+
'i': 'i',
|
|
188
189
|
'SS': 's',
|
|
189
190
|
'ss': 's',
|
|
190
191
|
'seconds': 's',
|
|
@@ -495,11 +496,11 @@ class bbnDateTool {
|
|
|
495
496
|
}
|
|
496
497
|
return str;
|
|
497
498
|
}
|
|
498
|
-
|
|
499
|
+
getWeekday(n, mode = 'long', locale) {
|
|
499
500
|
if (!mode) {
|
|
500
|
-
const letter = this.
|
|
501
|
-
const abbr = this.
|
|
502
|
-
const full = this.
|
|
501
|
+
const letter = this.getWeekday(n, 'narrow', locale);
|
|
502
|
+
const abbr = this.getWeekday(n, 'short', locale);
|
|
503
|
+
const full = this.getWeekday(n, 'long', locale);
|
|
503
504
|
return {
|
|
504
505
|
letter,
|
|
505
506
|
abbr,
|
|
@@ -530,6 +531,28 @@ class bbnDateTool {
|
|
|
530
531
|
const base = new Date(2023, 0, 1 + n);
|
|
531
532
|
return base.toLocaleDateString([locale || bbn.env.lang, ...navigator.languages], { weekday: m });
|
|
532
533
|
}
|
|
534
|
+
getWeekdayIndex(name, locale) {
|
|
535
|
+
const loc = locale || bbn.env.lang;
|
|
536
|
+
const input = name.trim().toLowerCase();
|
|
537
|
+
// Build a localized map only once per locale (optional optimization)
|
|
538
|
+
const langs = [loc, ...navigator.languages];
|
|
539
|
+
for (let i = 0; i < langs.length; i++) {
|
|
540
|
+
if (!langs[i]) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
const formatter = new Intl.DateTimeFormat(langs[i], { weekday: "long" });
|
|
544
|
+
// Generate localized weekday names for Sun → Sat
|
|
545
|
+
for (let i = 0; i < 7; i++) {
|
|
546
|
+
// 2023-01-01 was Sunday
|
|
547
|
+
const date = new Date(2023, 0, 1 + i);
|
|
548
|
+
const localized = formatter.format(date).toLowerCase();
|
|
549
|
+
if (localized === input) {
|
|
550
|
+
return i; // JS weekday number
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
throw new Error(`Unknown weekday name '${name}' for locale '${loc}'`);
|
|
555
|
+
}
|
|
533
556
|
copy() {
|
|
534
557
|
return new Date(__classPrivateFieldGet(this, _bbnDateTool_value, "f").getTime());
|
|
535
558
|
}
|