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