@bbn/bbn 2.0.68 → 2.0.69
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/dt/classes/dt.d.ts +32 -0
- package/dist/dt/classes/dt.js +365 -2
- package/package.json +1 -1
package/dist/dt/classes/dt.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Temporal } from 'temporal-polyfill';
|
|
1
2
|
import { bbnDtTemporal } from '../vars/types.js';
|
|
2
3
|
import bbnDtDuration from './duration.js';
|
|
3
4
|
export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
@@ -5,6 +6,29 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
5
6
|
abstract readonly kind: bbnDtKind;
|
|
6
7
|
constructor(value?: TValue);
|
|
7
8
|
get value(): TValue | undefined;
|
|
9
|
+
/** System time zone ID (e.g. "Europe/Rome") */
|
|
10
|
+
private static readonly systemTimeZoneId;
|
|
11
|
+
/**
|
|
12
|
+
* Convert this.value (PlainDate, PlainTime, PlainDateTime, YearMonth,
|
|
13
|
+
* MonthDay, ZonedDateTime) into epoch milliseconds, using the system
|
|
14
|
+
* time zone when needed.
|
|
15
|
+
*
|
|
16
|
+
* Conventions:
|
|
17
|
+
* - time → today at that time in system tz
|
|
18
|
+
* - date → that date at 00:00 in system tz
|
|
19
|
+
* - year-month → first of that month at 00:00 in system tz
|
|
20
|
+
* - month-day → that month/day in *this year* at 00:00 in system tz
|
|
21
|
+
*/
|
|
22
|
+
protected toEpochMs(): number;
|
|
23
|
+
/**
|
|
24
|
+
* "Now" value in the same *kind* as this instance.
|
|
25
|
+
*/
|
|
26
|
+
protected static nowForKind(kind: bbnDtKind): Temporal.PlainDate | Temporal.PlainTime | Temporal.PlainDateTime | Temporal.PlainYearMonth | Temporal.PlainMonthDay | Temporal.ZonedDateTime;
|
|
27
|
+
/**
|
|
28
|
+
* Helper to rebuild the same concrete subclass with a new Temporal value.
|
|
29
|
+
* Assumes your subclass constructor takes the value as first argument.
|
|
30
|
+
*/
|
|
31
|
+
protected withValue(newValue: any): this;
|
|
8
32
|
static compare(a: any, b: any, unit: string | undefined): -1 | 0 | 1;
|
|
9
33
|
static parse(input: string, format: string | string[], cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', locale?: {
|
|
10
34
|
monthsLong?: string[];
|
|
@@ -17,7 +41,9 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
17
41
|
add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
18
42
|
subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
|
|
19
43
|
isBefore(other: any): boolean;
|
|
44
|
+
isBeforeOrSame(other: any): boolean;
|
|
20
45
|
isAfter(other: any): boolean;
|
|
46
|
+
isAfterOrSame(other: any): boolean;
|
|
21
47
|
isSame(other: any): boolean;
|
|
22
48
|
equals(other: any): boolean;
|
|
23
49
|
toJSON(): {
|
|
@@ -68,5 +94,11 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
|
|
|
68
94
|
* @param {string} [locale] - Optional locale for weekday names.
|
|
69
95
|
*/
|
|
70
96
|
setWeekday(weekday: number | string, past?: boolean, locale?: string): bbnDt<any>;
|
|
97
|
+
diff(date: any, unit?: string, abs?: boolean): number;
|
|
98
|
+
guessUnit(valueInMs: number): string | null;
|
|
99
|
+
fromNow(unit?: string): string;
|
|
100
|
+
fromDate(date: any, unit?: string): string;
|
|
101
|
+
startOf(unit?: string): bbnDt<any>;
|
|
102
|
+
endOf(unit?: string): bbnDt<any>;
|
|
71
103
|
}
|
|
72
104
|
export default bbnDt;
|
package/dist/dt/classes/dt.js
CHANGED
|
@@ -11,10 +11,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
11
11
|
};
|
|
12
12
|
var _bbnDt_value;
|
|
13
13
|
import { Temporal } from 'temporal-polyfill';
|
|
14
|
-
import substr from '../../fn/string/substr.js';
|
|
15
14
|
import { getWeekdayIndex, getWeekday } from '../functions/getWeekday.js';
|
|
16
|
-
import { unitsCorrespondence, formatsMap } from '../vars/units.js';
|
|
15
|
+
import { unitsCorrespondence, units, formatsMap } from '../vars/units.js';
|
|
16
|
+
import _ from '../../_.js';
|
|
17
|
+
import substr from '../../fn/string/substr.js';
|
|
17
18
|
import each from '../../fn/loop/each.js';
|
|
19
|
+
import getRow from '../../fn/object/getRow.js';
|
|
18
20
|
import isPrimitive from '../../fn/type/isPrimitive.js';
|
|
19
21
|
import bbnDtDuration from './duration.js';
|
|
20
22
|
import camelToCss from '../../fn/string/camelToCss.js';
|
|
@@ -27,6 +29,98 @@ export class bbnDt {
|
|
|
27
29
|
return __classPrivateFieldGet(this, _bbnDt_value, "f");
|
|
28
30
|
}
|
|
29
31
|
;
|
|
32
|
+
/**
|
|
33
|
+
* Convert this.value (PlainDate, PlainTime, PlainDateTime, YearMonth,
|
|
34
|
+
* MonthDay, ZonedDateTime) into epoch milliseconds, using the system
|
|
35
|
+
* time zone when needed.
|
|
36
|
+
*
|
|
37
|
+
* Conventions:
|
|
38
|
+
* - time → today at that time in system tz
|
|
39
|
+
* - date → that date at 00:00 in system tz
|
|
40
|
+
* - year-month → first of that month at 00:00 in system tz
|
|
41
|
+
* - month-day → that month/day in *this year* at 00:00 in system tz
|
|
42
|
+
*/
|
|
43
|
+
toEpochMs() {
|
|
44
|
+
const tz = bbnDt.systemTimeZoneId;
|
|
45
|
+
switch (this.kind) {
|
|
46
|
+
case 'zoned': {
|
|
47
|
+
const v = this.value;
|
|
48
|
+
return v.toInstant().epochMilliseconds;
|
|
49
|
+
}
|
|
50
|
+
case 'datetime': {
|
|
51
|
+
const v = this.value;
|
|
52
|
+
// RFC 9557 string: "YYYY-MM-DDTHH:mm:ss[Europe/Rome]"
|
|
53
|
+
const iso = `${v.toString()}[${tz}]`;
|
|
54
|
+
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
55
|
+
return zdt.toInstant().epochMilliseconds;
|
|
56
|
+
}
|
|
57
|
+
case 'date': {
|
|
58
|
+
const d = this.value;
|
|
59
|
+
// "YYYY-MM-DDT00:00[Europe/Rome]"
|
|
60
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
61
|
+
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
62
|
+
return zdt.toInstant().epochMilliseconds;
|
|
63
|
+
}
|
|
64
|
+
case 'time': {
|
|
65
|
+
const t = this.value;
|
|
66
|
+
const today = Temporal.Now.plainDateISO();
|
|
67
|
+
// "YYYY-MM-DDTHH:mm[:ss][Europe/Rome]"
|
|
68
|
+
const iso = `${today.toString()}T${t.toString()}[${tz}]`;
|
|
69
|
+
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
70
|
+
return zdt.toInstant().epochMilliseconds;
|
|
71
|
+
}
|
|
72
|
+
case 'year-month': {
|
|
73
|
+
const ym = this.value;
|
|
74
|
+
const d = ym.toPlainDate({ day: 1 }); // first day of month
|
|
75
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
76
|
+
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
77
|
+
return zdt.toInstant().epochMilliseconds;
|
|
78
|
+
}
|
|
79
|
+
case 'month-day': {
|
|
80
|
+
const md = this.value;
|
|
81
|
+
const today = Temporal.Now.plainDateISO();
|
|
82
|
+
const d = md.toPlainDate({ year: today.year }); // current year
|
|
83
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
84
|
+
const zdt = Temporal.ZonedDateTime.from(iso);
|
|
85
|
+
return zdt.toInstant().epochMilliseconds;
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`Unsupported kind '${this.kind}' in toEpochMs`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* "Now" value in the same *kind* as this instance.
|
|
93
|
+
*/
|
|
94
|
+
static nowForKind(kind) {
|
|
95
|
+
switch (kind) {
|
|
96
|
+
case 'zoned':
|
|
97
|
+
return Temporal.Now.zonedDateTimeISO();
|
|
98
|
+
case 'datetime':
|
|
99
|
+
return Temporal.Now.plainDateTimeISO();
|
|
100
|
+
case 'date':
|
|
101
|
+
return Temporal.Now.plainDateISO();
|
|
102
|
+
case 'time':
|
|
103
|
+
return Temporal.Now.plainTimeISO();
|
|
104
|
+
case 'year-month': {
|
|
105
|
+
const d = Temporal.Now.plainDateISO();
|
|
106
|
+
return new Temporal.PlainYearMonth(d.year, d.month);
|
|
107
|
+
}
|
|
108
|
+
case 'month-day': {
|
|
109
|
+
const d = Temporal.Now.plainDateISO();
|
|
110
|
+
return new Temporal.PlainMonthDay(d.month, d.day, undefined, d.year);
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unsupported kind '${kind}' in nowForKind`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Helper to rebuild the same concrete subclass with a new Temporal value.
|
|
118
|
+
* Assumes your subclass constructor takes the value as first argument.
|
|
119
|
+
*/
|
|
120
|
+
withValue(newValue) {
|
|
121
|
+
const Ctor = this.constructor;
|
|
122
|
+
return new Ctor(newValue);
|
|
123
|
+
}
|
|
30
124
|
static compare(a, b, unit) {
|
|
31
125
|
if (!a || !b) {
|
|
32
126
|
throw new TypeError('Both arguments must be Temporal values');
|
|
@@ -115,9 +209,15 @@ export class bbnDt {
|
|
|
115
209
|
isBefore(other) {
|
|
116
210
|
return this.compare(other) < 0;
|
|
117
211
|
}
|
|
212
|
+
isBeforeOrSame(other) {
|
|
213
|
+
return this.compare(other) <= 0;
|
|
214
|
+
}
|
|
118
215
|
isAfter(other) {
|
|
119
216
|
return this.compare(other) > 0;
|
|
120
217
|
}
|
|
218
|
+
isAfterOrSame(other) {
|
|
219
|
+
return this.compare(other) >= 0;
|
|
220
|
+
}
|
|
121
221
|
isSame(other) {
|
|
122
222
|
return this.compare(other) === 0;
|
|
123
223
|
}
|
|
@@ -465,6 +565,269 @@ export class bbnDt {
|
|
|
465
565
|
}
|
|
466
566
|
return this.add(diff, 'd');
|
|
467
567
|
}
|
|
568
|
+
diff(date, unit = '', abs = false) {
|
|
569
|
+
let targetMs;
|
|
570
|
+
if (date instanceof bbnDt) {
|
|
571
|
+
targetMs = date.toEpochMs();
|
|
572
|
+
}
|
|
573
|
+
else if (date instanceof Temporal.ZonedDateTime ||
|
|
574
|
+
date instanceof Temporal.PlainDateTime ||
|
|
575
|
+
date instanceof Temporal.PlainDate ||
|
|
576
|
+
date instanceof Temporal.PlainTime ||
|
|
577
|
+
date instanceof Temporal.PlainYearMonth ||
|
|
578
|
+
date instanceof Temporal.PlainMonthDay) {
|
|
579
|
+
// Wrap it in a temporary bbnDt-like shim to reuse toEpochMs logic;
|
|
580
|
+
// or write a small standalone helper similar to toEpochMs(kind, value).
|
|
581
|
+
const temp = { kind: this.kind, value: date };
|
|
582
|
+
targetMs = temp.toEpochMs();
|
|
583
|
+
}
|
|
584
|
+
else if (typeof date === 'string' || typeof date === 'number') {
|
|
585
|
+
// Reuse your parse API: parse into same kind as `this`
|
|
586
|
+
const parsed = this.parse(String(date), ''); // format depends on your API
|
|
587
|
+
targetMs = parsed.toEpochMs();
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
throw new TypeError('Unsupported date argument for diff');
|
|
591
|
+
}
|
|
592
|
+
const nowMs = this.toEpochMs();
|
|
593
|
+
let diff = nowMs - targetMs;
|
|
594
|
+
if (abs) {
|
|
595
|
+
diff = Math.abs(diff);
|
|
596
|
+
}
|
|
597
|
+
if (!unit) {
|
|
598
|
+
return diff;
|
|
599
|
+
}
|
|
600
|
+
const realUnit = unitsCorrespondence[unit] || unit;
|
|
601
|
+
const match = getRow(units, d => d[0] === realUnit);
|
|
602
|
+
if (!match) {
|
|
603
|
+
throw new Error('Invalid unit for diff: ' + unit);
|
|
604
|
+
}
|
|
605
|
+
const [, , ms] = match; // [shortUnit, rtfUnit, ms]
|
|
606
|
+
return Math.round(diff / ms);
|
|
607
|
+
}
|
|
608
|
+
guessUnit(valueInMs) {
|
|
609
|
+
const absDiff = Math.abs(valueInMs);
|
|
610
|
+
for (const [shortUnit, rtfUnit, ms] of units) {
|
|
611
|
+
if ((absDiff >= ms) || (rtfUnit === 'second')) {
|
|
612
|
+
return shortUnit;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
fromNow(unit = '') {
|
|
618
|
+
const nowValue = bbnDt.nowForKind(this.kind);
|
|
619
|
+
const temp = { kind: this.kind, value: nowValue };
|
|
620
|
+
const rawDiffMs = this.diff(temp);
|
|
621
|
+
const chosenUnit = unitsCorrespondence[unit] || this.guessUnit(rawDiffMs);
|
|
622
|
+
if (!chosenUnit) {
|
|
623
|
+
throw new Error('Cannot guess unit for fromNow');
|
|
624
|
+
}
|
|
625
|
+
const diff = this.diff(temp, chosenUnit);
|
|
626
|
+
const rtf = new Intl.RelativeTimeFormat([bbn.env.lang, ...navigator.languages], { numeric: 'auto' });
|
|
627
|
+
const match = getRow(units, d => d[0] === chosenUnit);
|
|
628
|
+
if (!match) {
|
|
629
|
+
throw new Error('Invalid unit for fromNow: ' + unit);
|
|
630
|
+
}
|
|
631
|
+
const [, rtfUnit] = match; // [shortUnit, rtfUnit, ms]
|
|
632
|
+
return rtf.format(diff, rtfUnit);
|
|
633
|
+
}
|
|
634
|
+
fromDate(date, unit = '') {
|
|
635
|
+
const rawDiffMs = this.diff(date);
|
|
636
|
+
const chosenUnit = unitsCorrespondence[unit] || this.guessUnit(rawDiffMs);
|
|
637
|
+
if (!chosenUnit) {
|
|
638
|
+
throw new Error('Cannot guess unit for fromDate');
|
|
639
|
+
}
|
|
640
|
+
const diff = this.diff(date, chosenUnit);
|
|
641
|
+
const u = chosenUnit; // text unit, you may want a label here
|
|
642
|
+
return diff > 0
|
|
643
|
+
? _('%d %s before', diff, u)
|
|
644
|
+
: diff < 0
|
|
645
|
+
? _('%d %s after', -diff, u)
|
|
646
|
+
: _('The same %s', u);
|
|
647
|
+
}
|
|
648
|
+
startOf(unit = 'd') {
|
|
649
|
+
var _a, _b;
|
|
650
|
+
const u = unitsCorrespondence[unit] || unit;
|
|
651
|
+
if (!u) {
|
|
652
|
+
throw new Error('Invalid unit for startOf: ' + unit);
|
|
653
|
+
}
|
|
654
|
+
let v = this.value;
|
|
655
|
+
const zeroTime = (obj) => obj.with({
|
|
656
|
+
hour: 0, minute: 0, second: 0,
|
|
657
|
+
millisecond: 0, microsecond: 0, nanosecond: 0,
|
|
658
|
+
});
|
|
659
|
+
switch (u) {
|
|
660
|
+
case 'y':
|
|
661
|
+
if (!('year' in v)) {
|
|
662
|
+
throw new Error('startOf("y") only valid for year-based types');
|
|
663
|
+
}
|
|
664
|
+
v = zeroTime(v.with({ month: 1, day: 1 }));
|
|
665
|
+
break;
|
|
666
|
+
case 'm':
|
|
667
|
+
if (!('month' in v)) {
|
|
668
|
+
throw new Error('startOf("m") only valid for month-based types');
|
|
669
|
+
}
|
|
670
|
+
v = zeroTime(v.with({ day: 1 }));
|
|
671
|
+
break;
|
|
672
|
+
case 'w': {
|
|
673
|
+
// ISO dayOfWeek: 1 (Mon) .. 7 (Sun)
|
|
674
|
+
const d = ('toPlainDate' in v) ? v.toPlainDate() : v;
|
|
675
|
+
const dow = d.dayOfWeek; // 1..7
|
|
676
|
+
const diffToMonday = dow - 1; // 0 for Monday
|
|
677
|
+
const newDate = d.subtract({ days: diffToMonday });
|
|
678
|
+
if ('toPlainDateTime' in v) {
|
|
679
|
+
v = zeroTime(newDate.toPlainDateTime((_b = (_a = v.toPlainTime) === null || _a === void 0 ? void 0 : _a.call(v)) !== null && _b !== void 0 ? _b : Temporal.PlainTime.from('00:00')));
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
v = newDate; // PlainDate case
|
|
683
|
+
}
|
|
684
|
+
break;
|
|
685
|
+
}
|
|
686
|
+
case 'd':
|
|
687
|
+
v = zeroTime(v);
|
|
688
|
+
break;
|
|
689
|
+
case 'h':
|
|
690
|
+
v = v.with({ minute: 0, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 });
|
|
691
|
+
break;
|
|
692
|
+
case 'i':
|
|
693
|
+
v = v.with({ second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 });
|
|
694
|
+
break;
|
|
695
|
+
case 's':
|
|
696
|
+
v = v.with({ millisecond: 0, microsecond: 0, nanosecond: 0 });
|
|
697
|
+
break;
|
|
698
|
+
default:
|
|
699
|
+
throw new Error('Invalid unit for startOf: ' + unit);
|
|
700
|
+
}
|
|
701
|
+
return this.withValue(v);
|
|
702
|
+
}
|
|
703
|
+
endOf(unit = "d") {
|
|
704
|
+
const tz = Temporal.Now.timeZoneId();
|
|
705
|
+
const u = unitsCorrespondence[unit] || unit;
|
|
706
|
+
// 1. Convert current value to a ZonedDateTime (using your conventions)
|
|
707
|
+
const toZdt = (v) => {
|
|
708
|
+
switch (this.kind) {
|
|
709
|
+
case "zoned":
|
|
710
|
+
return this.value;
|
|
711
|
+
case "datetime": {
|
|
712
|
+
const pdt = this.value;
|
|
713
|
+
const iso = `${pdt.toString()}[${tz}]`;
|
|
714
|
+
return Temporal.ZonedDateTime.from(iso);
|
|
715
|
+
}
|
|
716
|
+
case "date": {
|
|
717
|
+
const d = this.value;
|
|
718
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
719
|
+
return Temporal.ZonedDateTime.from(iso);
|
|
720
|
+
}
|
|
721
|
+
case "time": {
|
|
722
|
+
const t = this.value;
|
|
723
|
+
const today = Temporal.Now.plainDateISO();
|
|
724
|
+
const iso = `${today.toString()}T${t.toString()}[${tz}]`;
|
|
725
|
+
return Temporal.ZonedDateTime.from(iso);
|
|
726
|
+
}
|
|
727
|
+
case "year-month": {
|
|
728
|
+
const ym = this.value;
|
|
729
|
+
const d = ym.toPlainDate({ day: 1 });
|
|
730
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
731
|
+
return Temporal.ZonedDateTime.from(iso);
|
|
732
|
+
}
|
|
733
|
+
case "month-day": {
|
|
734
|
+
const md = this.value;
|
|
735
|
+
const today = Temporal.Now.plainDateISO();
|
|
736
|
+
const d = md.toPlainDate({ year: today.year });
|
|
737
|
+
const iso = `${d.toString()}T00:00[${tz}]`;
|
|
738
|
+
return Temporal.ZonedDateTime.from(iso);
|
|
739
|
+
}
|
|
740
|
+
default:
|
|
741
|
+
throw new Error("Unsupported kind in endOf");
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
let zdt = toZdt(this.value);
|
|
745
|
+
// 2. compute start of next unit
|
|
746
|
+
let next;
|
|
747
|
+
switch (u) {
|
|
748
|
+
case "y": {
|
|
749
|
+
next = zdt.with({ month: 1, day: 1, hour: 0, minute: 0, second: 0,
|
|
750
|
+
millisecond: 0, microsecond: 0, nanosecond: 0 })
|
|
751
|
+
.add({ years: 1 });
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
case "m": {
|
|
755
|
+
next = zdt.with({ day: 1, hour: 0, minute: 0, second: 0,
|
|
756
|
+
millisecond: 0, microsecond: 0, nanosecond: 0 })
|
|
757
|
+
.add({ months: 1 });
|
|
758
|
+
break;
|
|
759
|
+
}
|
|
760
|
+
case "w": {
|
|
761
|
+
// ISO week: Monday = 1, Sunday = 7
|
|
762
|
+
const dow = zdt.toPlainDate().dayOfWeek;
|
|
763
|
+
const diffToMonday = -(dow - 1);
|
|
764
|
+
const weekStart = zdt.add({ days: diffToMonday }).with({
|
|
765
|
+
hour: 0, minute: 0, second: 0,
|
|
766
|
+
millisecond: 0, microsecond: 0, nanosecond: 0
|
|
767
|
+
});
|
|
768
|
+
next = weekStart.add({ weeks: 1 });
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
case "d": {
|
|
772
|
+
next = zdt
|
|
773
|
+
.with({
|
|
774
|
+
hour: 0, minute: 0, second: 0,
|
|
775
|
+
millisecond: 0, microsecond: 0, nanosecond: 0
|
|
776
|
+
})
|
|
777
|
+
.add({ days: 1 });
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
case "h": {
|
|
781
|
+
next = zdt.with({
|
|
782
|
+
minute: 0, second: 0,
|
|
783
|
+
millisecond: 0, microsecond: 0, nanosecond: 0
|
|
784
|
+
}).add({ hours: 1 });
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
case "i": // minute
|
|
788
|
+
case "n": // minute alternative?
|
|
789
|
+
case "min": {
|
|
790
|
+
next = zdt.with({
|
|
791
|
+
second: 0,
|
|
792
|
+
millisecond: 0, microsecond: 0, nanosecond: 0
|
|
793
|
+
}).add({ minutes: 1 });
|
|
794
|
+
break;
|
|
795
|
+
}
|
|
796
|
+
case "s": {
|
|
797
|
+
next = zdt.with({
|
|
798
|
+
millisecond: 0, microsecond: 0, nanosecond: 0
|
|
799
|
+
}).add({ seconds: 1 });
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
default:
|
|
803
|
+
throw new Error("Invalid unit for endOf: " + unit);
|
|
804
|
+
}
|
|
805
|
+
// 3. endOf = startOfNext - 1 millisecond
|
|
806
|
+
const end = (next.subtract({ milliseconds: 1 }));
|
|
807
|
+
// 4. Convert back to original kind
|
|
808
|
+
switch (this.kind) {
|
|
809
|
+
case "zoned":
|
|
810
|
+
return this.withValue(end);
|
|
811
|
+
case "datetime":
|
|
812
|
+
return this.withValue(end.toPlainDateTime());
|
|
813
|
+
case "date":
|
|
814
|
+
return this.withValue(end.toPlainDate());
|
|
815
|
+
case "time":
|
|
816
|
+
return this.withValue(end.toPlainTime());
|
|
817
|
+
case "year-month": {
|
|
818
|
+
const p = end.toPlainDate();
|
|
819
|
+
return this.withValue(new Temporal.PlainYearMonth(p.year, p.month));
|
|
820
|
+
}
|
|
821
|
+
case "month-day": {
|
|
822
|
+
const p = end.toPlainDate();
|
|
823
|
+
return this.withValue(new Temporal.PlainMonthDay(p.month, p.day));
|
|
824
|
+
}
|
|
825
|
+
default:
|
|
826
|
+
throw new Error("Unsupported kind in endOf");
|
|
827
|
+
}
|
|
828
|
+
}
|
|
468
829
|
}
|
|
469
830
|
_bbnDt_value = new WeakMap();
|
|
831
|
+
/** System time zone ID (e.g. "Europe/Rome") */
|
|
832
|
+
bbnDt.systemTimeZoneId = Temporal.Now.timeZoneId();
|
|
470
833
|
export default bbnDt;
|