@thisisagile/easy 18.11.1 → 18.12.0

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/README.md CHANGED
@@ -124,7 +124,7 @@ However, if you would create an `Email` value object, the validation can be impl
124
124
  You can now use the above `Email` class as the type of email properties in an entity or struct to make sure that this property is a valid email.
125
125
 
126
126
  #### DateTime
127
- DateTime is a value object that takes either a Date object, RFC-3339 formatted string, or a number representing Epoch in milliseconds. The json is always an RFC-3339 formatted string. [Day.js](https://day.js.org/) is used internally.
127
+ DateTime is a value object that takes either a Date object, RFC-3339 formatted string, or a number representing Epoch in milliseconds. The json is always an RFC-3339 formatted string. [luxon](https://moment.github.io/luxon/#/) is used internally.
128
128
 
129
129
  A few examples of DateTime:
130
130
 
@@ -0,0 +1,140 @@
1
+ import {
2
+ seconds
3
+ } from "./chunk-RF23BV6J.mjs";
4
+ import {
5
+ isDate
6
+ } from "./chunk-ADJAEGCT.mjs";
7
+ import {
8
+ choose,
9
+ ifDefined,
10
+ tryTo
11
+ } from "./chunk-I2VWZJ2K.mjs";
12
+ import {
13
+ Value
14
+ } from "./chunk-S3NSPQ7M.mjs";
15
+ import {
16
+ isA
17
+ } from "./chunk-D5IYAIMK.mjs";
18
+ import {
19
+ use
20
+ } from "./chunk-PF7HDF6B.mjs";
21
+ import {
22
+ isDefined,
23
+ isNumber,
24
+ isString
25
+ } from "./chunk-AAND4MKF.mjs";
26
+
27
+ // src/domain/DateTime.ts
28
+ import { DateTime as LuxonDateTime, Settings } from "luxon";
29
+ Settings.defaultZone = "utc";
30
+ var DateTime = class _DateTime extends Value {
31
+ luxon;
32
+ constructor(value, format) {
33
+ const luxon = choose(value).type(isString, (v) => format ? LuxonDateTime.fromFormat(v, format, { setZone: true }) : LuxonDateTime.fromISO(v, { setZone: true })).type(isNumber, (v) => LuxonDateTime.fromMillis(v)).type(isDate, (v) => LuxonDateTime.fromJSDate(v)).type(isDateTime, (v) => v.luxon).else(value instanceof LuxonDateTime ? value : LuxonDateTime.fromISO(void 0));
34
+ super(luxon.toISO() ?? void 0);
35
+ this.luxon = luxon;
36
+ }
37
+ static get now() {
38
+ return new _DateTime(LuxonDateTime.utc());
39
+ }
40
+ get isValid() {
41
+ return isDefined(this.value) && this.utc.isValid;
42
+ }
43
+ /**
44
+ * @deprecated Deprecated in favor for DateTime.from as that also accepts locales and another DateTime
45
+ */
46
+ get fromNow() {
47
+ return this.from();
48
+ }
49
+ get inAmsterdam() {
50
+ return this.withZone("Europe/Amsterdam");
51
+ }
52
+ get inNewYork() {
53
+ return this.withZone("America/New_York");
54
+ }
55
+ get inLondon() {
56
+ return this.withZone("Europe/London");
57
+ }
58
+ get inWarsaw() {
59
+ return this.withZone("Europe/Warsaw");
60
+ }
61
+ get utc() {
62
+ return this.luxon.setZone("utc");
63
+ }
64
+ from(dateOrLocale, maybeLocale) {
65
+ return use(
66
+ (isString(dateOrLocale) ? dateOrLocale : maybeLocale) ?? "en",
67
+ (locale) => ifDefined(
68
+ isA(dateOrLocale) ? dateOrLocale : void 0,
69
+ (d) => this.utc.setLocale(locale).toRelative({ base: d.utc }),
70
+ () => this.utc.setLocale(locale).toRelative()
71
+ )
72
+ ) ?? "";
73
+ }
74
+ isAfter(dt2) {
75
+ return this.utc > dt2.utc;
76
+ }
77
+ isBefore(dt2) {
78
+ return this.utc < dt2.utc;
79
+ }
80
+ equals(dt2) {
81
+ return this.utc.hasSame(dt2.utc, "millisecond");
82
+ }
83
+ add(n, unit = "day") {
84
+ return new _DateTime(this.luxon.plus(isNumber(n) ? { [unit]: n } : n));
85
+ }
86
+ subtract(n, unit = "day") {
87
+ return new _DateTime(this.luxon.minus(isNumber(n) ? { [unit]: n } : n));
88
+ }
89
+ diff(other, unit = "day", opts) {
90
+ return Math[opts?.rounding ?? "floor"](this.utc.diff(other.utc).as(unit));
91
+ }
92
+ startOf(unit = "day") {
93
+ return new _DateTime(this.luxon.startOf(unit));
94
+ }
95
+ endOf(unit = "day") {
96
+ return new _DateTime(this.luxon.endOf(unit));
97
+ }
98
+ isWeekend() {
99
+ return this.luxon.isWeekend;
100
+ }
101
+ withZone(zone) {
102
+ return new _DateTime(this.luxon.setZone(zone));
103
+ }
104
+ toString() {
105
+ return this.value ?? "";
106
+ }
107
+ toJSON() {
108
+ return this.utc.toISO();
109
+ }
110
+ toFormat(format) {
111
+ return this.luxon.toFormat(format);
112
+ }
113
+ toLocale(locale = "nl-NL", format = "D") {
114
+ return this.luxon.setLocale(locale).toFormat(format);
115
+ }
116
+ toFull(locale) {
117
+ return this.toLocale(locale, "DDD");
118
+ }
119
+ toDate() {
120
+ return this.isValid ? this.utc.toJSDate() : void 0;
121
+ }
122
+ toEpoch() {
123
+ return this.luxon.toMillis();
124
+ }
125
+ ago(end = _DateTime.now) {
126
+ return seconds.toText(end.diff(this, "second"));
127
+ }
128
+ withClock(clock) {
129
+ return tryTo(() => [this.toDate(), clock.toDate()]).map(([td, cd]) => new Date(td.getFullYear(), td.getMonth(), td.getDate(), cd.getHours(), cd.getMinutes(), cd.getSeconds())).map((d) => new _DateTime(d)).value;
130
+ }
131
+ };
132
+ var isDateTime = (dt2) => isDefined(dt2) && dt2 instanceof DateTime;
133
+ var dt = (dt2) => new DateTime(dt2);
134
+
135
+ export {
136
+ DateTime,
137
+ isDateTime,
138
+ dt
139
+ };
140
+ //# sourceMappingURL=chunk-EOHHPAAY.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/domain/DateTime.ts"],"sourcesContent":["import { DateTime as LuxonDateTime, DateTimeUnit as LuxonDateTimeUnit, DurationUnit as LuxonDurationUnit, Settings } from 'luxon';\nimport { Value } from '../types/Value';\nimport { Optional } from '../types/Types';\nimport { choose } from '../types/Case';\nimport { isDefined, isNumber, isString } from '../types/Is';\nimport { isDate } from '../types/IsDate';\nimport { isA } from '../types/IsA';\nimport { ifDefined } from '../utils/If';\nimport { JsonValue } from '../types/Json';\nimport { seconds } from '../utils/Seconds';\nimport { tryTo } from '../types/Try';\nimport { use } from '../types/Constructor';\n\nSettings.defaultZone = 'utc';\n\nexport type DateTimeUnit = LuxonDateTimeUnit;\nexport type DurationUnit = LuxonDurationUnit;\nexport type Duration = Partial<Record<DurationUnit, number>>;\n\nexport type DiffOptions = {\n rounding: 'floor' | 'ceil' | 'round';\n};\n\nexport type DatetimeInput = string | number | Date | DateTime | null;\n\nexport class DateTime extends Value<Optional<string>> {\n protected readonly luxon: LuxonDateTime;\n\n constructor(value?: DatetimeInput);\n constructor(value?: string, format?: string);\n constructor(value?: DatetimeInput, format?: string) {\n const luxon = choose(value)\n .type(isString, v => (format ? LuxonDateTime.fromFormat(v, format, { setZone: true }) : LuxonDateTime.fromISO(v, { setZone: true })))\n .type(isNumber, v => LuxonDateTime.fromMillis(v))\n .type(isDate, v => LuxonDateTime.fromJSDate(v))\n .type(isDateTime, v => v.luxon)\n // Allow constructing with LuxonDateTime without exposing types\n .else(value instanceof LuxonDateTime ? value : LuxonDateTime.fromISO(undefined as any));\n\n super(luxon.toISO() ?? undefined);\n this.luxon = luxon;\n }\n\n static get now(): DateTime {\n return new DateTime(LuxonDateTime.utc() as any);\n }\n\n get isValid(): boolean {\n return isDefined(this.value) && this.utc.isValid;\n }\n\n /**\n * @deprecated Deprecated in favor for DateTime.from as that also accepts locales and another DateTime\n */\n get fromNow(): string {\n return this.from();\n }\n\n get inAmsterdam(): DateTime {\n return this.withZone('Europe/Amsterdam');\n }\n\n get inNewYork(): DateTime {\n return this.withZone('America/New_York');\n }\n\n get inLondon(): DateTime {\n return this.withZone('Europe/London');\n }\n\n get inWarsaw(): DateTime {\n return this.withZone('Europe/Warsaw');\n }\n\n protected get utc(): LuxonDateTime {\n return this.luxon.setZone('utc');\n }\n\n from(locale?: string): string;\n\n from(date?: DateTime, locale?: string): string;\n\n from(dateOrLocale?: string | DateTime, maybeLocale?: string): string {\n return (\n use((isString(dateOrLocale) ? dateOrLocale : maybeLocale) ?? 'en', locale =>\n ifDefined(\n isA<DateTime>(dateOrLocale) ? dateOrLocale : undefined,\n d => this.utc.setLocale(locale).toRelative({ base: d.utc }),\n () => this.utc.setLocale(locale).toRelative()\n )\n ) ?? ''\n );\n }\n\n isAfter(dt: DateTime): boolean {\n return this.utc > dt.utc;\n }\n\n isBefore(dt: DateTime): boolean {\n return this.utc < dt.utc;\n }\n\n equals(dt: DateTime): boolean {\n return this.utc.hasSame(dt.utc, 'millisecond');\n }\n\n add(n: number, unit?: DurationUnit): DateTime;\n\n add(duration: Duration): DateTime;\n\n add(n: number | Duration, unit: DurationUnit = 'day'): DateTime {\n return new DateTime(this.luxon.plus(isNumber(n) ? { [unit]: n } : n) as any);\n }\n\n subtract(n: number, unit?: DurationUnit): DateTime;\n\n subtract(duration: Duration): DateTime;\n\n subtract(n: number | Duration, unit: DurationUnit = 'day'): DateTime {\n return new DateTime(this.luxon.minus(isNumber(n) ? { [unit]: n } : n) as any);\n }\n\n diff(other: DateTime, unit: DateTimeUnit = 'day', opts?: DiffOptions): number {\n return Math[opts?.rounding ?? 'floor'](this.utc.diff(other.utc).as(unit));\n }\n\n startOf(unit: DateTimeUnit = 'day'): DateTime {\n return new DateTime(this.luxon.startOf(unit) as any);\n }\n\n endOf(unit: DateTimeUnit = 'day'): DateTime {\n return new DateTime(this.luxon.endOf(unit) as any);\n }\n\n isWeekend(): boolean {\n return this.luxon.isWeekend;\n }\n\n withZone(zone: string): DateTime {\n return new DateTime(this.luxon.setZone(zone) as any);\n }\n\n toString(): string {\n return this.value ?? '';\n }\n\n toJSON(): JsonValue {\n return this.utc.toISO();\n }\n\n toFormat(format: string): string {\n return this.luxon.toFormat(format);\n }\n\n toLocale(locale = 'nl-NL', format = 'D'): string {\n return this.luxon.setLocale(locale).toFormat(format);\n }\n\n toFull(locale?: string): string {\n return this.toLocale(locale, 'DDD');\n }\n\n toDate(): Optional<Date> {\n return this.isValid ? this.utc.toJSDate() : undefined;\n }\n\n toEpoch(): number {\n return this.luxon.toMillis();\n }\n\n ago(end: DateTime = DateTime.now): string {\n return seconds.toText(end.diff(this, 'second'));\n }\n\n withClock(clock: DateTime): DateTime {\n return tryTo(() => [this.toDate() as Date, clock.toDate() as Date])\n .map(([td, cd]) => new Date(td.getFullYear(), td.getMonth(), td.getDate(), cd.getHours(), cd.getMinutes(), cd.getSeconds()))\n .map(d => new DateTime(d)).value;\n }\n}\n\nexport const isDateTime = (dt?: unknown): dt is DateTime => isDefined(dt) && dt instanceof DateTime;\n\nexport const dt = (dt?: DatetimeInput): DateTime => new DateTime(dt);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,YAAY,eAAqF,gBAAgB;AAa1H,SAAS,cAAc;AAYhB,IAAM,WAAN,MAAM,kBAAiB,MAAwB;AAAA,EACjC;AAAA,EAInB,YAAY,OAAuB,QAAiB;AAClD,UAAM,QAAQ,OAAO,KAAK,EACvB,KAAK,UAAU,OAAM,SAAS,cAAc,WAAW,GAAG,QAAQ,EAAE,SAAS,KAAK,CAAC,IAAI,cAAc,QAAQ,GAAG,EAAE,SAAS,KAAK,CAAC,CAAE,EACnI,KAAK,UAAU,OAAK,cAAc,WAAW,CAAC,CAAC,EAC/C,KAAK,QAAQ,OAAK,cAAc,WAAW,CAAC,CAAC,EAC7C,KAAK,YAAY,OAAK,EAAE,KAAK,EAE7B,KAAK,iBAAiB,gBAAgB,QAAQ,cAAc,QAAQ,MAAgB,CAAC;AAExF,UAAM,MAAM,MAAM,KAAK,MAAS;AAChC,SAAK,QAAQ;AAAA,EACf;AAAA,EAEA,WAAW,MAAgB;AACzB,WAAO,IAAI,UAAS,cAAc,IAAI,CAAQ;AAAA,EAChD;AAAA,EAEA,IAAI,UAAmB;AACrB,WAAO,UAAU,KAAK,KAAK,KAAK,KAAK,IAAI;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAkB;AACpB,WAAO,KAAK,KAAK;AAAA,EACnB;AAAA,EAEA,IAAI,cAAwB;AAC1B,WAAO,KAAK,SAAS,kBAA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GAAG,YAAY,GAAG,GAAG,SAAS,GAAG,GAAG,QAAQ,GAAG,GAAG,SAAS,GAAG,GAAG,WAAW,GAAG,GAAG,WAAW,CAAC,CAAC,EAC1H,IAAI,OAAK,IAAI,UAAS,CAAC,CAAC,EAAE;AAAA,EAC/B;AACF;AAEO,IAAM,aAAa,CAACA,QAAiC,UAAUA,GAAE,KAAKA,eAAc;AAEpF,IAAM,KAAK,CAACA,QAAiC,IAAI,SAASA,GAAE;","names":["dt"]}
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-TNLJ45P5.mjs";
5
5
  import {
6
6
  DateTime
7
- } from "./chunk-GRDUTNMZ.mjs";
7
+ } from "./chunk-EOHHPAAY.mjs";
8
8
  import {
9
9
  Struct
10
10
  } from "./chunk-BSN5WGZ6.mjs";
@@ -45,4 +45,4 @@ __decorateClass([
45
45
  export {
46
46
  Audit
47
47
  };
48
- //# sourceMappingURL=chunk-5VP4WNID.mjs.map
48
+ //# sourceMappingURL=chunk-TMVZSMUA.mjs.map
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Audit
3
- } from "../chunk-5VP4WNID.mjs";
3
+ } from "../chunk-TMVZSMUA.mjs";
4
4
  import "../chunk-TNLJ45P5.mjs";
5
- import "../chunk-GRDUTNMZ.mjs";
5
+ import "../chunk-EOHHPAAY.mjs";
6
6
  import "../chunk-RF23BV6J.mjs";
7
7
  import "../chunk-ADJAEGCT.mjs";
8
8
  import "../chunk-BSN5WGZ6.mjs";
@@ -1,18 +1,16 @@
1
- import { Dayjs } from 'dayjs';
2
- import 'dayjs/locale/de';
3
- import 'dayjs/locale/nl';
1
+ import { DateTime as LuxonDateTime, DateTimeUnit as LuxonDateTimeUnit, DurationUnit as LuxonDurationUnit } from 'luxon';
4
2
  import { Value } from '../types/Value';
5
3
  import { Optional } from '../types/Types';
6
4
  import { JsonValue } from '../types/Json';
7
- export type DateTimeUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
8
- export type DurationUnit = DateTimeUnit | 'years' | 'quarters' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds' | 'milliseconds';
5
+ export type DateTimeUnit = LuxonDateTimeUnit;
6
+ export type DurationUnit = LuxonDurationUnit;
9
7
  export type Duration = Partial<Record<DurationUnit, number>>;
10
8
  export type DiffOptions = {
11
9
  rounding: 'floor' | 'ceil' | 'round';
12
10
  };
13
11
  export type DatetimeInput = string | number | Date | DateTime | null;
14
12
  export declare class DateTime extends Value<Optional<string>> {
15
- protected readonly date: Dayjs;
13
+ protected readonly luxon: LuxonDateTime;
16
14
  constructor(value?: DatetimeInput);
17
15
  constructor(value?: string, format?: string);
18
16
  static get now(): DateTime;
@@ -22,7 +20,7 @@ export declare class DateTime extends Value<Optional<string>> {
22
20
  get inNewYork(): DateTime;
23
21
  get inLondon(): DateTime;
24
22
  get inWarsaw(): DateTime;
25
- protected get utc(): Dayjs;
23
+ protected get utc(): LuxonDateTime;
26
24
  from(locale?: string): string;
27
25
  from(date?: DateTime, locale?: string): string;
28
26
  isAfter(dt: DateTime): boolean;
@@ -2,7 +2,7 @@ import {
2
2
  DateTime,
3
3
  dt,
4
4
  isDateTime
5
- } from "../chunk-GRDUTNMZ.mjs";
5
+ } from "../chunk-EOHHPAAY.mjs";
6
6
  import "../chunk-RF23BV6J.mjs";
7
7
  import "../chunk-ADJAEGCT.mjs";
8
8
  import "../chunk-I2VWZJ2K.mjs";
@@ -4,11 +4,11 @@ import {
4
4
  import "../chunk-6FUVIZYN.mjs";
5
5
  import {
6
6
  Audit
7
- } from "../chunk-5VP4WNID.mjs";
7
+ } from "../chunk-TMVZSMUA.mjs";
8
8
  import {
9
9
  required
10
10
  } from "../chunk-TNLJ45P5.mjs";
11
- import "../chunk-GRDUTNMZ.mjs";
11
+ import "../chunk-EOHHPAAY.mjs";
12
12
  import "../chunk-RF23BV6J.mjs";
13
13
  import "../chunk-ADJAEGCT.mjs";
14
14
  import {
package/dist/index.js CHANGED
@@ -141,6 +141,7 @@ __export(src_exports, {
141
141
  dt: () => dt,
142
142
  entries: () => entries,
143
143
  equals: () => equals,
144
+ errorMessage: () => errorMessage,
144
145
  extractKeys: () => extractKeys,
145
146
  future: () => future,
146
147
  gt: () => gt,
@@ -264,7 +265,7 @@ __export(src_exports, {
264
265
  template: () => template,
265
266
  text: () => text,
266
267
  textValue: () => textValue,
267
- timezone: () => timezone2,
268
+ timezone: () => timezone,
268
269
  timezones: () => timezones,
269
270
  toArray: () => toArray,
270
271
  toCacheOptions: () => toCacheOptions,
@@ -300,7 +301,7 @@ __export(src_exports, {
300
301
  tupleO: () => tupleO,
301
302
  uri: () => uri,
302
303
  use: () => use,
303
- utc: () => utc2,
304
+ utc: () => utc,
304
305
  valid: () => valid,
305
306
  validate: () => validate,
306
307
  validateReject: () => validateReject,
@@ -1796,17 +1797,7 @@ function isStruct(s) {
1796
1797
  }
1797
1798
 
1798
1799
  // src/domain/DateTime.ts
1799
- var import_dayjs = __toESM(require("dayjs"));
1800
- var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"));
1801
- var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
1802
- var import_isoWeek = __toESM(require("dayjs/plugin/isoWeek"));
1803
- var import_localizedFormat = __toESM(require("dayjs/plugin/localizedFormat"));
1804
- var import_quarterOfYear = __toESM(require("dayjs/plugin/quarterOfYear"));
1805
- var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"));
1806
- var import_timezone = __toESM(require("dayjs/plugin/timezone"));
1807
- var import_utc = __toESM(require("dayjs/plugin/utc"));
1808
- var import_de = require("dayjs/locale/de");
1809
- var import_nl = require("dayjs/locale/nl");
1800
+ var import_luxon = require("luxon");
1810
1801
 
1811
1802
  // src/types/IsDate.ts
1812
1803
  var isDate = (o) => o instanceof Date && !isNaN(o.getTime());
@@ -1838,58 +1829,19 @@ var seconds = {
1838
1829
  };
1839
1830
 
1840
1831
  // src/domain/DateTime.ts
1841
- import_dayjs.default.extend(import_utc.default);
1842
- import_dayjs.default.extend(import_timezone.default);
1843
- import_dayjs.default.extend(import_customParseFormat.default);
1844
- import_dayjs.default.extend(import_localizedFormat.default);
1845
- import_dayjs.default.extend(import_relativeTime.default);
1846
- import_dayjs.default.extend(import_isoWeek.default);
1847
- import_dayjs.default.extend(import_advancedFormat.default);
1848
- import_dayjs.default.extend(import_quarterOfYear.default);
1849
- import_dayjs.default.tz.setDefault("UTC");
1850
- var invalidDate = import_dayjs.default.utc(Number.NaN);
1851
- var isDayjs = (value) => import_dayjs.default.isDayjs(value);
1852
- var isoFormats = [
1853
- "YYYY-MM-DD",
1854
- "YYYY-MM-DDTHH:mm",
1855
- "YYYY-MM-DDTHH:mm:ss",
1856
- "YYYY-MM-DDTHH:mm:ss.SSS",
1857
- "YYYY-MM-DDTHH:mm[Z]",
1858
- "YYYY-MM-DDTHH:mm:ss[Z]",
1859
- "YYYY-MM-DDTHH:mm:ss.SSS[Z]",
1860
- "YYYY-MM-DDTHH:mmZ",
1861
- "YYYY-MM-DDTHH:mmZZ",
1862
- "YYYY-MM-DDTHH:mm:ssZ",
1863
- "YYYY-MM-DDTHH:mm:ssZZ",
1864
- "YYYY-MM-DDTHH:mm:ss.SSSZ",
1865
- "YYYY-MM-DDTHH:mm:ss.SSSZZ"
1866
- ];
1867
- var fixedUnitMilliseconds = {
1868
- day: 864e5,
1869
- days: 864e5,
1870
- week: 6048e5,
1871
- weeks: 6048e5
1872
- };
1873
- var calendarUnitMonths = {
1874
- month: 1,
1875
- months: 1,
1876
- quarter: 3,
1877
- quarters: 3,
1878
- year: 12,
1879
- years: 12
1880
- };
1832
+ import_luxon.Settings.defaultZone = "utc";
1881
1833
  var DateTime = class _DateTime extends Value {
1882
- date;
1834
+ luxon;
1883
1835
  constructor(value, format) {
1884
- const date = choose(value).type(isDayjs, (date2) => date2).type(isDateTime, (dateTime) => dateTime.date).type(isNumber, (timestamp) => import_dayjs.default.utc(timestamp)).type(isDate, (date2) => import_dayjs.default.utc(date2)).type(isString, (string) => string === "" ? invalidDate : format ? parseFormatted(string, format) : parseIso(string)).else(invalidDate);
1885
- super(date.isValid() ? formatDateTime(date) : void 0);
1886
- this.date = date;
1836
+ const luxon = choose(value).type(isString, (v) => format ? import_luxon.DateTime.fromFormat(v, format, { setZone: true }) : import_luxon.DateTime.fromISO(v, { setZone: true })).type(isNumber, (v) => import_luxon.DateTime.fromMillis(v)).type(isDate, (v) => import_luxon.DateTime.fromJSDate(v)).type(isDateTime, (v) => v.luxon).else(value instanceof import_luxon.DateTime ? value : import_luxon.DateTime.fromISO(void 0));
1837
+ super(luxon.toISO() ?? void 0);
1838
+ this.luxon = luxon;
1887
1839
  }
1888
1840
  static get now() {
1889
- return fromDayjs(import_dayjs.default.utc(Date.now()));
1841
+ return new _DateTime(import_luxon.DateTime.utc());
1890
1842
  }
1891
1843
  get isValid() {
1892
- return isDefined(this.value) && this.date.isValid();
1844
+ return isDefined(this.value) && this.utc.isValid;
1893
1845
  }
1894
1846
  /**
1895
1847
  * @deprecated Deprecated in favor for DateTime.from as that also accepts locales and another DateTime
@@ -1910,161 +1862,78 @@ var DateTime = class _DateTime extends Value {
1910
1862
  return this.withZone("Europe/Warsaw");
1911
1863
  }
1912
1864
  get utc() {
1913
- return this.date.utc();
1865
+ return this.luxon.setZone("utc");
1914
1866
  }
1915
1867
  from(dateOrLocale, maybeLocale) {
1916
1868
  return use(
1917
1869
  (isString(dateOrLocale) ? dateOrLocale : maybeLocale) ?? "en",
1918
1870
  (locale) => ifDefined(
1919
1871
  isA(dateOrLocale) ? dateOrLocale : void 0,
1920
- (d) => this.utc.locale(toDayjsLocale(locale)).from(d.utc),
1921
- () => this.utc.locale(toDayjsLocale(locale)).from(import_dayjs.default.utc(Date.now()))
1872
+ (d) => this.utc.setLocale(locale).toRelative({ base: d.utc }),
1873
+ () => this.utc.setLocale(locale).toRelative()
1922
1874
  )
1923
1875
  ) ?? "";
1924
1876
  }
1925
1877
  isAfter(dt2) {
1926
- return this.utc.valueOf() > dt2.utc.valueOf();
1878
+ return this.utc > dt2.utc;
1927
1879
  }
1928
1880
  isBefore(dt2) {
1929
- return this.utc.valueOf() < dt2.utc.valueOf();
1881
+ return this.utc < dt2.utc;
1930
1882
  }
1931
1883
  equals(dt2) {
1932
- return this.utc.valueOf() === dt2.utc.valueOf();
1884
+ return this.utc.hasSame(dt2.utc, "millisecond");
1933
1885
  }
1934
1886
  add(n, unit = "day") {
1935
- return fromDayjs(change(this.date, n, unit, "add"));
1887
+ return new _DateTime(this.luxon.plus(isNumber(n) ? { [unit]: n } : n));
1936
1888
  }
1937
1889
  subtract(n, unit = "day") {
1938
- return fromDayjs(change(this.date, n, unit, "subtract"));
1890
+ return new _DateTime(this.luxon.minus(isNumber(n) ? { [unit]: n } : n));
1939
1891
  }
1940
1892
  diff(other, unit = "day", opts) {
1941
- return Math[opts?.rounding ?? "floor"](this.utc.diff(other.utc, toDayjsUnit(unit), true));
1893
+ return Math[opts?.rounding ?? "floor"](this.utc.diff(other.utc).as(unit));
1942
1894
  }
1943
1895
  startOf(unit = "day") {
1944
- return fromDayjs(this.date.startOf(toDayjsBoundaryUnit(unit)));
1896
+ return new _DateTime(this.luxon.startOf(unit));
1945
1897
  }
1946
1898
  endOf(unit = "day") {
1947
- return fromDayjs(this.date.endOf(toDayjsBoundaryUnit(unit)));
1899
+ return new _DateTime(this.luxon.endOf(unit));
1948
1900
  }
1949
1901
  isWeekend() {
1950
- const day = this.date.day();
1951
- return day === 0 || day === 6;
1902
+ return this.luxon.isWeekend;
1952
1903
  }
1953
1904
  withZone(zone) {
1954
- return fromDayjs(this.date.tz(zone));
1905
+ return new _DateTime(this.luxon.setZone(zone));
1955
1906
  }
1956
1907
  toString() {
1957
1908
  return this.value ?? "";
1958
1909
  }
1959
1910
  toJSON() {
1960
- return this.isValid ? this.utc.format("YYYY-MM-DDTHH:mm:ss.SSS[Z]") : null;
1911
+ return this.utc.toISO();
1961
1912
  }
1962
1913
  toFormat(format) {
1963
- return this.isValid ? this.date.format(toDayjsFormat(format)) : "";
1914
+ return this.luxon.toFormat(format);
1964
1915
  }
1965
1916
  toLocale(locale = "nl-NL", format = "D") {
1966
- if (!this.isValid)
1967
- return "";
1968
- if (format === "D")
1969
- return formatWithIntl(this.date, locale, { year: "numeric", month: "numeric", day: "numeric" });
1970
- if (format === "DDD")
1971
- return formatWithIntl(this.date, locale, { dateStyle: "long" });
1972
- if (format === "ffff") {
1973
- return formatWithIntl(this.date, locale, {
1974
- weekday: "long",
1975
- year: "numeric",
1976
- month: "long",
1977
- day: "numeric",
1978
- hour: "numeric",
1979
- minute: "2-digit",
1980
- timeZoneName: timezoneOf(this.date) ? "long" : "short"
1981
- });
1982
- }
1983
- return this.date.locale(toDayjsLocale(locale)).format(toDayjsFormat(format));
1917
+ return this.luxon.setLocale(locale).toFormat(format);
1984
1918
  }
1985
1919
  toFull(locale) {
1986
1920
  return this.toLocale(locale, "DDD");
1987
1921
  }
1988
1922
  toDate() {
1989
- return this.isValid ? this.utc.toDate() : void 0;
1923
+ return this.isValid ? this.utc.toJSDate() : void 0;
1990
1924
  }
1991
1925
  toEpoch() {
1992
- return this.date.valueOf();
1926
+ return this.luxon.toMillis();
1993
1927
  }
1994
1928
  ago(end = _DateTime.now) {
1995
1929
  return seconds.toText(end.diff(this, "second"));
1996
1930
  }
1997
1931
  withClock(clock) {
1998
- return tryTo(() => [this.toDate(), clock.toDate()]).map(([td, cd]) => new Date(Date.UTC(td.getUTCFullYear(), td.getUTCMonth(), td.getUTCDate(), cd.getUTCHours(), cd.getUTCMinutes(), cd.getUTCSeconds()))).map((d) => new _DateTime(d)).value;
1932
+ return tryTo(() => [this.toDate(), clock.toDate()]).map(([td, cd]) => new Date(td.getFullYear(), td.getMonth(), td.getDate(), cd.getHours(), cd.getMinutes(), cd.getSeconds())).map((d) => new _DateTime(d)).value;
1999
1933
  }
2000
1934
  };
2001
1935
  var isDateTime = (dt2) => isDefined(dt2) && dt2 instanceof DateTime;
2002
1936
  var dt = (dt2) => new DateTime(dt2);
2003
- var parseIso = (value) => {
2004
- const offset = offsetOf(value);
2005
- if (offset) {
2006
- const date = import_dayjs.default.utc(value);
2007
- return date.isValid() ? inOffsetZone(date, offset) : invalidDate;
2008
- }
2009
- return (0, import_dayjs.default)(value, isoFormats, true).isValid() ? import_dayjs.default.utc(value) : invalidDate;
2010
- };
2011
- var parseFormatted = (value, format) => {
2012
- const dayjsFormat = toDayjsFormat(format);
2013
- const offset = offsetOf(value);
2014
- if (format.includes("ZZZ") && offset) {
2015
- const iso = import_dayjs.default.utc(value);
2016
- return iso.isValid() ? inOffsetZone(iso, offset) : invalidDate;
2017
- }
2018
- return import_dayjs.default.utc(value, dayjsFormat, true);
2019
- };
2020
- var offsetOf = (value) => value.match(/([+-]\d{2}:?\d{2})$/)?.[1];
2021
- var fromDayjs = (date) => new DateTime(date);
2022
- var formatDateTime = (date) => {
2023
- const formatted = date.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
2024
- return timezoneOf(date) ? formatted : formatted.replace("+00:00", "Z");
2025
- };
2026
- var change = (date, value, unit, direction) => {
2027
- if (isNumber(value))
2028
- return changeUnit(date, value, unit, direction);
2029
- return Object.entries(value).reduce((result, [durationUnit, durationValue]) => changeUnit(result, durationValue ?? 0, durationUnit, direction), date);
2030
- };
2031
- var changeUnit = (date, value, unit, direction) => {
2032
- const amount = direction === "add" ? value : -value;
2033
- const milliseconds = fixedUnitMilliseconds[unit];
2034
- const months = calendarUnitMonths[unit];
2035
- if (months && !Number.isInteger(value))
2036
- return addMonths(date, amount * months);
2037
- if (milliseconds && !Number.isInteger(value))
2038
- return date.add(amount * milliseconds, "millisecond");
2039
- return date.add(amount, toDayjsUnit(unit));
2040
- };
2041
- var addMonths = (date, months) => {
2042
- const wholeMonths = Math.trunc(months);
2043
- const fraction = months - wholeMonths;
2044
- const shifted = date.add(wholeMonths, "month");
2045
- if (fraction === 0)
2046
- return shifted;
2047
- const next = shifted.add(months > 0 ? 1 : -1, "month");
2048
- return shifted.add((next.valueOf() - shifted.valueOf()) * Math.abs(fraction), "millisecond");
2049
- };
2050
- var inOffsetZone = (date, offset) => offsetToTimeZone(offset).map((zone) => date.tz(zone)).or(date.utcOffset(offset));
2051
- var offsetToTimeZone = (offset) => tryTo(() => {
2052
- const [, sign, hours, minutes] = offset.match(/^([+-])(\d{2}):?(\d{2})$/) ?? [];
2053
- if (minutes !== "00")
2054
- throw new Error();
2055
- if (hours === "00")
2056
- return "UTC";
2057
- return `Etc/GMT${sign === "+" ? "-" : "+"}${Number(hours)}`;
2058
- });
2059
- var toDayjsUnit = (unit) => unit.replace(/s$/, "");
2060
- var toDayjsBoundaryUnit = (unit) => {
2061
- const dayjsUnit = toDayjsUnit(unit);
2062
- return dayjsUnit === "week" ? "isoWeek" : dayjsUnit;
2063
- };
2064
- var toDayjsFormat = (format) => format.replace(/'([^']+)'/g, "[$1]").replace(/EEE/g, "ddd").replace(/yyyy/g, "YYYY").replace(/dd/g, "DD").replace(/LLL/g, "MMM").replace(/ZZZ/g, "ZZ").replace(/hh/g, "HH");
2065
- var toDayjsLocale = (locale) => locale.toLowerCase().split("-")[0];
2066
- var formatWithIntl = (date, locale, options) => new Intl.DateTimeFormat(locale, { ...options, timeZone: timezoneOf(date) ?? "UTC" }).format(date.toDate());
2067
- var timezoneOf = (date) => date.$x?.$timezone;
2068
1937
 
2069
1938
  // src/validation/Contraints.ts
2070
1939
  var constraint = (c, message) => (subject, property) => {
@@ -3429,6 +3298,9 @@ var Environment = class _Environment extends Enum {
3429
3298
  static Prd = new _Environment("Production", "prd");
3430
3299
  };
3431
3300
 
3301
+ // src/types/ErrorOrigin.ts
3302
+ var errorMessage = (e) => choose(e).type(isResponse, (r) => r.body.error?.errors?.[0]?.message ?? r.body.error?.message).type(isException, (ex) => asString(ex.reason) || ex.message).type(isResults, (rs) => rs.results[0]?.message).type(isError, (e2) => e2.message).type(isString, (s) => s).else(() => void 0);
3303
+
3432
3304
  // src/types/Falsy.ts
3433
3305
  var isFalsy = (v) => !v;
3434
3306
  var isTruthy = (v) => !isFalsy(v);
@@ -3526,7 +3398,7 @@ var timezones = [
3526
3398
  "Europe/Warsaw",
3527
3399
  "America/New_York"
3528
3400
  ];
3529
- var timezone2 = {
3401
+ var timezone = {
3530
3402
  utc: "utc",
3531
3403
  amsterdam: "Europe/Amsterdam",
3532
3404
  berlin: "Europe/Berlin",
@@ -3537,8 +3409,8 @@ var timezone2 = {
3537
3409
  warsaw: "Europe/Warsaw",
3538
3410
  newYork: "America/New_York"
3539
3411
  };
3540
- var utc2 = timezone2.utc;
3541
- var ams = timezone2.amsterdam;
3412
+ var utc = timezone.utc;
3413
+ var ams = timezone.amsterdam;
3542
3414
 
3543
3415
  // src/types/Uri.ts
3544
3416
  var toSegment = (key, {
@@ -3655,7 +3527,7 @@ function dir(t) {
3655
3527
  }
3656
3528
 
3657
3529
  // src/utils/Period.ts
3658
- var toStartEnd = ({ period: period2, start, end, zone = utc2 }) => {
3530
+ var toStartEnd = ({ period: period2, start, end, zone = utc }) => {
3659
3531
  const today = DateTime.now.withZone(zone).startOf("day");
3660
3532
  return choose(period2).equals("today", { start: today, end: today.endOf("day") }).equals("yesterday", { start: today.subtract(1, "day"), end: today }).equals("tomorrow", { start: today.add(1, "day"), end: today.add(1, "day").endOf("day") }).equals("this-week", { start: today.startOf("week"), end: today.endOf("week") }).equals("last-seven-days", { start: today.subtract(6, "day"), end: today.endOf("day") }).equals("last-week", {
3661
3533
  start: today.subtract(1, "week").startOf("week"),
@@ -3846,6 +3718,7 @@ var wait = (millis) => Wait.wait(millis);
3846
3718
  dt,
3847
3719
  entries,
3848
3720
  equals,
3721
+ errorMessage,
3849
3722
  extractKeys,
3850
3723
  future,
3851
3724
  gt,