@bbn/bbn 2.0.104 → 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.
@@ -4,6 +4,7 @@ export default class bbnDtDate extends bbnDt<Temporal.PlainDate> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number, d?: number);
6
6
  protected compareSameKind(other: this): -1 | 0 | 1;
7
+ format(format?: string | boolean): string;
7
8
  ftime(withSeconds?: boolean): string;
8
9
  fdate(long?: boolean, weekday?: boolean): string;
9
10
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtDate extends bbnDt {
4
5
  constructor(y, m, d) {
5
6
  let value;
@@ -31,6 +32,17 @@ export default class bbnDtDate extends bbnDt {
31
32
  const cmp = Temporal.PlainDate.compare(this.value, other.value);
32
33
  return (cmp < 0 ? -1 : cmp > 0 ? 1 : 0);
33
34
  }
35
+ format(format) {
36
+ // long
37
+ if (format === true) {
38
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'long', day: 'long', weekday: 'long' }).pattern;
39
+ }
40
+ // short
41
+ if (!format) {
42
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric' }).pattern;
43
+ }
44
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
45
+ }
34
46
  ftime(withSeconds = false) {
35
47
  return '00:00' + (withSeconds ? ':00' : '');
36
48
  }
@@ -3,6 +3,7 @@ import bbnDt from './dt.js';
3
3
  export default class bbnDtDateTime extends bbnDt<Temporal.PlainDateTime> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
6
+ format(format?: string | boolean): string;
6
7
  fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
7
8
  ftime(withSeconds?: boolean): string;
8
9
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtDateTime extends bbnDt {
4
5
  constructor(y, m, d, h, i, s, ms) {
5
6
  let value;
@@ -27,6 +28,17 @@ export default class bbnDtDateTime extends bbnDt {
27
28
  super(value);
28
29
  this.kind = 'datetime';
29
30
  }
31
+ format(format) {
32
+ // long
33
+ if (format === true) {
34
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'long', day: 'long', weekday: 'long', hour: '2-digit', minute: '2-digit', second: undefined }).pattern;
35
+ }
36
+ // short
37
+ if (!format) {
38
+ format = getRow(bbn.dt.locales.date, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit', second: undefined }).pattern;
39
+ }
40
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
41
+ }
30
42
  fdate(long = false, withTime = false, weekday = false) {
31
43
  if (!this.value) {
32
44
  return '';
@@ -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) {
@@ -3,5 +3,6 @@ import bbnDt from './dt.js';
3
3
  export default class bbnDtYearMonth extends bbnDt<Temporal.PlainYearMonth> {
4
4
  readonly kind: bbnDtKind;
5
5
  constructor(y?: any, m?: number);
6
+ format(format?: string | boolean): string;
6
7
  fdate(long?: boolean, withTime?: boolean, weekday?: boolean): string;
7
8
  }
@@ -1,5 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  import bbnDt from './dt.js';
3
+ import getRow from '../../fn/object/getRow.js';
3
4
  export default class bbnDtYearMonth extends bbnDt {
4
5
  constructor(y, m) {
5
6
  let value;
@@ -28,6 +29,21 @@ export default class bbnDtYearMonth extends bbnDt {
28
29
  super(value);
29
30
  this.kind = 'year-month';
30
31
  }
32
+ format(format) {
33
+ // long
34
+ if (format === true) {
35
+ format = getRow(bbn.dt.locales.date, d => (d.year === 'numeric')
36
+ && (d.month === 'long')
37
+ && !('day' in d)).pattern;
38
+ }
39
+ // short
40
+ if (!format) {
41
+ format = getRow(bbn.dt.locales.date, d => (d.year === 'numeric')
42
+ && (d.month === 'numeric')
43
+ && !('day' in d)).pattern;
44
+ }
45
+ return bbnDt.constructor.prototype.formatDate.call(this, this.value, format);
46
+ }
31
47
  fdate(long = false, withTime = false, weekday = false) {
32
48
  if (!this.value) {
33
49
  return '';
@@ -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.104",
3
+ "version": "2.0.106",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",