@bbn/bbn 1.0.460 → 1.0.461
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 +11 -0
- package/dist/date.js +90 -0
- package/package.json +1 -1
package/dist/date.d.ts
CHANGED
|
@@ -44,6 +44,17 @@ declare class bbnDateTool {
|
|
|
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
|
+
copy(): Date;
|
|
48
|
+
/**
|
|
49
|
+
* Returns a NEW bbnDateTool at the start of the given unit.
|
|
50
|
+
* Units: year, month, week, day, hour, minute, second
|
|
51
|
+
*/
|
|
52
|
+
startOf(unit?: string): bbnDateTool;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a NEW bbnDateTool at the end of the given unit.
|
|
55
|
+
* Units: year, month, week, day, hour, minute, second
|
|
56
|
+
*/
|
|
57
|
+
endOf(unit?: string): bbnDateTool;
|
|
47
58
|
get daysInMonth(): number;
|
|
48
59
|
}
|
|
49
60
|
declare function generatorFunction(value: any, inputFormat?: null | String): bbnDateTool;
|
package/dist/date.js
CHANGED
|
@@ -530,6 +530,96 @@ class bbnDateTool {
|
|
|
530
530
|
const base = new Date(2023, 0, 1 + n);
|
|
531
531
|
return base.toLocaleDateString([locale || bbn.env.lang, ...navigator.languages], { weekday: m });
|
|
532
532
|
}
|
|
533
|
+
copy() {
|
|
534
|
+
return new Date(__classPrivateFieldGet(this, _bbnDateTool_value, "f").getTime());
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Returns a NEW bbnDateTool at the start of the given unit.
|
|
538
|
+
* Units: year, month, week, day, hour, minute, second
|
|
539
|
+
*/
|
|
540
|
+
startOf(unit = "d") {
|
|
541
|
+
const u = unitsCorrespondence[unit];
|
|
542
|
+
if (!u) {
|
|
543
|
+
throw new Error('Invalid unit for startOf: ' + unit);
|
|
544
|
+
}
|
|
545
|
+
let d;
|
|
546
|
+
switch (u) {
|
|
547
|
+
case "y":
|
|
548
|
+
d = new Date(this.year, 0, 1, 0, 0, 0, 0);
|
|
549
|
+
break;
|
|
550
|
+
case "m":
|
|
551
|
+
d = new Date(this.year, this.month - 1, 1, 0, 0, 0, 0);
|
|
552
|
+
break;
|
|
553
|
+
case "w": {
|
|
554
|
+
// Week starting Monday:
|
|
555
|
+
// JS getDay(): 0 (Sun) .. 6 (Sat)
|
|
556
|
+
const current = new Date(this.year, this.month - 1, this.day, this.hours, this.minutes, this.seconds, 0);
|
|
557
|
+
const wd = current.getDay(); // 0..6
|
|
558
|
+
const diffToMonday = (wd + 6) % 7; // 0 for Monday, 6 for Sunday
|
|
559
|
+
d = new Date(current.getFullYear(), current.getMonth(), current.getDate() - diffToMonday, 0, 0, 0, 0);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
case "d":
|
|
563
|
+
d = new Date(this.year, this.month - 1, this.day, 0, 0, 0, 0);
|
|
564
|
+
break;
|
|
565
|
+
case "h":
|
|
566
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, 0, 0, 0);
|
|
567
|
+
break;
|
|
568
|
+
case "i":
|
|
569
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, this.minutes, 0, 0);
|
|
570
|
+
break;
|
|
571
|
+
case "s":
|
|
572
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, this.minutes, this.seconds, 0);
|
|
573
|
+
break;
|
|
574
|
+
default:
|
|
575
|
+
throw new Error('Invalid unit for startOf: ' + unit);
|
|
576
|
+
}
|
|
577
|
+
return new bbnDateTool(d);
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Returns a NEW bbnDateTool at the end of the given unit.
|
|
581
|
+
* Units: year, month, week, day, hour, minute, second
|
|
582
|
+
*/
|
|
583
|
+
endOf(unit = "d") {
|
|
584
|
+
const u = unitsCorrespondence[unit];
|
|
585
|
+
if (!u) {
|
|
586
|
+
throw new Error('Invalid unit for endOf: ' + unit);
|
|
587
|
+
}
|
|
588
|
+
let d;
|
|
589
|
+
switch (u) {
|
|
590
|
+
case "y":
|
|
591
|
+
// Dec 31, 23:59:59.999
|
|
592
|
+
d = new Date(this.year, 11, 31, 23, 59, 59, 999);
|
|
593
|
+
break;
|
|
594
|
+
case "m":
|
|
595
|
+
// Day 0 of next month = last day of this month
|
|
596
|
+
d = new Date(this.year, this.month, 0, 23, 59, 59, 999);
|
|
597
|
+
break;
|
|
598
|
+
case "w": {
|
|
599
|
+
// End of week (starting Monday) = startOf('week') + 6 days, at 23:59:59.999
|
|
600
|
+
const start = this.startOf("w");
|
|
601
|
+
const base = new Date(start.year, start.month - 1, start.day, 23, 59, 59, 999);
|
|
602
|
+
base.setDate(base.getDate() + 6);
|
|
603
|
+
d = base;
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
case "day":
|
|
607
|
+
d = new Date(this.year, this.month - 1, this.day, 23, 59, 59, 999);
|
|
608
|
+
break;
|
|
609
|
+
case "hour":
|
|
610
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, 59, 59, 999);
|
|
611
|
+
break;
|
|
612
|
+
case "minute":
|
|
613
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, this.minutes, 59, 999);
|
|
614
|
+
break;
|
|
615
|
+
case "second":
|
|
616
|
+
d = new Date(this.year, this.month - 1, this.day, this.hours, this.minutes, this.seconds, 999);
|
|
617
|
+
break;
|
|
618
|
+
default:
|
|
619
|
+
d = new Date(this.mtst);
|
|
620
|
+
}
|
|
621
|
+
return new bbnDateTool(d);
|
|
622
|
+
}
|
|
533
623
|
get daysInMonth() {
|
|
534
624
|
if (this.isValid && !__classPrivateFieldGet(this, _bbnDateTool_daysInMonth, "f")) {
|
|
535
625
|
switch (__classPrivateFieldGet(this, _bbnDateTool_value, "f").getMonth()) {
|