@bbn/bbn 2.0.106 → 2.0.108

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.
@@ -41,7 +41,7 @@ export default class bbnDtDate extends bbnDt {
41
41
  if (!format) {
42
42
  format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric' }).pattern;
43
43
  }
44
- return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
44
+ return bbnDt.prototype.format.call(this, this.value, format);
45
45
  }
46
46
  ftime(withSeconds = false) {
47
47
  return '00:00' + (withSeconds ? ':00' : '');
@@ -37,7 +37,7 @@ export default class bbnDtDateTime extends bbnDt {
37
37
  if (!format) {
38
38
  format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit', second: undefined }).pattern;
39
39
  }
40
- return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
40
+ return bbnDt.prototype.format.call(this, this.value, format);
41
41
  }
42
42
  fdate(long = false, withTime = false, weekday = false) {
43
43
  if (!this.value) {
@@ -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");
@@ -42,7 +42,7 @@ export default class bbnDtYearMonth extends bbnDt {
42
42
  && (d.month === 'numeric')
43
43
  && !('day' in d)).pattern;
44
44
  }
45
- return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
45
+ return bbnDt.prototype.format.call(this, this.value, format);
46
46
  }
47
47
  fdate(long = false, withTime = false, weekday = false) {
48
48
  if (!this.value) {
@@ -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
- input = new bbnDtDateTime(1970, 1, 1, 0, 0, 0, 0).format(fmt);
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
- return new bbnDtZoned(zdt);
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
- return new bbnDtDateTime(d);
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
- return new bbnDtDate(d);
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
- return new bbnDtYearMonth(d);
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
- return new bbnDtMonthDay(d);
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
- return new bbnDtTime(d);
622
+ dtObj = new bbnDtTime(d);
623
+ }
624
+ else {
625
+ throw new Error('No date or time information found in input');
615
626
  }
616
- throw new Error('No date or time information found in input');
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
@@ -179,7 +179,7 @@ const dt = (value, inputFormat = null, cls = 'auto') => {
179
179
  if (inputFormat) {
180
180
  let parsed;
181
181
  try {
182
- parsed = parse(value, inputFormat, cls);
182
+ parsed = parse(value, inputFormat, cls, true);
183
183
  return parsed;
184
184
  }
185
185
  catch (e) { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.106",
3
+ "version": "2.0.108",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",