@bbn/bbn 1.0.463 → 1.0.464
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 +10 -0
- package/dist/date.js +48 -0
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
|
@@ -45,6 +45,16 @@ declare class bbnDateTool {
|
|
|
45
45
|
calendar(format: string): string;
|
|
46
46
|
getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): any;
|
|
47
47
|
getWeekdayIndex(name: string, locale?: string): number;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a NEW date that is the next (or previous if past=true)
|
|
50
|
+
* occurrence of the given weekday, starting from this.#value.
|
|
51
|
+
*
|
|
52
|
+
* @param {number|string} weekday - Weekday index (0=Sunday…6=Saturday)
|
|
53
|
+
* or a localized weekday name.
|
|
54
|
+
* @param {boolean} past - If true → return previous occurrence instead of next.
|
|
55
|
+
* @param {string} [locale] - Optional locale for weekday names.
|
|
56
|
+
*/
|
|
57
|
+
setWeekday(weekday: any, past: boolean, locale: any): bbnDateTool;
|
|
48
58
|
copy(): Date;
|
|
49
59
|
/**
|
|
50
60
|
* Returns a NEW bbnDateTool at the start of the given unit.
|
package/dist/date.js
CHANGED
|
@@ -553,6 +553,54 @@ class bbnDateTool {
|
|
|
553
553
|
}
|
|
554
554
|
throw new Error(`Unknown weekday name '${name}' for locale '${loc}'`);
|
|
555
555
|
}
|
|
556
|
+
/**
|
|
557
|
+
* Returns a NEW date that is the next (or previous if past=true)
|
|
558
|
+
* occurrence of the given weekday, starting from this.#value.
|
|
559
|
+
*
|
|
560
|
+
* @param {number|string} weekday - Weekday index (0=Sunday…6=Saturday)
|
|
561
|
+
* or a localized weekday name.
|
|
562
|
+
* @param {boolean} past - If true → return previous occurrence instead of next.
|
|
563
|
+
* @param {string} [locale] - Optional locale for weekday names.
|
|
564
|
+
*/
|
|
565
|
+
setWeekday(weekday, past = false, locale) {
|
|
566
|
+
let targetDay;
|
|
567
|
+
if (typeof weekday === "string") {
|
|
568
|
+
// Use your previously defined reverse method:
|
|
569
|
+
weekday = this.getWeekdayIndex(weekday, locale);
|
|
570
|
+
}
|
|
571
|
+
// --- Normalize weekday ---
|
|
572
|
+
if (typeof weekday === "number") {
|
|
573
|
+
if (weekday < 0 || weekday > 6) {
|
|
574
|
+
throw new RangeError("weekday number must be between 0 and 6");
|
|
575
|
+
}
|
|
576
|
+
targetDay = weekday;
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
throw new TypeError("weekday must be a number (0–6) or a string");
|
|
580
|
+
}
|
|
581
|
+
const currentDay = this.weekday; // JS weekday (0–6)
|
|
582
|
+
let diff;
|
|
583
|
+
if (!past) {
|
|
584
|
+
// ---------- NEXT occurrence ----------
|
|
585
|
+
diff = (targetDay - currentDay + 7) % 7;
|
|
586
|
+
if (diff === 0) {
|
|
587
|
+
diff = 7; // next week if same day
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
else {
|
|
591
|
+
// ---------- PREVIOUS occurrence ----------
|
|
592
|
+
diff = (currentDay - targetDay + 7) % 7;
|
|
593
|
+
if (diff === 0) {
|
|
594
|
+
diff = 7; // previous week if same day
|
|
595
|
+
}
|
|
596
|
+
diff = -diff;
|
|
597
|
+
}
|
|
598
|
+
const d = this.copy();
|
|
599
|
+
d.setDate(d.getDate() + diff);
|
|
600
|
+
// Rebuild object keeping hours/min/sec from original
|
|
601
|
+
d.setHours(this.hours, this.minutes, this.seconds, 0);
|
|
602
|
+
return new bbnDateTool(d);
|
|
603
|
+
}
|
|
556
604
|
copy() {
|
|
557
605
|
return new Date(__classPrivateFieldGet(this, _bbnDateTool_value, "f").getTime());
|
|
558
606
|
}
|