@thisisagile/easy 18.11.0 → 18.11.1

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. [luxon](https://moment.github.io/luxon/#/) 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. [Day.js](https://day.js.org/) is used internally.
128
128
 
129
129
  A few examples of DateTime:
130
130
 
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-TNLJ45P5.mjs";
5
5
  import {
6
6
  DateTime
7
- } from "./chunk-EOHHPAAY.mjs";
7
+ } from "./chunk-GRDUTNMZ.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-TMVZSMUA.mjs.map
48
+ //# sourceMappingURL=chunk-5VP4WNID.mjs.map
@@ -0,0 +1,272 @@
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 dayjs from "dayjs";
29
+ import advancedFormat from "dayjs/plugin/advancedFormat";
30
+ import customParseFormat from "dayjs/plugin/customParseFormat";
31
+ import isoWeek from "dayjs/plugin/isoWeek";
32
+ import localizedFormat from "dayjs/plugin/localizedFormat";
33
+ import quarterOfYear from "dayjs/plugin/quarterOfYear";
34
+ import relativeTime from "dayjs/plugin/relativeTime";
35
+ import timezone from "dayjs/plugin/timezone";
36
+ import utc from "dayjs/plugin/utc";
37
+ import "dayjs/locale/de";
38
+ import "dayjs/locale/nl";
39
+ dayjs.extend(utc);
40
+ dayjs.extend(timezone);
41
+ dayjs.extend(customParseFormat);
42
+ dayjs.extend(localizedFormat);
43
+ dayjs.extend(relativeTime);
44
+ dayjs.extend(isoWeek);
45
+ dayjs.extend(advancedFormat);
46
+ dayjs.extend(quarterOfYear);
47
+ dayjs.tz.setDefault("UTC");
48
+ var invalidDate = dayjs.utc(Number.NaN);
49
+ var isDayjs = (value) => dayjs.isDayjs(value);
50
+ var isoFormats = [
51
+ "YYYY-MM-DD",
52
+ "YYYY-MM-DDTHH:mm",
53
+ "YYYY-MM-DDTHH:mm:ss",
54
+ "YYYY-MM-DDTHH:mm:ss.SSS",
55
+ "YYYY-MM-DDTHH:mm[Z]",
56
+ "YYYY-MM-DDTHH:mm:ss[Z]",
57
+ "YYYY-MM-DDTHH:mm:ss.SSS[Z]",
58
+ "YYYY-MM-DDTHH:mmZ",
59
+ "YYYY-MM-DDTHH:mmZZ",
60
+ "YYYY-MM-DDTHH:mm:ssZ",
61
+ "YYYY-MM-DDTHH:mm:ssZZ",
62
+ "YYYY-MM-DDTHH:mm:ss.SSSZ",
63
+ "YYYY-MM-DDTHH:mm:ss.SSSZZ"
64
+ ];
65
+ var fixedUnitMilliseconds = {
66
+ day: 864e5,
67
+ days: 864e5,
68
+ week: 6048e5,
69
+ weeks: 6048e5
70
+ };
71
+ var calendarUnitMonths = {
72
+ month: 1,
73
+ months: 1,
74
+ quarter: 3,
75
+ quarters: 3,
76
+ year: 12,
77
+ years: 12
78
+ };
79
+ var DateTime = class _DateTime extends Value {
80
+ date;
81
+ constructor(value, format) {
82
+ const date = choose(value).type(isDayjs, (date2) => date2).type(isDateTime, (dateTime) => dateTime.date).type(isNumber, (timestamp) => dayjs.utc(timestamp)).type(isDate, (date2) => dayjs.utc(date2)).type(isString, (string) => string === "" ? invalidDate : format ? parseFormatted(string, format) : parseIso(string)).else(invalidDate);
83
+ super(date.isValid() ? formatDateTime(date) : void 0);
84
+ this.date = date;
85
+ }
86
+ static get now() {
87
+ return fromDayjs(dayjs.utc(Date.now()));
88
+ }
89
+ get isValid() {
90
+ return isDefined(this.value) && this.date.isValid();
91
+ }
92
+ /**
93
+ * @deprecated Deprecated in favor for DateTime.from as that also accepts locales and another DateTime
94
+ */
95
+ get fromNow() {
96
+ return this.from();
97
+ }
98
+ get inAmsterdam() {
99
+ return this.withZone("Europe/Amsterdam");
100
+ }
101
+ get inNewYork() {
102
+ return this.withZone("America/New_York");
103
+ }
104
+ get inLondon() {
105
+ return this.withZone("Europe/London");
106
+ }
107
+ get inWarsaw() {
108
+ return this.withZone("Europe/Warsaw");
109
+ }
110
+ get utc() {
111
+ return this.date.utc();
112
+ }
113
+ from(dateOrLocale, maybeLocale) {
114
+ return use(
115
+ (isString(dateOrLocale) ? dateOrLocale : maybeLocale) ?? "en",
116
+ (locale) => ifDefined(
117
+ isA(dateOrLocale) ? dateOrLocale : void 0,
118
+ (d) => this.utc.locale(toDayjsLocale(locale)).from(d.utc),
119
+ () => this.utc.locale(toDayjsLocale(locale)).from(dayjs.utc(Date.now()))
120
+ )
121
+ ) ?? "";
122
+ }
123
+ isAfter(dt2) {
124
+ return this.utc.valueOf() > dt2.utc.valueOf();
125
+ }
126
+ isBefore(dt2) {
127
+ return this.utc.valueOf() < dt2.utc.valueOf();
128
+ }
129
+ equals(dt2) {
130
+ return this.utc.valueOf() === dt2.utc.valueOf();
131
+ }
132
+ add(n, unit = "day") {
133
+ return fromDayjs(change(this.date, n, unit, "add"));
134
+ }
135
+ subtract(n, unit = "day") {
136
+ return fromDayjs(change(this.date, n, unit, "subtract"));
137
+ }
138
+ diff(other, unit = "day", opts) {
139
+ return Math[opts?.rounding ?? "floor"](this.utc.diff(other.utc, toDayjsUnit(unit), true));
140
+ }
141
+ startOf(unit = "day") {
142
+ return fromDayjs(this.date.startOf(toDayjsBoundaryUnit(unit)));
143
+ }
144
+ endOf(unit = "day") {
145
+ return fromDayjs(this.date.endOf(toDayjsBoundaryUnit(unit)));
146
+ }
147
+ isWeekend() {
148
+ const day = this.date.day();
149
+ return day === 0 || day === 6;
150
+ }
151
+ withZone(zone) {
152
+ return fromDayjs(this.date.tz(zone));
153
+ }
154
+ toString() {
155
+ return this.value ?? "";
156
+ }
157
+ toJSON() {
158
+ return this.isValid ? this.utc.format("YYYY-MM-DDTHH:mm:ss.SSS[Z]") : null;
159
+ }
160
+ toFormat(format) {
161
+ return this.isValid ? this.date.format(toDayjsFormat(format)) : "";
162
+ }
163
+ toLocale(locale = "nl-NL", format = "D") {
164
+ if (!this.isValid)
165
+ return "";
166
+ if (format === "D")
167
+ return formatWithIntl(this.date, locale, { year: "numeric", month: "numeric", day: "numeric" });
168
+ if (format === "DDD")
169
+ return formatWithIntl(this.date, locale, { dateStyle: "long" });
170
+ if (format === "ffff") {
171
+ return formatWithIntl(this.date, locale, {
172
+ weekday: "long",
173
+ year: "numeric",
174
+ month: "long",
175
+ day: "numeric",
176
+ hour: "numeric",
177
+ minute: "2-digit",
178
+ timeZoneName: timezoneOf(this.date) ? "long" : "short"
179
+ });
180
+ }
181
+ return this.date.locale(toDayjsLocale(locale)).format(toDayjsFormat(format));
182
+ }
183
+ toFull(locale) {
184
+ return this.toLocale(locale, "DDD");
185
+ }
186
+ toDate() {
187
+ return this.isValid ? this.utc.toDate() : void 0;
188
+ }
189
+ toEpoch() {
190
+ return this.date.valueOf();
191
+ }
192
+ ago(end = _DateTime.now) {
193
+ return seconds.toText(end.diff(this, "second"));
194
+ }
195
+ withClock(clock) {
196
+ 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;
197
+ }
198
+ };
199
+ var isDateTime = (dt2) => isDefined(dt2) && dt2 instanceof DateTime;
200
+ var dt = (dt2) => new DateTime(dt2);
201
+ var parseIso = (value) => {
202
+ const offset = offsetOf(value);
203
+ if (offset) {
204
+ const date = dayjs.utc(value);
205
+ return date.isValid() ? inOffsetZone(date, offset) : invalidDate;
206
+ }
207
+ return dayjs(value, isoFormats, true).isValid() ? dayjs.utc(value) : invalidDate;
208
+ };
209
+ var parseFormatted = (value, format) => {
210
+ const dayjsFormat = toDayjsFormat(format);
211
+ const offset = offsetOf(value);
212
+ if (format.includes("ZZZ") && offset) {
213
+ const iso = dayjs.utc(value);
214
+ return iso.isValid() ? inOffsetZone(iso, offset) : invalidDate;
215
+ }
216
+ return dayjs.utc(value, dayjsFormat, true);
217
+ };
218
+ var offsetOf = (value) => value.match(/([+-]\d{2}:?\d{2})$/)?.[1];
219
+ var fromDayjs = (date) => new DateTime(date);
220
+ var formatDateTime = (date) => {
221
+ const formatted = date.format("YYYY-MM-DDTHH:mm:ss.SSSZ");
222
+ return timezoneOf(date) ? formatted : formatted.replace("+00:00", "Z");
223
+ };
224
+ var change = (date, value, unit, direction) => {
225
+ if (isNumber(value))
226
+ return changeUnit(date, value, unit, direction);
227
+ return Object.entries(value).reduce((result, [durationUnit, durationValue]) => changeUnit(result, durationValue ?? 0, durationUnit, direction), date);
228
+ };
229
+ var changeUnit = (date, value, unit, direction) => {
230
+ const amount = direction === "add" ? value : -value;
231
+ const milliseconds = fixedUnitMilliseconds[unit];
232
+ const months = calendarUnitMonths[unit];
233
+ if (months && !Number.isInteger(value))
234
+ return addMonths(date, amount * months);
235
+ if (milliseconds && !Number.isInteger(value))
236
+ return date.add(amount * milliseconds, "millisecond");
237
+ return date.add(amount, toDayjsUnit(unit));
238
+ };
239
+ var addMonths = (date, months) => {
240
+ const wholeMonths = Math.trunc(months);
241
+ const fraction = months - wholeMonths;
242
+ const shifted = date.add(wholeMonths, "month");
243
+ if (fraction === 0)
244
+ return shifted;
245
+ const next = shifted.add(months > 0 ? 1 : -1, "month");
246
+ return shifted.add((next.valueOf() - shifted.valueOf()) * Math.abs(fraction), "millisecond");
247
+ };
248
+ var inOffsetZone = (date, offset) => offsetToTimeZone(offset).map((zone) => date.tz(zone)).or(date.utcOffset(offset));
249
+ var offsetToTimeZone = (offset) => tryTo(() => {
250
+ const [, sign, hours, minutes] = offset.match(/^([+-])(\d{2}):?(\d{2})$/) ?? [];
251
+ if (minutes !== "00")
252
+ throw new Error();
253
+ if (hours === "00")
254
+ return "UTC";
255
+ return `Etc/GMT${sign === "+" ? "-" : "+"}${Number(hours)}`;
256
+ });
257
+ var toDayjsUnit = (unit) => unit.replace(/s$/, "");
258
+ var toDayjsBoundaryUnit = (unit) => {
259
+ const dayjsUnit = toDayjsUnit(unit);
260
+ return dayjsUnit === "week" ? "isoWeek" : dayjsUnit;
261
+ };
262
+ 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");
263
+ var toDayjsLocale = (locale) => locale.toLowerCase().split("-")[0];
264
+ var formatWithIntl = (date, locale, options) => new Intl.DateTimeFormat(locale, { ...options, timeZone: timezoneOf(date) ?? "UTC" }).format(date.toDate());
265
+ var timezoneOf = (date) => date.$x?.$timezone;
266
+
267
+ export {
268
+ DateTime,
269
+ isDateTime,
270
+ dt
271
+ };
272
+ //# sourceMappingURL=chunk-GRDUTNMZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/domain/DateTime.ts"],"sourcesContent":["import dayjs, { Dayjs, ManipulateType, OpUnitType, QUnitType } from 'dayjs';\nimport advancedFormat from 'dayjs/plugin/advancedFormat';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport isoWeek from 'dayjs/plugin/isoWeek';\nimport localizedFormat from 'dayjs/plugin/localizedFormat';\nimport quarterOfYear from 'dayjs/plugin/quarterOfYear';\nimport relativeTime from 'dayjs/plugin/relativeTime';\nimport timezone from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\nimport 'dayjs/locale/de';\nimport 'dayjs/locale/nl';\nimport { Value } from '../types/Value';\nimport { Optional } from '../types/Types';\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';\nimport { choose } from '../types/Case';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.extend(customParseFormat);\ndayjs.extend(localizedFormat);\ndayjs.extend(relativeTime);\ndayjs.extend(isoWeek);\ndayjs.extend(advancedFormat);\ndayjs.extend(quarterOfYear);\ndayjs.tz.setDefault('UTC');\n\nexport type DateTimeUnit = 'year' | 'quarter' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';\nexport type DurationUnit =\n | DateTimeUnit\n | 'years'\n | 'quarters'\n | 'months'\n | 'weeks'\n | 'days'\n | 'hours'\n | 'minutes'\n | 'seconds'\n | 'milliseconds';\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\ntype DateTimeConstructorInput = DatetimeInput | Dayjs;\ntype ZonedDayjs = Dayjs & { $x?: { $timezone?: string } };\n\nconst invalidDate = dayjs.utc(Number.NaN);\nconst isDayjs = (value: unknown): value is Dayjs => dayjs.isDayjs(value);\nconst isoFormats = [\n 'YYYY-MM-DD',\n 'YYYY-MM-DDTHH:mm',\n 'YYYY-MM-DDTHH:mm:ss',\n 'YYYY-MM-DDTHH:mm:ss.SSS',\n 'YYYY-MM-DDTHH:mm[Z]',\n 'YYYY-MM-DDTHH:mm:ss[Z]',\n 'YYYY-MM-DDTHH:mm:ss.SSS[Z]',\n 'YYYY-MM-DDTHH:mmZ',\n 'YYYY-MM-DDTHH:mmZZ',\n 'YYYY-MM-DDTHH:mm:ssZ',\n 'YYYY-MM-DDTHH:mm:ssZZ',\n 'YYYY-MM-DDTHH:mm:ss.SSSZ',\n 'YYYY-MM-DDTHH:mm:ss.SSSZZ',\n];\nconst fixedUnitMilliseconds: Partial<Record<DurationUnit, number>> = {\n day: 86400000,\n days: 86400000,\n week: 604800000,\n weeks: 604800000,\n};\nconst calendarUnitMonths: Partial<Record<DurationUnit, number>> = {\n month: 1,\n months: 1,\n quarter: 3,\n quarters: 3,\n year: 12,\n years: 12,\n};\n\nexport class DateTime extends Value<Optional<string>> {\n protected readonly date: Dayjs;\n\n constructor(value?: DatetimeInput);\n constructor(value?: string, format?: string);\n constructor(value?: DateTimeConstructorInput, format?: string) {\n const date = choose<DateTimeConstructorInput | undefined>(value)\n .type(isDayjs, date => date)\n .type(isDateTime, dateTime => dateTime.date)\n .type(isNumber, timestamp => dayjs.utc(timestamp))\n .type(isDate, date => dayjs.utc(date))\n .type(isString, string => (string === '' ? invalidDate : format ? parseFormatted(string, format) : parseIso(string)))\n .else(invalidDate);\n\n super(date.isValid() ? formatDateTime(date) : undefined);\n this.date = date;\n }\n\n static get now(): DateTime {\n return fromDayjs(dayjs.utc(Date.now()));\n }\n\n get isValid(): boolean {\n return isDefined(this.value) && this.date.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(): Dayjs {\n return this.date.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.locale(toDayjsLocale(locale)).from(d.utc),\n () => this.utc.locale(toDayjsLocale(locale)).from(dayjs.utc(Date.now()))\n )\n ) ?? ''\n );\n }\n\n isAfter(dt: DateTime): boolean {\n return this.utc.valueOf() > dt.utc.valueOf();\n }\n\n isBefore(dt: DateTime): boolean {\n return this.utc.valueOf() < dt.utc.valueOf();\n }\n\n equals(dt: DateTime): boolean {\n return this.utc.valueOf() === dt.utc.valueOf();\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 fromDayjs(change(this.date, n, unit, 'add'));\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 fromDayjs(change(this.date, n, unit, 'subtract'));\n }\n\n diff(other: DateTime, unit: DateTimeUnit = 'day', opts?: DiffOptions): number {\n return Math[opts?.rounding ?? 'floor'](this.utc.diff(other.utc, toDayjsUnit(unit) as QUnitType | OpUnitType, true));\n }\n\n startOf(unit: DateTimeUnit = 'day'): DateTime {\n return fromDayjs(this.date.startOf(toDayjsBoundaryUnit(unit)));\n }\n\n endOf(unit: DateTimeUnit = 'day'): DateTime {\n return fromDayjs(this.date.endOf(toDayjsBoundaryUnit(unit)));\n }\n\n isWeekend(): boolean {\n const day = this.date.day();\n return day === 0 || day === 6;\n }\n\n withZone(zone: string): DateTime {\n return fromDayjs(this.date.tz(zone));\n }\n\n toString(): string {\n return this.value ?? '';\n }\n\n toJSON(): JsonValue {\n return this.isValid ? this.utc.format('YYYY-MM-DDTHH:mm:ss.SSS[Z]') : null;\n }\n\n toFormat(format: string): string {\n return this.isValid ? this.date.format(toDayjsFormat(format)) : '';\n }\n\n toLocale(locale = 'nl-NL', format = 'D'): string {\n if (!this.isValid) return '';\n\n if (format === 'D') return formatWithIntl(this.date, locale, { year: 'numeric', month: 'numeric', day: 'numeric' });\n if (format === 'DDD') return formatWithIntl(this.date, locale, { dateStyle: 'long' });\n if (format === 'ffff') {\n return formatWithIntl(this.date, locale, {\n weekday: 'long',\n year: 'numeric',\n month: 'long',\n day: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n timeZoneName: timezoneOf(this.date) ? 'long' : 'short',\n });\n }\n return this.date.locale(toDayjsLocale(locale)).format(toDayjsFormat(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.toDate() : undefined;\n }\n\n toEpoch(): number {\n return this.date.valueOf();\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(Date.UTC(td.getUTCFullYear(), td.getUTCMonth(), td.getUTCDate(), cd.getUTCHours(), cd.getUTCMinutes(), cd.getUTCSeconds())))\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\nconst parseIso = (value: string): Dayjs => {\n const offset = offsetOf(value);\n if (offset) {\n const date = dayjs.utc(value);\n return date.isValid() ? inOffsetZone(date, offset) : invalidDate;\n }\n return dayjs(value, isoFormats, true).isValid() ? dayjs.utc(value) : invalidDate;\n};\n\nconst parseFormatted = (value: string, format: string): Dayjs => {\n const dayjsFormat = toDayjsFormat(format);\n const offset = offsetOf(value);\n if (format.includes('ZZZ') && offset) {\n const iso = dayjs.utc(value);\n return iso.isValid() ? inOffsetZone(iso, offset) : invalidDate;\n }\n return dayjs.utc(value, dayjsFormat, true);\n};\n\nconst offsetOf = (value: string): string | undefined => value.match(/([+-]\\d{2}:?\\d{2})$/)?.[1];\n\nconst fromDayjs = (date: Dayjs): DateTime => new DateTime(date as unknown as DatetimeInput);\n\nconst formatDateTime = (date: Dayjs): string => {\n const formatted = date.format('YYYY-MM-DDTHH:mm:ss.SSSZ');\n return timezoneOf(date) ? formatted : formatted.replace('+00:00', 'Z');\n};\n\nconst change = (date: Dayjs, value: number | Duration, unit: DurationUnit, direction: 'add' | 'subtract'): Dayjs => {\n if (isNumber(value)) return changeUnit(date, value, unit, direction);\n return Object.entries(value).reduce((result, [durationUnit, durationValue]) => changeUnit(result, durationValue ?? 0, durationUnit as DurationUnit, direction), date);\n};\n\nconst changeUnit = (date: Dayjs, value: number, unit: DurationUnit, direction: 'add' | 'subtract'): Dayjs => {\n const amount = direction === 'add' ? value : -value;\n const milliseconds = fixedUnitMilliseconds[unit];\n const months = calendarUnitMonths[unit];\n\n if (months && !Number.isInteger(value)) return addMonths(date, amount * months);\n if (milliseconds && !Number.isInteger(value)) return date.add(amount * milliseconds, 'millisecond');\n return date.add(amount, toDayjsUnit(unit));\n};\n\nconst addMonths = (date: Dayjs, months: number): Dayjs => {\n const wholeMonths = Math.trunc(months);\n const fraction = months - wholeMonths;\n const shifted = date.add(wholeMonths, 'month');\n if (fraction === 0) return shifted;\n\n const next = shifted.add(months > 0 ? 1 : -1, 'month');\n return shifted.add((next.valueOf() - shifted.valueOf()) * Math.abs(fraction), 'millisecond');\n};\n\nconst inOffsetZone = (date: Dayjs, offset: string): Dayjs => offsetToTimeZone(offset).map(zone => date.tz(zone)).or(date.utcOffset(offset));\n\nconst offsetToTimeZone = (offset: string) =>\n tryTo(() => {\n const [, sign, hours, minutes] = offset.match(/^([+-])(\\d{2}):?(\\d{2})$/) ?? [];\n if (minutes !== '00') throw new Error();\n if (hours === '00') return 'UTC';\n return `Etc/GMT${sign === '+' ? '-' : '+'}${Number(hours)}`;\n });\n\nconst toDayjsUnit = (unit: DurationUnit): ManipulateType => unit.replace(/s$/, '') as ManipulateType;\n\nconst toDayjsBoundaryUnit = (unit: DateTimeUnit): OpUnitType => {\n const dayjsUnit = toDayjsUnit(unit);\n return (dayjsUnit === 'week' ? 'isoWeek' : dayjsUnit) as OpUnitType;\n};\n\nconst toDayjsFormat = (format: string): string =>\n format\n .replace(/'([^']+)'/g, '[$1]')\n .replace(/EEE/g, 'ddd')\n .replace(/yyyy/g, 'YYYY')\n .replace(/dd/g, 'DD')\n .replace(/LLL/g, 'MMM')\n .replace(/ZZZ/g, 'ZZ')\n .replace(/hh/g, 'HH');\n\nconst toDayjsLocale = (locale: string): string => locale.toLowerCase().split('-')[0];\n\nconst formatWithIntl = (date: Dayjs, locale: string, options: Intl.DateTimeFormatOptions): string =>\n new Intl.DateTimeFormat(locale, { ...options, timeZone: timezoneOf(date) ?? 'UTC' }).format(date.toDate());\n\nconst timezoneOf = (date: Dayjs): string | undefined => (date as ZonedDayjs).$x?.$timezone;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAA6D;AACpE,OAAO,oBAAoB;AAC3B,OAAO,uBAAuB;AAC9B,OAAO,aAAa;AACpB,OAAO,qBAAqB;AAC5B,OAAO,mBAAmB;AAC1B,OAAO,kBAAkB;AACzB,OAAO,cAAc;AACrB,OAAO,SAAS;AAChB,OAAO;AACP,OAAO;AAaP,MAAM,OAAO,GAAG;AAChB,MAAM,OAAO,QAAQ;AACrB,MAAM,OAAO,iBAAiB;AAC9B,MAAM,OAAO,eAAe;AAC5B,MAAM,OAAO,YAAY;AACzB,MAAM,OAAO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Y,EAAE,MAAM,GAAG,EAAE,CAAC;AAEnF,IAAM,iBAAiB,CAAC,MAAa,QAAgB,YACnD,IAAI,KAAK,eAAe,QAAQ,EAAE,GAAG,SAAS,UAAU,WAAW,IAAI,KAAK,MAAM,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;AAE3G,IAAM,aAAa,CAAC,SAAqC,KAAoB,IAAI;","names":["date","dt"]}
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  Audit
3
- } from "../chunk-TMVZSMUA.mjs";
3
+ } from "../chunk-5VP4WNID.mjs";
4
4
  import "../chunk-TNLJ45P5.mjs";
