@bbn/bbn 1.0.462 → 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 +26 -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
|
@@ -496,11 +496,11 @@ class bbnDateTool {
|
|
|
496
496
|
}
|
|
497
497
|
return str;
|
|
498
498
|
}
|
|
499
|
-
|
|
499
|
+
getWeekday(n, mode = 'long', locale) {
|
|
500
500
|
if (!mode) {
|
|
501
|
-
const letter = this.
|
|
502
|
-
const abbr = this.
|
|
503
|
-
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);
|
|
504
504
|
return {
|
|
505
505
|
letter,
|
|
506
506
|
abbr,
|
|
@@ -531,6 +531,28 @@ class bbnDateTool {
|
|
|
531
531
|
const base = new Date(2023, 0, 1 + n);
|
|
532
532
|
return base.toLocaleDateString([locale || bbn.env.lang, ...navigator.languages], { weekday: m });
|
|
533
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
|
+
}
|
|
534
556
|
copy() {
|
|
535
557
|
return new Date(__classPrivateFieldGet(this, _bbnDateTool_value, "f").getTime());
|
|
536
558
|
}
|