@bbn/bbn 2.0.105 → 2.0.106

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.
@@ -7,6 +7,7 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
7
7
  readonly __bbnNoData = true;
8
8
  readonly __isBbnDt = true;
9
9
  constructor(value?: TValue);
10
+ setValid(isValid: boolean): void;
10
11
  get value(): TValue | undefined;
11
12
  get hasFullDate(): boolean;
12
13
  /** System time zone ID (e.g. "Europe/Rome") */
@@ -86,7 +87,6 @@ export declare abstract class bbnDt<TValue extends bbnDtTemporal> {
86
87
  get S(): string;
87
88
  get WW(): string;
88
89
  get W(): string;
89
- get isValid(): boolean;
90
90
  format(format?: string): string;
91
91
  matchFormat(value: any, format: string): boolean;
92
92
  getWeekday(n: 0 | 1 | 2 | 3 | 4 | 5 | 6, mode?: string, locale?: string): string | object;
@@ -46,8 +46,20 @@ export class bbnDt {
46
46
  }
47
47
  throw new Error(`Unknown weekday name '${name}' for locale '${loc}'`);
48
48
  };
49
+ Object.defineProperty(this, 'isValid', {
50
+ value: false,
51
+ writable: false,
52
+ configurable: true
53
+ });
49
54
  __classPrivateFieldSet(this, _bbnDt_value, value, "f");
50
55
  }
56
+ setValid(isValid) {
57
+ Object.defineProperty(this, 'isValid', {
58
+ value: isValid,
59
+ writable: false,
60
+ configurable: false
61
+ });
62
+ }
51
63
  get value() {
52
64
  return __classPrivateFieldGet(this, _bbnDt_value, "f");
53
65
  }
@@ -612,9 +624,6 @@ export class bbnDt {
612
624
  }
613
625
  return undefined;
614
626
  }
615
- get isValid() {
616
- return this.value !== undefined;
617
- }
618
627
  format(format = 'YYYY-MM-DD HH:II:SS') {
619
628
  let str = '';
620
629
  if (format) {
@@ -1,4 +1,4 @@
1
- export default function parse(input: string, format: string | string[], cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', locale?: {
1
+ export default function parse(input: string, format: string | string[], cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', force?: boolean, locale?: {
2
2
  monthsLong?: string[];
3
3
  monthsShort?: string[];
4
4
  weekdaysLong?: string[];
@@ -13,7 +13,7 @@ const lc = function (str, localeCode) {
13
13
  return str.toLowerCase();
14
14
  }
15
15
  };
16
- export default function parse(input, format, cls = 'auto', locale) {
16
+ export default function parse(input, format, cls = 'auto', force, locale) {
17
17
  var _a, _b, _c, _d, _e, _f, _g;
18
18
  buildLocaleFromIntl();
19
19
  const TemporalAny = globalThis.Temporal;
@@ -527,9 +527,15 @@ export default function parse(input, format, cls = 'auto', locale) {
527
527
  }
528
528
  }
529
529
  const fullRegex = new RegExp('^' + pattern + '$');
530
- const match = fullRegex.exec(input);
530
+ let match = fullRegex.exec(input);
531
531
  if (!match) {
532
- throw new Error(`Date string "${input}" does not match format "${fmt}"`);
532
+ if (force) {
533
+ input = new bbnDtDateTime(1970, 1, 1, 0, 0, 0, 0).format(fmt);
534
+ match = fullRegex.exec(input);
535
+ }
536
+ else {
537
+ throw new Error(`Date string "${input}" does not match format "${fmt}"`);
538
+ }
533
539
  }
534
540
  for (let idx = 1; idx < match.length; idx++) {
535
541
  const value = match[idx];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.105",
3
+ "version": "2.0.106",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",