5
- import "../chunk-EOHHPAAY.mjs";
5
+ import "../chunk-GRDUTNMZ.mjs";
6
6
  import "../chunk-RF23BV6J.mjs";
7
7
  import "../chunk-ADJAEGCT.mjs";
8
8
  import "../chunk-BSN5WGZ6.mjs";
@@ -1,16 +1,18 @@
1
- import { DateTime as LuxonDateTime, DateTimeUnit as LuxonDateTimeUnit, DurationUnit as LuxonDurationUnit } from 'luxon';
1
+ import { Dayjs } from 'dayjs';
2
+ import 'dayjs/locale/de';
3
+ import 'dayjs/locale/nl';
2
4
  import { Value } from '../types/Value';
3
5
  import { Optional } from '../types/Types';
4
6
  import { JsonValue } from '../types/Json';
5
- export type DateTimeUnit = LuxonDateTimeUnit;
6
- export type DurationUnit = LuxonDurationUnit;
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';
7
9
  export type Duration = Partial<Record<DurationUnit, number>>;
8
10
  export type DiffOptions = {
9
11
  rounding: 'floor' | 'ceil' | 'round';
10
12
  };
11
13
  export type DatetimeInput = string | number | Date | DateTime | null;
12
14
  export declare class DateTime extends Value<Optional<string>> {
13
- protected readonly luxon: LuxonDateTime;
15
+ protected readonly date: Dayjs;
14
16
  constructor(value?: DatetimeInput);
15
17
  constructor(value?: string, format?: string);
16
18
  static get now(): DateTime;
@@ -20,7 +22,7 @@ export declare class DateTime extends Value<Optional<string>> {
20
22
  get inNewYork(): DateTime;
21
23
  get inLondon(): DateTime;
22
24
  get inWarsaw(): DateTime;
23
- protected get utc(): LuxonDateTime;
25
+ protected get utc(): Dayjs;
24
26
  from(locale?: string): string;
25
27
  from(date?: DateTime, locale?: string): string;
26
28
  isAfter(dt: DateTime): boolean;
@@ -2,7 +2,7 @@ import {
2
2
  DateTime,
3
3
  dt,
4
4
  isDateTime
5
- } from "../chunk-EOHHPAAY.mjs";
5
+ } from "../chunk-GRDUTNMZ.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-TMVZSMUA.mjs";
7
+ } from "../chunk-5VP4WNID.mjs";
8
8
  import {
9
9
  required
10
10
  } from "../chunk-TNLJ45P5.mjs";
11
- import "../chunk-EOHHPAAY.mjs";
11
+ import "../chunk-GRDUTNMZ.mjs";
12
12
  import "../chunk-RF23BV6J.mjs";
13
13
  import "../chunk-ADJAEGCT.mjs";
14
14
  import {