@bbn/bbn 2.0.224 → 2.0.226

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/db.d.ts CHANGED
@@ -5,7 +5,7 @@ interface DbIndexDefinition {
5
5
  interface DbStructure {
6
6
  keys: Record<string, DbIndexDefinition>;
7
7
  fields: Record<string, Record<string, unknown>>;
8
- num?: number;
8
+ version?: number;
9
9
  }
10
10
  interface DbStructures {
11
11
  [database: string]: {
@@ -6,7 +6,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
6
6
  abstract readonly kind: bbnDtKind;
7
7
  readonly __bbnNoData = true;
8
8
  readonly __isBbnDt = true;
9
- isValid: boolean;
9
+ isValid: boolean | undefined;
10
10
  defaultValue: TimeProperties | undefined;
11
11
  constructor(value?: TValue);
12
12
  setValid(isValid: boolean): void;
@@ -44,8 +44,8 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
44
44
  }): bbnDt<any>;
45
45
  parse(input: string, format: string, cls?: bbnDtKindParams): bbnDt<any>;
46
46
  compare(other: any, unit?: string): -1 | 0 | 1;
47
- add(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
48
- subtract(amount: number | bbnDtDuration | object, unit?: string): bbnDt<any>;
47
+ add(amount: number | bbnDtDuration | object, unit?: string): undefined | bbnDt<any>;
48
+ subtract(amount: number | bbnDtDuration | object, unit?: string): undefined | bbnDt<any>;
49
49
  duration(amount: number, unit: string): bbnDtDuration;
50
50
  isBefore(other: any, unit?: string): boolean;
51
51
  isBeforeOrSame(other: any, unit?: string): boolean;
@@ -56,44 +56,44 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
56
56
  toJSON(): string;
57
57
  timezone(d: any): string | bbnDt<any>;
58
58
  toString(): string;
59
- year(v?: any): number | bbnDt<any>;
60
- month(v?: any): number | bbnDt<any>;
61
- day(v?: any): number | bbnDt<any>;
62
- hour(v?: any): number | bbnDt<any>;
63
- minute(v?: any): number | bbnDt<any>;
64
- second(v?: any): number | bbnDt<any>;
65
- millisecond(v?: any): number | bbnDt<any>;
66
- weekday(v?: any, past?: any): number | bbnDt<any>;
67
- date(v?: any): string | bbnDt<any>;
59
+ year(v?: any): undefined | number | bbnDt<any>;
60
+ month(v?: any): undefined | number | bbnDt<any>;
61
+ day(v?: any): undefined | number | bbnDt<any>;
62
+ hour(v?: any): undefined | number | bbnDt<any>;
63
+ minute(v?: any): undefined | number | bbnDt<any>;
64
+ second(v?: any): undefined | number | bbnDt<any>;
65
+ millisecond(v?: any): undefined | number | bbnDt<any>;
66
+ weekday(v?: any, past?: any): undefined | number | bbnDt<any>;
67
+ date(v?: any): undefined | string | bbnDt<any>;
68
68
  datetime(v?: any): string | bbnDt<any>;
69
69
  time(v?: any): string | bbnDt<any>;
70
70
  fdate(long?: boolean, withTime?: boolean): string;
71
71
  ftime(withSeconds?: boolean): string;
72
- week(): number;
73
- get YYYY(): string;
74
- get YY(): string;
75
- get MMMM(): string;
76
- get MMM(): string;
77
- get MM(): string;
78
- get M(): string;
79
- get EE(): string;
80
- get DD(): string;
81
- get d(): string;
82
- get dddd(): string;
83
- get ddd(): string;
84
- get D(): string;
85
- get HH(): string;
86
- get H(): string;
87
- get II(): string;
88
- get mm(): string;
89
- get I(): string;
90
- get SS(): string;
91
- get SSS(): string;
92
- get S(): string;
93
- get WW(): string;
94
- get W(): string;
95
- get Z(): string;
96
- get ZZ(): string;
72
+ week(): undefined | number;
73
+ get YYYY(): undefined | string;
74
+ get YY(): undefined | string;
75
+ get MMMM(): undefined | string;
76
+ get MMM(): undefined | string;
77
+ get MM(): undefined | string;
78
+ get M(): undefined | string;
79
+ get EE(): undefined | string;
80
+ get DD(): undefined | string;
81
+ get d(): undefined | string;
82
+ get dddd(): undefined | string;
83
+ get ddd(): undefined | string;
84
+ get D(): undefined | string;
85
+ get HH(): undefined | string;
86
+ get H(): undefined | string;
87
+ get II(): undefined | string;
88
+ get mm(): undefined | string;
89
+ get I(): undefined | string;
90
+ get SS(): undefined | string;
91
+ get SSS(): undefined | string;
92
+ get S(): undefined | string;
93
+ get WW(): undefined | string;
94
+ get W(): undefined | string;
95
+ get Z(): undefined | string;
96
+ get ZZ(): undefined | string;
97
97
  unix(ms?: boolean | number): number | bbnDt<any>;
98
98
  format(format?: string): string;
99
99
  calendar(short?: boolean): string;
@@ -109,7 +109,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
109
109
  * @param {boolean} past - If true → return previous occurrence instead of next.
110
110
  * @param {string} [locale] - Optional locale for weekday names.
111
111
  */
112
- setWeekday(weekday: number | string, past?: boolean, locale?: string): bbnDt<any>;
112
+ setWeekday(weekday: number | string, past?: boolean, locale?: string): undefined | bbnDt<any>;
113
113
  diff(date: any, unit?: string, abs?: boolean): number;
114
114
  guessUnit(valueInMs: number): string | null;
115
115
  fromNow(unit?: string): string;
@@ -77,7 +77,7 @@ export class bbnDt {
77
77
  return __classPrivateFieldGet(this, _bbnDt_value, "f");
78
78
  }
79
79
  get hasFullDate() {
80
- return ('year' in this.value) && ('month' in this.value) && ('day' in this.value);
80
+ return !!this.value && ('year' in this.value) && ('month' in this.value) && ('day' in this.value);
81
81
  }
82
82
  /**
83
83
  * Convert this.value (PlainDate, PlainTime, PlainDateTime, YearMonth,
@@ -181,7 +181,7 @@ export class bbnDt {
181
181
  throw new TypeError('Both arguments must be Temporal values');
182
182
  }
183
183
  const tz = Temporal.Now.timeZoneId();
184
- let realUnit = unitsCorrespondence[unit] ? getRow(units, d => d[0] === unitsCorrespondence[unit])[1] : undefined;
184
+ let realUnit = unit && unitsCorrespondence[unit] ? getRow(units, (d) => d[0] === unitsCorrespondence[unit])[1] : undefined;
185
185
  realUnit = realUnit ? realUnit + 's' : undefined;
186
186
  const isBbnDt = (x) => x instanceof bbnDt;
187
187
  // --- helper: get underlying Temporal value if wrapper ---
@@ -353,7 +353,7 @@ export class bbnDt {
353
353
  }
354
354
  // ---- Serialization ----
355
355
  toJSON() {
356
- if ('toZonedDateTime' in __classPrivateFieldGet(this, _bbnDt_value, "f")) {
356
+ if (__classPrivateFieldGet(this, _bbnDt_value, "f") && 'toZonedDateTime' in __classPrivateFieldGet(this, _bbnDt_value, "f")) {
357
357
  const zdt = __classPrivateFieldGet(this, _bbnDt_value, "f").toZonedDateTime(bbnDt.systemTimeZoneId);
358
358
  const zdt2 = zdt.withTimeZone('UTC');
359
359
  return bbn.dt(zdt2).format('YYYY-MM-DDTHH:II:SS.SSS') + 'Z';
@@ -403,7 +403,7 @@ export class bbnDt {
403
403
  if (!('year' in this.value)) {
404
404
  throw new Error('year() is not supported for this type');
405
405
  }
406
- if ((v !== undefined) && !(v instanceof Event)) {
406
+ if ((v !== undefined) && !(v instanceof Event) && (typeof v === 'number')) {
407
407
  const d = this.value.with({ year: v });
408
408
  return new this.constructor(d);
409
409
  }
@@ -416,7 +416,7 @@ export class bbnDt {
416
416
  if (!('month' in this.value)) {
417
417
  throw new Error('month() is not supported for this type');
418
418
  }
419
- if ((v !== undefined) && !(v instanceof Event)) {
419
+ if ((v !== undefined) && !(v instanceof Event) && (typeof v === 'number')) {
420
420
  const d = this.value.with({ month: v });
421
421
  return new this.constructor(d);
422
422
  }
@@ -581,81 +581,81 @@ export class bbnDt {
581
581
  return 2 + Math.floor(remainingDays / 7);
582
582
  }
583
583
  get YYYY() {
584
- if ('year' in this.value) {
584
+ if (this.value && 'year' in this.value) {
585
585
  return this.year().toString();
586
586
  }
587
587
  return undefined;
588
588
  }
589
589
  get YY() {
590
- if ('year' in this.value) {
590
+ if (this.value && 'year' in this.value) {
591
591
  return substr(this.year().toString(), 2, 2);
592
592
  }
593
593
  return undefined;
594
594
  }
595
595
  get MMMM() {
596
- if ('month' in this.value) {
596
+ if (this.value && 'month' in this.value) {
597
597
  return bbn.dt.locales.monthsLong[this.month() - 1];
598
598
  }
599
599
  return undefined;
600
600
  }
601
601
  get MMM() {
602
- if ('month' in this.value) {
602
+ if (this.value && 'month' in this.value) {
603
603
  return bbn.dt.locales.monthsShort[this.month() - 1];
604
604
  }
605
605
  return undefined;
606
606
  }
607
607
  get MM() {
608
- if ('month' in this.value) {
608
+ if (this.value && 'month' in this.value) {
609
609
  const m = parseInt(this.month().toString());
610
610
  return m < 10 ? '0' + m.toString() : m.toString();
611
611
  }
612
612
  return undefined;
613
613
  }
614
614
  get M() {
615
- if ('month' in this.value) {
615
+ if (this.value && 'month' in this.value) {
616
616
  return this.month().toString();
617
617
  }
618
618
  return undefined;
619
619
  }
620
620
  get EE() {
621
- if ('dayOfWeek' in this.value) {
621
+ if (this.value && 'dayOfWeek' in this.value) {
622
622
  return this.value.dayOfWeek.toString();
623
623
  }
624
624
  return undefined;
625
625
  }
626
626
  get DD() {
627
- if ('day' in this.value) {
627
+ if (this.value && 'day' in this.value) {
628
628
  const d = parseInt(this.day().toString());
629
629
  return d < 10 ? '0' + d.toString() : d.toString();
630
630
  }
631
631
  return undefined;
632
632
  }
633
633
  get d() {
634
- if ('day' in this.value) {
634
+ if (this.value && 'day' in this.value) {
635
635
  return this.day().toString();
636
636
  }
637
637
  return undefined;
638
638
  }
639
639
  get dddd() {
640
- if ('dayOfWeek' in this.value) {
640
+ if (this.value && 'dayOfWeek' in this.value) {
641
641
  return this.getWeekday(this.value.dayOfWeek, 'long');
642
642
  }
643
643
  return undefined;
644
644
  }
645
645
  get ddd() {
646
- if ('dayOfWeek' in this.value) {
646
+ if (this.value && 'dayOfWeek' in this.value) {
647
647
  return this.getWeekday(this.value.dayOfWeek, 'short');
648
648
  }
649
649
  return undefined;
650
650
  }
651
651
  get D() {
652
- if ('day' in this.value) {
652
+ if (this.value && 'day' in this.value) {
653
653
  return this.day().toString();
654
654
  }
655
655
  return undefined;
656
656
  }
657
657
  get HH() {
658
- if ('hour' in this.value) {
658
+ if (this.value && 'hour' in this.value) {
659
659
  const h = parseInt(this.hour().toString());
660
660
  return h < 10 ? '0' + h.toString() : h.toString();
661
661
  }
@@ -665,7 +665,7 @@ export class bbnDt {
665
665
  return undefined;
666
666
  }
667
667
  get H() {
668
- if ('hour' in this.value) {
668
+ if (this.value && 'hour' in this.value) {
669
669
  return this.hour().toString();
670
670
  }
671
671
  else if (this.hasFullDate) {
@@ -674,7 +674,7 @@ export class bbnDt {
674
674
  return undefined;
675
675
  }
676
676
  get II() {
677
- if ('minute' in this.value) {
677
+ if (this.value && 'minute' in this.value) {
678
678
  const i = parseInt(this.minute().toString());
679
679
  return i < 10 ? '0' + i.toString() : i.toString();
680
680
  }
@@ -684,7 +684,7 @@ export class bbnDt {
684
684
  return undefined;
685
685
  }
686
686
  get mm() {
687
- if ('minute' in this.value) {
687
+ if (this.value && 'minute' in this.value) {
688
688
  const i = parseInt(this.minute().toString());
689
689
  return i < 10 ? '0' + i.toString() : i.toString();
690
690
  }
@@ -694,7 +694,7 @@ export class bbnDt {
694
694
  return undefined;
695
695
  }
696
696
  get I() {
697
- if ('minute' in this.value) {
697
+ if (this.value && 'minute' in this.value) {
698
698
  return this.minute().toString();
699
699
  }
700
700
  else if (this.hasFullDate) {
@@ -703,7 +703,7 @@ export class bbnDt {
703
703
  return undefined;
704
704
  }
705
705
  get SS() {
706
- if ('second' in this.value) {
706
+ if (this.value && 'second' in this.value) {
707
707
  const s = parseInt(this.second().toString());
708
708
  return s < 10 ? '0' + s.toString() : s.toString();
709
709
  }
@@ -713,7 +713,7 @@ export class bbnDt {
713
713
  return undefined;
714
714
  }
715
715
  get SSS() {
716
- if ('millisecond' in this.value) {
716
+ if (this.value && 'millisecond' in this.value) {
717
717
  const s = parseInt(this.millisecond().toString());
718
718
  return s < 10 ? '00' + s.toString() : (s < 100 ? '0' + s.toString() : s.toString());
719
719
  }
@@ -723,7 +723,7 @@ export class bbnDt {
723
723
  return undefined;
724
724
  }
725
725
  get S() {
726
- if ('second' in this.value) {
726
+ if (this.value && 'second' in this.value) {
727
727
  return this.second().toString();
728
728
  }
729
729
  else if (this.hasFullDate) {
@@ -732,13 +732,13 @@ export class bbnDt {
732
732
  return undefined;
733
733
  }
734
734
  get WW() {
735
- if ('weekOfYear' in this.value) {
735
+ if (this.value && 'weekOfYear' in this.value) {
736
736
  return this.value.weekOfYear.toString().padStart(2, '0');
737
737
  }
738
738
  return undefined;
739
739
  }
740
740
  get W() {
741
- if ('weekOfYear' in this.value) {
741
+ if (this.value && 'weekOfYear' in this.value) {
742
742
  return this.value.weekOfYear.toString();
743
743
  }
744
744
  return undefined;
@@ -954,7 +954,7 @@ export class bbnDt {
954
954
  return diff;
955
955
  }
956
956
  const realUnit = unitsCorrespondence[unit] || unit;
957
- const match = getRow(units, d => d[0] === realUnit);
957
+ const match = getRow(units, (d) => d[0] === realUnit);
958
958
  if (!match) {
959
959
  throw new Error('Invalid unit for diff: ' + unit);
960
960
  }
@@ -981,7 +981,7 @@ export class bbnDt {
981
981
  }
982
982
  let diff = this.diff(temp, chosenUnit);
983
983
  const rtf = new Intl.RelativeTimeFormat([bbn.env.lang, ...navigator.languages], { numeric: 'auto' });
984
- const match = getRow(units, d => d[0] === chosenUnit);
984
+ const match = getRow(units, (d) => d[0] === chosenUnit);
985
985
  if (!match) {
986
986
  throw new Error('Invalid unit for fromNow: ' + unit);
987
987
  }
@@ -1224,6 +1224,7 @@ export class bbnDt {
1224
1224
  return 31;
1225
1225
  }
1226
1226
  }
1227
+ return 0;
1227
1228
  }
1228
1229
  valueOf() {
1229
1230
  return this.unix(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.224",
3
+ "version": "2.0.226",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",