@bbn/bbn 2.0.51 → 2.0.53

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.
@@ -0,0 +1,6 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ export default class bbnDtDate {
3
+ #private;
4
+ constructor(y?: any, m?: number, d?: number);
5
+ get value(): Temporal.PlainDate;
6
+ }
@@ -0,0 +1,42 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _bbnDtDate_value;
13
+ import { Temporal } from 'temporal-polyfill';
14
+ class bbnDtDate {
15
+ constructor(y, m, d) {
16
+ _bbnDtDate_value.set(this, void 0);
17
+ if (!y) {
18
+ __classPrivateFieldSet(this, _bbnDtDate_value, Temporal.PlainDate.from(Temporal.Now.plainDateISO()), "f");
19
+ }
20
+ else if (m === undefined) {
21
+ if (y instanceof Temporal.PlainDate) {
22
+ __classPrivateFieldSet(this, _bbnDtDate_value, y, "f");
23
+ }
24
+ else if (y instanceof Date) {
25
+ __classPrivateFieldSet(this, _bbnDtDate_value, new Temporal.PlainDate(y.getFullYear(), y.getMonth() + 1, y.getDate()), "f");
26
+ }
27
+ else if (typeof y === 'number') {
28
+ const d = new Date(y);
29
+ __classPrivateFieldSet(this, _bbnDtDate_value, new Temporal.PlainDate(d.getFullYear(), d.getMonth() + 1, d.getDate()), "f");
30
+ }
31
+ else {
32
+ throw new Error('Invalid value for bbnDtDateTime');
33
+ }
34
+ }
35
+ }
36
+ get value() {
37
+ return __classPrivateFieldGet(this, _bbnDtDate_value, "f");
38
+ }
39
+ }
40
+ _bbnDtDate_value = new WeakMap();
41
+ export default bbnDtDate;
42
+ ;
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from 'temporal-polyfill';
2
2
  export default class bbnDtDateTime {
3
3
  #private;
4
- constructor(y: number, m: number, d: number, h: number, i: number, s: number, ms?: number);
4
+ constructor(y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
5
5
  get value(): Temporal.PlainDateTime;
6
6
  }
@@ -12,9 +12,29 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _bbnDtDateTime_value;
13
13
  import { Temporal } from 'temporal-polyfill';
14
14
  class bbnDtDateTime {
15
- constructor(y, m, d, h, i, s, ms = 0) {
15
+ constructor(y, m, d, h, i, s, ms) {
16
16
  _bbnDtDateTime_value.set(this, void 0);
17
- __classPrivateFieldSet(this, _bbnDtDateTime_value, new Temporal.PlainDateTime(y, m, d, h, i, s, ms), "f");
17
+ if (!y) {
18
+ __classPrivateFieldSet(this, _bbnDtDateTime_value, Temporal.PlainDateTime.from(Temporal.Now.plainDateISO()), "f");
19
+ }
20
+ else if (m === undefined) {
21
+ if (y instanceof Temporal.PlainDateTime) {
22
+ __classPrivateFieldSet(this, _bbnDtDateTime_value, y, "f");
23
+ }
24
+ else if (y instanceof Date) {
25
+ __classPrivateFieldSet(this, _bbnDtDateTime_value, new Temporal.PlainDateTime(y.getFullYear(), y.getMonth() + 1, y.getDate(), y.getHours(), y.getMinutes(), y.getSeconds(), y.getMilliseconds()), "f");
26
+ }
27
+ else if (typeof y === 'number') {
28
+ const d = new Date(y);
29
+ __classPrivateFieldSet(this, _bbnDtDateTime_value, new Temporal.PlainDateTime(d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()), "f");
30
+ }
31
+ else {
32
+ throw new Error('Invalid value for bbnDtDateTime');
33
+ }
34
+ }
35
+ else {
36
+ __classPrivateFieldSet(this, _bbnDtDateTime_value, new Temporal.PlainDateTime(y, m, d || 1, h || 0, i || 0, s || 0, ms || 0), "f");
37
+ }
18
38
  }
19
39
  get value() {
20
40
  return __classPrivateFieldGet(this, _bbnDtDateTime_value, "f");
@@ -0,0 +1,6 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ export default class bbnDtMonthDay {
3
+ #private;
4
+ constructor(m?: any, d?: number);
5
+ get value(): Temporal.PlainMonthDay;
6
+ }
@@ -0,0 +1,46 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _bbnDtMonthDay_value;
13
+ import { Temporal } from 'temporal-polyfill';
14
+ class bbnDtMonthDay {
15
+ constructor(m, d) {
16
+ _bbnDtMonthDay_value.set(this, void 0);
17
+ if (!m) {
18
+ const d = new Date();
19
+ __classPrivateFieldSet(this, _bbnDtMonthDay_value, new Temporal.PlainMonthDay(d.getMonth() + 1, d.getDate()), "f");
20
+ }
21
+ else if (d === undefined) {
22
+ if (m instanceof Temporal.PlainMonthDay) {
23
+ __classPrivateFieldSet(this, _bbnDtMonthDay_value, m, "f");
24
+ }
25
+ else if (m instanceof Date) {
26
+ __classPrivateFieldSet(this, _bbnDtMonthDay_value, new Temporal.PlainMonthDay(m.getMonth() + 1, m.getDate()), "f");
27
+ }
28
+ else if (typeof m === 'number') {
29
+ const d = new Date(m);
30
+ __classPrivateFieldSet(this, _bbnDtMonthDay_value, new Temporal.PlainMonthDay(d.getMonth() + 1, d.getDate()), "f");
31
+ }
32
+ else {
33
+ throw new Error('Invalid value for bbnDtDateTime');
34
+ }
35
+ }
36
+ else {
37
+ __classPrivateFieldSet(this, _bbnDtMonthDay_value, new Temporal.PlainMonthDay(m, d), "f");
38
+ }
39
+ }
40
+ get value() {
41
+ return __classPrivateFieldGet(this, _bbnDtMonthDay_value, "f");
42
+ }
43
+ }
44
+ _bbnDtMonthDay_value = new WeakMap();
45
+ export default bbnDtMonthDay;
46
+ ;
@@ -0,0 +1,6 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ export default class bbnDtTime {
3
+ #private;
4
+ constructor(h?: any, i?: number, s?: number, ms?: number);
5
+ get value(): Temporal.PlainTime;
6
+ }
@@ -0,0 +1,48 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _bbnDtTime_value;
13
+ import { Temporal } from 'temporal-polyfill';
14
+ class bbnDtTime {
15
+ constructor(h, i, s, ms) {
16
+ _bbnDtTime_value.set(this, void 0);
17
+ if (!h) {
18
+ const d = new Date();
19
+ __classPrivateFieldSet(this, _bbnDtTime_value, new Temporal.PlainTime(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds() * 1000000), "f");
20
+ }
21
+ else if (h === undefined) {
22
+ if (h instanceof Temporal.PlainTime) {
23
+ __classPrivateFieldSet(this, _bbnDtTime_value, h, "f");
24
+ }
25
+ else if (h instanceof Date) {
26
+ __classPrivateFieldSet(this, _bbnDtTime_value, new Temporal.PlainTime(h.getHours(), h.getMinutes(), h.getSeconds(), h.getMilliseconds() * 1000000), "f");
27
+ }
28
+ else if (typeof h === 'number') {
29
+ if (i !== undefined) {
30
+ __classPrivateFieldSet(this, _bbnDtTime_value, new Temporal.PlainTime(h, i, s || 0, ms || 0), "f");
31
+ }
32
+ else {
33
+ const d = new Date(h);
34
+ __classPrivateFieldSet(this, _bbnDtTime_value, new Temporal.PlainTime(d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds() * 1000000), "f");
35
+ }
36
+ }
37
+ else {
38
+ throw new Error('Invalid value for bbnDtDateTime');
39
+ }
40
+ }
41
+ }
42
+ get value() {
43
+ return __classPrivateFieldGet(this, _bbnDtTime_value, "f");
44
+ }
45
+ }
46
+ _bbnDtTime_value = new WeakMap();
47
+ export default bbnDtTime;
48
+ ;
@@ -0,0 +1,6 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ export default class bbnDtYearMonth {
3
+ #private;
4
+ constructor(y?: any, m?: number);
5
+ get value(): Temporal.PlainYearMonth;
6
+ }
@@ -0,0 +1,43 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _bbnDtYearMonth_value;
13
+ import { Temporal } from 'temporal-polyfill';
14
+ class bbnDtYearMonth {
15
+ constructor(y, m) {
16
+ _bbnDtYearMonth_value.set(this, void 0);
17
+ if (!y) {
18
+ const d = new Date();
19
+ __classPrivateFieldSet(this, _bbnDtYearMonth_value, new Temporal.PlainYearMonth(d.getFullYear(), d.getMonth() + 1), "f");
20
+ }
21
+ else if (m === undefined) {
22
+ if (y instanceof Temporal.PlainYearMonth) {
23
+ __classPrivateFieldSet(this, _bbnDtYearMonth_value, y, "f");
24
+ }
25
+ else if (y instanceof Date) {
26
+ __classPrivateFieldSet(this, _bbnDtYearMonth_value, new Temporal.PlainYearMonth(y.getFullYear(), y.getMonth() + 1), "f");
27
+ }
28
+ else if (typeof m === 'number') {
29
+ const d = new Date(m);
30
+ __classPrivateFieldSet(this, _bbnDtYearMonth_value, new Temporal.PlainYearMonth(d.getFullYear(), d.getMonth() + 1), "f");
31
+ }
32
+ else {
33
+ throw new Error('Invalid value for bbnDtDateTime');
34
+ }
35
+ }
36
+ }
37
+ get value() {
38
+ return __classPrivateFieldGet(this, _bbnDtYearMonth_value, "f");
39
+ }
40
+ }
41
+ _bbnDtYearMonth_value = new WeakMap();
42
+ export default bbnDtYearMonth;
43
+ ;
@@ -0,0 +1,6 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ export default class bbnDtZoned {
3
+ #private;
4
+ constructor(z?: any, y?: any, m?: number, d?: number, h?: number, i?: number, s?: number, ms?: number);
5
+ get value(): Temporal.ZonedDateTime;
6
+ }
@@ -0,0 +1,47 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _bbnDtZoned_value;
13
+ import { Temporal } from 'temporal-polyfill';
14
+ import fromJsDate from '../functions/fromJsDate.js';
15
+ class bbnDtZoned {
16
+ constructor(z, y, m, d, h, i, s, ms) {
17
+ _bbnDtZoned_value.set(this, void 0);
18
+ if (!z) {
19
+ const date = new Date();
20
+ __classPrivateFieldSet(this, _bbnDtZoned_value, new Temporal.ZonedDateTime(BigInt(date.getTime() * 1000000), Intl.DateTimeFormat().resolvedOptions().timeZone), "f");
21
+ }
22
+ else if (y === undefined) {
23
+ if (z instanceof Temporal.ZonedDateTime) {
24
+ __classPrivateFieldSet(this, _bbnDtZoned_value, z, "f");
25
+ }
26
+ else if (z instanceof Date) {
27
+ __classPrivateFieldSet(this, _bbnDtZoned_value, fromJsDate(z, true), "f");
28
+ }
29
+ else if (typeof z === 'number') {
30
+ const d = new Date(z);
31
+ __classPrivateFieldSet(this, _bbnDtZoned_value, fromJsDate(d, true), "f");
32
+ }
33
+ else {
34
+ throw new Error('Invalid value for bbnDtZoned');
35
+ }
36
+ }
37
+ else {
38
+ const dt = new Temporal.PlainDateTime(y, m, d || 1, h || 0, i || 0, s || 0, ms || 0);
39
+ __classPrivateFieldSet(this, _bbnDtZoned_value, dt.toZonedDateTime(z || Temporal.Now.timeZoneId()), "f");
40
+ }
41
+ }
42
+ get value() {
43
+ return __classPrivateFieldGet(this, _bbnDtZoned_value, "f");
44
+ }
45
+ }
46
+ _bbnDtZoned_value = new WeakMap();
47
+ export default bbnDtZoned;
@@ -24,6 +24,6 @@ type CommonFormats = {
24
24
  * - Time: hour / hour:minute / hour:minute:second (+ optional TZ).
25
25
  * - Datetime: only full dates (Y-M-D ± weekday) combined with time.
26
26
  */
27
- export declare function getCommonFormatsForLocale(lng: string | string[]): CommonFormats;
27
+ export declare function getCommonFormatsForLocale(lng?: string | string[]): CommonFormats;
28
28
  export default function buildLocaleFromIntl(): void;
29
29
  export {};
@@ -125,6 +125,9 @@ const partsToPattern = (parts, resolved, requestedOpts) => {
125
125
  * - Datetime: only full dates (Y-M-D ± weekday) combined with time.
126
126
  */
127
127
  export function getCommonFormatsForLocale(lng) {
128
+ if (!lng) {
129
+ lng = [bbn.env.lang, ...navigator.languages];
130
+ }
128
131
  const sample = new Date(Date.UTC(2000, 0, 2, 13, 45, 30));
129
132
  const date = [];
130
133
  const time = [];
@@ -0,0 +1,7 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ /**
3
+ * Convert a JS Date into:
4
+ * - Temporal.Instant (if hasZone=true)
5
+ * - Temporal.PlainDate (if hasZone=false)
6
+ */
7
+ export default function fromJsDate(date: Date, hasZone?: boolean, timeZone?: string): Temporal.ZonedDateTime | Temporal.PlainDateTime;
@@ -0,0 +1,12 @@
1
+ import { Temporal } from 'temporal-polyfill';
2
+ /**
3
+ * Convert a JS Date into:
4
+ * - Temporal.Instant (if hasZone=true)
5
+ * - Temporal.PlainDate (if hasZone=false)
6
+ */
7
+ export default function fromJsDate(date, hasZone = false, timeZone = Temporal.Now.timeZoneId()) {
8
+ const T = Temporal;
9
+ const instant = T.Instant.fromEpochMilliseconds(date.getTime());
10
+ const zdt = instant.toZonedDateTimeISO(timeZone);
11
+ return hasZone ? zdt : zdt.toPlainDateTime();
12
+ }
@@ -1 +1 @@
1
- export default function guessFormat(input: string, formats?: string | string[], lng?: string): string | null;
1
+ export default function guessFormat(input: string, formats?: string | string[], lng?: string | string[]): string | null;
@@ -1,7 +1,12 @@
1
- import { Temporal } from 'temporal-polyfill';
2
- export default function parse(input: string, format: string | string[], locale?: {
1
+ import bbnDtZoned from '../classes/zoned.js';
2
+ import bbnDtDateTime from '../classes/dateTime.js';
3
+ import bbnDtDate from '../classes/date.js';
4
+ import bbnDtTime from '../classes/time.js';
5
+ import bbnDtYearMonth from '../classes/yearMonth.js';
6
+ import bbnDtMonthDay from '../classes/monthDay.js';
7
+ export default function parse(input: string, format: string | string[], cls?: 'auto' | 'zoned' | 'dateTime' | 'date' | 'time' | 'yearMonth' | 'monthDay', locale?: {
3
8
  monthsLong?: string[];
4
9
  monthsShort?: string[];
5
10
  weekdaysLong?: string[];
6
11
  weekdaysShort?: string[];
7
- }): Temporal.Instant | Temporal.PlainDateTime | Temporal.PlainDate | Temporal.PlainTime | Temporal.PlainYearMonth | Temporal.PlainMonthDay;
12
+ }): bbnDtZoned | bbnDtDateTime | bbnDtDate | bbnDtTime | bbnDtYearMonth | bbnDtMonthDay;
@@ -1,4 +1,10 @@
1
1
  import buildLocaleFromIntl from './buildLocaleFromIntl.js';
2
+ import bbnDtZoned from '../classes/zoned.js';
3
+ import bbnDtDateTime from '../classes/dateTime.js';
4
+ import bbnDtDate from '../classes/date.js';
5
+ import bbnDtTime from '../classes/time.js';
6
+ import bbnDtYearMonth from '../classes/yearMonth.js';
7
+ import bbnDtMonthDay from '../classes/monthDay.js';
2
8
  const lc = function (str, localeCode) {
3
9
  try {
4
10
  return localeCode ? str.toLocaleLowerCase(localeCode) : str.toLowerCase();
@@ -7,7 +13,7 @@ const lc = function (str, localeCode) {
7
13
  return str.toLowerCase();
8
14
  }
9
15
  };
10
- export default function parse(input, format, locale) {
16
+ export default function parse(input, format, cls = 'auto', locale) {
11
17
  var _a, _b, _c, _d, _e, _f;
12
18
  buildLocaleFromIntl();
13
19
  const TemporalAny = globalThis.Temporal;
@@ -443,7 +449,7 @@ export default function parse(input, format, locale) {
443
449
  }
444
450
  }
445
451
  ];
446
- function parseWithFormat(fmt) {
452
+ function parseWithFormat(fmt, cls = 'auto') {
447
453
  var _a;
448
454
  const ctx = {
449
455
  year: 1970,
@@ -461,6 +467,13 @@ export default function parse(input, format, locale) {
461
467
  hasSecond: false,
462
468
  hasMs: false
463
469
  };
470
+ const isClsAuto = cls === 'auto';
471
+ const isClsZoned = cls.toLowerCase() === 'zoned';
472
+ const isClsDateTime = cls.toLowerCase() === 'datetime';
473
+ const isClsDate = cls.toLowerCase() === 'date';
474
+ const isClsTime = cls.toLowerCase() === 'time';
475
+ const isClsYearMonth = cls.toLowerCase() === 'yearmonth';
476
+ const isClsMonthDay = cls.toLowerCase() === 'monthday';
464
477
  const tokenSpecs = makeTokenSpecs();
465
478
  const tokensByLength = [...tokenSpecs].sort((a, b) => b.token.length - a.token.length);
466
479
  let pattern = '';
@@ -546,8 +559,8 @@ export default function parse(input, format, locale) {
546
559
  const hasMonthDayOnly = !ctx.hasYear && ctx.hasMonth && ctx.hasDay;
547
560
  const hasTime = ctx.hasHour || ctx.hasMinute || ctx.hasSecond || ctx.hasMs;
548
561
  const hasZone = ctx.timeZone != null || ctx.offsetMinutes != null;
549
- // ---------- 1) If timezone (Z or z) → Instant ----------
550
- if (hasZone) {
562
+ // ---------- 1) If timezone (Z or z) → Zoned ----------
563
+ if (isClsZoned || (hasZone && isClsAuto)) {
551
564
  let pdt;
552
565
  try {
553
566
  pdt = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
@@ -558,33 +571,38 @@ export default function parse(input, format, locale) {
558
571
  if (ctx.timeZone) {
559
572
  const tz = T.TimeZone.from(ctx.timeZone);
560
573
  const zdt = pdt.toZonedDateTime(tz);
561
- return zdt.toInstant();
574
+ return new bbnDtZoned(zdt);
562
575
  }
563
576
  const utcMs = Date.UTC(ctx.year, ctx.month - 1, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms);
564
577
  const epochMs = utcMs - ((_a = ctx.offsetMinutes) !== null && _a !== void 0 ? _a : 0) * 60000;
565
- return T.Instant.fromEpochMilliseconds(epochMs);
578
+ return new bbnDtZoned(T.Instant.fromEpochMilliseconds(epochMs).toZonedDateTimeISO(T.Now.timeZoneId()));
566
579
  }
567
580
  // ---------- 2) No timezone: decide which Plain* type ----------
568
- if (hasDate && hasTime) {
581
+ if (isClsDateTime || (isClsAuto && hasDate && hasTime)) {
569
582
  if (!hasFullDate) {
570
583
  throw new Error('PlainDateTime requires year, month and day');
571
584
  }
572
- return new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
585
+ const d = new T.PlainDateTime(ctx.year, ctx.month, ctx.day, ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
586
+ return new bbnDtDateTime(d);
573
587
  }
574
- if (hasDate && !hasTime) {
575
- if (hasFullDate) {
576
- return new T.PlainDate(ctx.year, ctx.month, ctx.day);
588
+ if (isClsDate || isClsYearMonth || isClsMonthDay || (isClsAuto && hasDate && !hasTime)) {
589
+ if (isClsDate && hasFullDate) {
590
+ const d = new T.PlainDate(ctx.year, ctx.month, ctx.day);
591
+ return new bbnDtDate(d);
577
592
  }
578
- if (hasYearMonthOnly) {
579
- return new T.PlainYearMonth(ctx.year, ctx.month);
593
+ if (isClsYearMonth && hasYearMonthOnly) {
594
+ const d = new T.PlainYearMonth(ctx.year, ctx.month);
595
+ return new bbnDtYearMonth(d);
580
596
  }
581
- if (hasMonthDayOnly) {
582
- return new T.PlainMonthDay(ctx.month, ctx.day, 1972);
597
+ if (isClsMonthDay && hasMonthDayOnly) {
598
+ const d = new T.PlainMonthDay(ctx.month, ctx.day, 1972);
599
+ return new bbnDtMonthDay(d);
583
600
  }
584
601
  throw new Error('Not enough date components for a known Temporal type');
585
602
  }
586
- if (!hasDate && hasTime) {
587
- return new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
603
+ if (isClsTime || (isClsAuto && !hasDate && hasTime)) {
604
+ const d = new T.PlainTime(ctx.hour, ctx.minute, ctx.second, ctx.ms * 1000000);
605
+ return new bbnDtTime(d);
588
606
  }
589
607
  throw new Error('No date or time information found in input');
590
608
  }
@@ -592,7 +610,7 @@ export default function parse(input, format, locale) {
592
610
  let lastError = null;
593
611
  for (const fmt of format) {
594
612
  try {
595
- return parseWithFormat(fmt);
613
+ return parseWithFormat(fmt, cls);
596
614
  }
597
615
  catch (e) {
598
616
  lastError = e;
@@ -600,6 +618,6 @@ export default function parse(input, format, locale) {
600
618
  }
601
619
  throw lastError !== null && lastError !== void 0 ? lastError : new Error('No format matched');
602
620
  }
603
- return parseWithFormat(format);
621
+ return parseWithFormat(format, cls);
604
622
  }
605
623
  ;
package/dist/dt.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import { Temporal } from 'temporal-polyfill';
2
1
  import bbnDtDateTime from './dt/classes/dateTime.js';
3
2
  import parse from './dt/functions/parse.js';
4
3
  import guessFormat from './dt/functions/guessFormat.js';
5
4
  declare const dt: {
6
- (value: any, inputFormat?: null | String): bbnDtDateTime | Temporal.PlainDateTime | Temporal.Instant | Temporal.PlainDate | Temporal.PlainTime | Temporal.PlainYearMonth | Temporal.PlainMonthDay;
5
+ (value: any, inputFormat?: null | String, cls?: "auto" | "zoned" | "dateTime" | "date" | "time" | "yearMonth" | "monthDay"): bbnDtDateTime | import("./dt/classes/zoned.js").default | import("./dt/classes/date.js").default | import("./dt/classes/time.js").default | import("./dt/classes/yearMonth.js").default | import("./dt/classes/monthDay.js").default;
7
6
  locales: any;
8
7
  parse: typeof parse;
9
8
  guessFormat: typeof guessFormat;
package/dist/dt.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import bbnDtDateTime from './dt/classes/dateTime.js';
2
2
  import _ from './_.js';
3
- import isDate from './fn/type/isDate.js';
4
- import isPrimitive from './fn/type/isPrimitive.js';
5
3
  import parse from './dt/functions/parse.js';
6
4
  import guessFormat from './dt/functions/guessFormat.js';
7
5
  const patterns = [
@@ -192,39 +190,32 @@ const unitsCorrespondence = {
192
190
  'W': 'w',
193
191
  'w': 'w'
194
192
  };
195
- const dt = (value, inputFormat = null) => {
196
- let v;
193
+ const dt = (value, inputFormat = null, cls = 'auto') => {
197
194
  if (!value) {
198
- const d = new Date();
199
- return new bbnDtDateTime(d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
195
+ return new bbnDtDateTime();
200
196
  }
201
197
  if (typeof value === 'string') {
202
198
  if (inputFormat) {
203
- return parse(value, inputFormat);
199
+ return parse(value, inputFormat, cls);
204
200
  }
205
201
  else {
206
202
  const format = guessFormat(value);
207
203
  if (format) {
208
- return parse(value, format);
204
+ return parse(value, format, cls);
209
205
  }
210
206
  else {
211
207
  throw new Error(_('Could not guess the date format for value: %s', value));
212
208
  }
213
209
  }
214
210
  }
215
- else {
216
- if (typeof value === 'number') {
217
- const d = new Date(value);
218
- return new bbnDtDateTime(d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
219
- }
220
- else if (isDate(value)) {
221
- const d = value;
222
- return new bbnDtDateTime(d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
223
- }
224
- else if (isPrimitive(value)) {
225
- throw new Error(_('Invalid date value: %s', value));
226
- }
211
+ if (typeof value === 'number') {
212
+ return new bbnDtDateTime(value);
213
+ }
214
+ else if (value instanceof Date) {
215
+ const d = value;
216
+ return new bbnDtDateTime(d.getFullYear(), d.getMonth() + 1, d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
227
217
  }
218
+ throw new Error(_('Invalid date value: %s', value));
228
219
  };
229
220
  dt.locales = Object.create(null);
230
221
  dt.parse = parse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bbn/bbn",
3
- "version": "2.0.51",
3
+ "version": "2.0.53",
4
4
  "description": "Javascript toolkit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",