@bbn/bbn 2.0.106 → 2.0.107
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/duration.d.ts +1 -0
- package/dist/dt/classes/duration.js +12 -0
- package/dist/dt/functions/parse.js +29 -17
- package/dist/dt.js +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ export default class bbnDtDuration {
|
|
|
3
3
|
#private;
|
|
4
4
|
static fromUnit(value: number, unit: string): bbnDtDuration;
|
|
5
5
|
constructor(y: Temporal.Duration | number | object, m?: number, w?: number, d?: number, h?: number, i?: number, s?: number, ms?: number, unit?: string);
|
|
6
|
+
setValid(isValid: boolean): void;
|
|
6
7
|
get value(): Temporal.Duration;
|
|
7
8
|
years(remaining?: boolean): number;
|
|
8
9
|
months(remaining?: boolean): number;
|
|
@@ -52,6 +52,18 @@ class bbnDtDuration {
|
|
|
52
52
|
if (!row) {
|
|
53
53
|
//throw new Error('Invalid unit for duration: ' + realUnit);
|
|
54
54
|
}
|
|
55
|
+
Object.defineProperty(this, 'isValid', {
|
|
56
|
+
value: false,
|
|
57
|
+
writable: false,
|
|
58
|
+
configurable: true
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
setValid(isValid) {
|
|
62
|
+
Object.defineProperty(this, 'isValid', {
|
|
63
|
+
value: isValid,
|
|
64
|
+
writable: false,
|
|
65
|
+
configurable: false
|
|
66
|
+
});
|
|
55
67
|
}
|
|
56
68
|
get value() {
|
|
57
69
|
return __classPrivateFieldGet(this, _bbnDtDuration_value, "f");
|
|
@@ -21,6 +21,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
21
21
|
throw new Error('Temporal API is required (load @js-temporal/polyfill)');
|
|
22
22
|
}
|
|
23
23
|
const T = TemporalAny;
|
|
24
|
+
let isValid = true;
|
|
24
25
|
if (!locale) {
|
|
25
26
|
locale = ((_a = bbn === null || bbn === void 0 ? void 0 : bbn.dt) === null || _a === void 0 ? void 0 : _a.locales) || {};
|
|
26
27
|
}
|
|
@@ -530,7 +531,9 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
530
531
|
let match = fullRegex.exec(input);
|
|
531
532
|
if (!match) {
|
|
532
533
|
if (force) {
|
|
533
|
-
|
|
534
|
+
const inputDate = new bbnDtDateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
535
|
+
input = inputDate.format(fmt);
|
|
536
|
+
isValid = false;
|
|
534
537
|
match = fullRegex.exec(input);
|
|
535
538
|
}
|
|
536
539
|
else {
|
|
@@ -568,6 +571,7 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
568
571
|
const hasMonthDayOnly = !ctx.hasYear && ctx.hasMonth && ctx.hasDay;
|
|
569
572
|
const hasTime = ctx.hasHour || ctx.hasMinute || ctx.hasSecond || ctx.hasMs;
|
|
570
573
|
const hasZone = ctx.timeZone != null || ctx.offsetMinutes != null;
|
|
574
|
+
let dtObj;
|
|
571
575
|
// ---------- 1) If timezone (Z or z) → Zoned ----------
|
|
572
576
|
if (isClsZoned || (hasZone && isClsAuto)) {
|
|
573
577
|
let pdt;
|
|
@@ -580,40 +584,48 @@ export default function parse(input, format, cls = 'auto', force, locale) {
|
|
|
580
584
|
if (ctx.timeZone) {
|
|
581
585
|
const tz = T.TimeZone.from(ctx.timeZone);
|
|
582
586
|
const zdt = pdt.toZonedDateTime(tz);
|
|
583
|
-
|
|
587
|
+
dtObj = new bbnDtZoned(zdt);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
const utcMs = Date.UTC(ctx.year, ctx.month - 1, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms);
|
|
591
|
+
const epochMs = utcMs - ((_a = ctx.offsetMinutes) !== null && _a !== void 0 ? _a : 0) * 60000;
|
|
592
|
+
dtObj = new bbnDtZoned(T.Instant.fromEpochMilliseconds(epochMs).toZonedDateTimeISO(T.Now.timeZoneId()));
|
|
584
593
|
}
|
|
585
|
-
const utcMs = Date.UTC(ctx.year, ctx.month - 1, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms);
|
|
586
|
-
const epochMs = utcMs - ((_a = ctx.offsetMinutes) !== null && _a !== void 0 ? _a : 0) * 60000;
|
|
587
|
-
return new bbnDtZoned(T.Instant.fromEpochMilliseconds(epochMs).toZonedDateTimeISO(T.Now.timeZoneId()));
|
|
588
594
|
}
|
|
589
595
|
// ---------- 2) No timezone: decide which Plain* type ----------
|
|
590
|
-
if (isClsDateTime || (isClsAuto && hasDate && hasTime)) {
|
|
596
|
+
else if (isClsDateTime || (isClsAuto && hasDate && hasTime)) {
|
|
591
597
|
if (!hasFullDate) {
|
|
592
598
|
throw new Error('PlainDateTime requires year, month and day');
|
|
593
599
|
}
|
|
594
600
|
const d = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
|
|
595
|
-
|
|
601
|
+
dtObj = new bbnDtDateTime(d);
|
|
596
602
|
}
|
|
597
|
-
if (isClsDate || isClsYearMonth || isClsMonthDay || (isClsAuto && hasDate && !hasTime)) {
|
|
603
|
+
else if (isClsDate || isClsYearMonth || isClsMonthDay || (isClsAuto && hasDate && !hasTime)) {
|
|
598
604
|
if (isClsDate || (hasFullDate && isClsAuto)) {
|
|
599
605
|
const d = new T.PlainDate(ctx.year, ctx.month, ctx.day);
|
|
600
|
-
|
|
606
|
+
dtObj = new bbnDtDate(d);
|
|
601
607
|
}
|
|
602
|
-
if (isClsYearMonth || (hasYearMonthOnly && isClsAuto)) {
|
|
608
|
+
else if (isClsYearMonth || (hasYearMonthOnly && isClsAuto)) {
|
|
603
609
|
const d = new T.PlainYearMonth(ctx.year, ctx.month);
|
|
604
|
-
|
|
610
|
+
dtObj = new bbnDtYearMonth(d);
|
|
605
611
|
}
|
|
606
|
-
if (isClsMonthDay || (hasMonthDayOnly && isClsAuto)) {
|
|
612
|
+
else if (isClsMonthDay || (hasMonthDayOnly && isClsAuto)) {
|
|
607
613
|
const d = new T.PlainMonthDay(ctx.month, ctx.day, 1972);
|
|
608
|
-
|
|
614
|
+
dtObj = new bbnDtMonthDay(d);
|
|
615
|
+
}
|
|
616
|
+
else {
|
|
617
|
+
throw new Error('Not enough date components for a known Temporal type');
|
|
609
618
|
}
|
|
610
|
-
throw new Error('Not enough date components for a known Temporal type');
|
|
611
619
|
}
|
|
612
|
-
if (isClsTime || (isClsAuto && !hasDate && hasTime)) {
|
|
620
|
+
else if (isClsTime || (isClsAuto && !hasDate && hasTime)) {
|
|
613
621
|
const d = new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
|
|
614
|
-
|
|
622
|
+
dtObj = new bbnDtTime(d);
|
|
623
|
+
}
|
|
624
|
+
else {
|
|
625
|
+
throw new Error('No date or time information found in input');
|
|
615
626
|
}
|
|
616
|
-
|
|
627
|
+
dtObj.setValid(isValid);
|
|
628
|
+
return dtObj;
|
|
617
629
|
}
|
|
618
630
|
if (Array.isArray(format)) {
|
|
619
631
|
let lastError = null;
|
package/dist/dt.js
CHANGED