@rikdotcodes/temporal-polyfill 0.3.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.
@@ -0,0 +1,587 @@
1
+ "use strict";
2
+
3
+ function createSlotClass(branding, construct, getters, methods, staticMethods) {
4
+ function Class(...args) {
5
+ if (!(this instanceof Class)) {
6
+ throw new TypeError(internal.invalidCallingContext);
7
+ }
8
+ setSlots(this, construct(...args));
9
+ }
10
+ function bindMethod(method, methodName) {
11
+ return Object.defineProperties((function(...args) {
12
+ return method.call(this, getSpecificSlots(this), ...args);
13
+ }), internal.createNameDescriptors(methodName));
14
+ }
15
+ function getSpecificSlots(obj) {
16
+ const slots = getSlots(obj);
17
+ if (!slots || slots.branding !== branding) {
18
+ throw new TypeError(internal.invalidCallingContext);
19
+ }
20
+ return slots;
21
+ }
22
+ return Object.defineProperties(Class.prototype, {
23
+ ...internal.createGetterDescriptors(internal.mapProps(bindMethod, getters)),
24
+ ...internal.createPropDescriptors(internal.mapProps(bindMethod, methods)),
25
+ ...internal.createStringTagDescriptors("Temporal." + branding)
26
+ }), Object.defineProperties(Class, {
27
+ ...internal.createPropDescriptors(staticMethods),
28
+ ...internal.createNameDescriptors(branding)
29
+ }), [ Class, slots => {
30
+ const instance = Object.create(Class.prototype);
31
+ return setSlots(instance, slots), instance;
32
+ }, getSpecificSlots ];
33
+ }
34
+
35
+ function rejectInvalidBag(bag) {
36
+ if (getSlots(bag) || void 0 !== bag.calendar || void 0 !== bag.timeZone) {
37
+ throw new TypeError(internal.invalidBag);
38
+ }
39
+ return bag;
40
+ }
41
+
42
+ function getCalendarIdFromBag(bag) {
43
+ return extractCalendarIdFromBag(bag) || internal.isoCalendarId;
44
+ }
45
+
46
+ function extractCalendarIdFromBag(bag) {
47
+ const {calendar: calendarArg} = bag;
48
+ if (void 0 !== calendarArg) {
49
+ return refineCalendarArg(calendarArg);
50
+ }
51
+ }
52
+
53
+ function refineCalendarArg(arg) {
54
+ if (internal.isObjectLike(arg)) {
55
+ const {calendar: calendar} = getSlots(arg) || {};
56
+ if (!calendar) {
57
+ throw new TypeError(internal.invalidCalendar(arg));
58
+ }
59
+ return calendar;
60
+ }
61
+ return (arg => internal.resolveCalendarId(internal.parseCalendarId(internal.requireString(arg))))(arg);
62
+ }
63
+
64
+ function createCalendarGetters(methodNameMap) {
65
+ const methods = {};
66
+ for (const methodName in methodNameMap) {
67
+ methods[methodName] = slots => {
68
+ const {calendar: calendar} = slots;
69
+ return internal.createNativeStandardOps(calendar)[methodName](slots);
70
+ };
71
+ }
72
+ return methods;
73
+ }
74
+
75
+ function neverValueOf() {
76
+ throw new TypeError(internal.forbiddenValueOf);
77
+ }
78
+
79
+ function refineTimeZoneArg(arg) {
80
+ if (internal.isObjectLike(arg)) {
81
+ const {timeZone: timeZone} = getSlots(arg) || {};
82
+ if (!timeZone) {
83
+ throw new TypeError(internal.invalidTimeZone(arg));
84
+ }
85
+ return timeZone;
86
+ }
87
+ return (arg => internal.resolveTimeZoneId(internal.parseTimeZoneId(internal.requireString(arg))))(arg);
88
+ }
89
+
90
+ function toDurationSlots(arg) {
91
+ if (internal.isObjectLike(arg)) {
92
+ const slots = getSlots(arg);
93
+ return slots && slots.branding === internal.DurationBranding ? slots : internal.refineDurationBag(arg);
94
+ }
95
+ return internal.parseDuration(arg);
96
+ }
97
+
98
+ function refinePublicRelativeTo(relativeTo) {
99
+ if (void 0 !== relativeTo) {
100
+ if (internal.isObjectLike(relativeTo)) {
101
+ const slots = getSlots(relativeTo) || {};
102
+ switch (slots.branding) {
103
+ case internal.ZonedDateTimeBranding:
104
+ case internal.PlainDateBranding:
105
+ return slots;
106
+
107
+ case internal.PlainDateTimeBranding:
108
+ return internal.createPlainDateSlots(slots);
109
+ }
110
+ const calendarId = getCalendarIdFromBag(relativeTo);
111
+ return {
112
+ ...internal.refineMaybeZonedDateTimeBag(refineTimeZoneArg, internal.queryNativeTimeZone, internal.createNativeStandardOps(calendarId), relativeTo),
113
+ calendar: calendarId
114
+ };
115
+ }
116
+ return internal.parseRelativeToSlots(relativeTo);
117
+ }
118
+ }
119
+
120
+ function toPlainTimeSlots(arg, options) {
121
+ if (internal.isObjectLike(arg)) {
122
+ const slots = getSlots(arg) || {};
123
+ switch (slots.branding) {
124
+ case internal.PlainTimeBranding:
125
+ return internal.refineOverflowOptions(options), slots;
126
+
127
+ case internal.PlainDateTimeBranding:
128
+ return internal.refineOverflowOptions(options), internal.createPlainTimeSlots(slots);
129
+
130
+ case internal.ZonedDateTimeBranding:
131
+ return internal.refineOverflowOptions(options), internal.zonedDateTimeToPlainTime(internal.queryNativeTimeZone, slots);
132
+ }
133
+ return internal.refinePlainTimeBag(arg, options);
134
+ }
135
+ const timeSlots = internal.parsePlainTime(arg);
136
+ return internal.refineOverflowOptions(options), timeSlots;
137
+ }
138
+
139
+ function optionalToPlainTimeFields(timeArg) {
140
+ return void 0 === timeArg ? void 0 : toPlainTimeSlots(timeArg);
141
+ }
142
+
143
+ function toPlainDateTimeSlots(arg, options) {
144
+ if (internal.isObjectLike(arg)) {
145
+ const slots = getSlots(arg) || {};
146
+ switch (slots.branding) {
147
+ case internal.PlainDateTimeBranding:
148
+ return internal.refineOverflowOptions(options), slots;
149
+
150
+ case internal.PlainDateBranding:
151
+ return internal.refineOverflowOptions(options), internal.createPlainDateTimeSlots({
152
+ ...slots,
153
+ ...internal.isoTimeFieldDefaults
154
+ });
155
+
156
+ case internal.ZonedDateTimeBranding:
157
+ return internal.refineOverflowOptions(options), internal.zonedDateTimeToPlainDateTime(internal.queryNativeTimeZone, slots);
158
+ }
159
+ return internal.refinePlainDateTimeBag(internal.createNativeStandardOps(getCalendarIdFromBag(arg)), arg, options);
160
+ }
161
+ const res = internal.parsePlainDateTime(arg);
162
+ return internal.refineOverflowOptions(options), res;
163
+ }
164
+
165
+ function toPlainMonthDaySlots(arg, options) {
166
+ if (internal.isObjectLike(arg)) {
167
+ const slots = getSlots(arg);
168
+ if (slots && slots.branding === internal.PlainMonthDayBranding) {
169
+ return internal.refineOverflowOptions(options), slots;
170
+ }
171
+ const calendarIdMaybe = extractCalendarIdFromBag(arg), calendarId = calendarIdMaybe || internal.isoCalendarId;
172
+ return internal.refinePlainMonthDayBag(internal.createNativeStandardOps(calendarId), !calendarIdMaybe, arg, options);
173
+ }
174
+ const res = internal.parsePlainMonthDay(internal.createNativeStandardOps, arg);
175
+ return internal.refineOverflowOptions(options), res;
176
+ }
177
+
178
+ function toPlainYearMonthSlots(arg, options) {
179
+ if (internal.isObjectLike(arg)) {
180
+ const slots = getSlots(arg);
181
+ return slots && slots.branding === internal.PlainYearMonthBranding ? (internal.refineOverflowOptions(options),
182
+ slots) : internal.refinePlainYearMonthBag(internal.createNativeStandardOps(getCalendarIdFromBag(arg)), arg, options);
183
+ }
184
+ const res = internal.parsePlainYearMonth(internal.createNativeStandardOps, arg);
185
+ return internal.refineOverflowOptions(options), res;
186
+ }
187
+
188
+ function toPlainDateSlots(arg, options) {
189
+ if (internal.isObjectLike(arg)) {
190
+ const slots = getSlots(arg) || {};
191
+ switch (slots.branding) {
192
+ case internal.PlainDateBranding:
193
+ return internal.refineOverflowOptions(options), slots;
194
+
195
+ case internal.PlainDateTimeBranding:
196
+ return internal.refineOverflowOptions(options), internal.createPlainDateSlots(slots);
197
+
198
+ case internal.ZonedDateTimeBranding:
199
+ return internal.refineOverflowOptions(options), internal.zonedDateTimeToPlainDate(internal.queryNativeTimeZone, slots);
200
+ }
201
+ return internal.refinePlainDateBag(internal.createNativeStandardOps(getCalendarIdFromBag(arg)), arg, options);
202
+ }
203
+ const res = internal.parsePlainDate(arg);
204
+ return internal.refineOverflowOptions(options), res;
205
+ }
206
+
207
+ function toZonedDateTimeSlots(arg, options) {
208
+ if (internal.isObjectLike(arg)) {
209
+ const slots = getSlots(arg);
210
+ if (slots && slots.branding === internal.ZonedDateTimeBranding) {
211
+ return internal.refineZonedFieldOptions(options), slots;
212
+ }
213
+ const calendarId = getCalendarIdFromBag(arg);
214
+ return internal.refineZonedDateTimeBag(refineTimeZoneArg, internal.queryNativeTimeZone, internal.createNativeStandardOps(calendarId), calendarId, arg, options);
215
+ }
216
+ return internal.parseZonedDateTime(arg, options);
217
+ }
218
+
219
+ function adaptDateMethods(methods) {
220
+ return internal.mapProps((method => slots => method(slotsToIso(slots))), methods);
221
+ }
222
+
223
+ function slotsToIso(slots) {
224
+ return internal.zonedEpochSlotsToIso(slots, internal.queryNativeTimeZone);
225
+ }
226
+
227
+ function toInstantSlots(arg) {
228
+ if (internal.isObjectLike(arg)) {
229
+ const slots = getSlots(arg);
230
+ if (slots) {
231
+ switch (slots.branding) {
232
+ case internal.InstantBranding:
233
+ return slots;
234
+
235
+ case internal.ZonedDateTimeBranding:
236
+ return internal.createInstantSlots(slots.epochNanoseconds);
237
+ }
238
+ }
239
+ }
240
+ return internal.parseInstant(arg);
241
+ }
242
+
243
+ function createFormatMethod(methodName) {
244
+ return Object.defineProperties((function(...formattables) {
245
+ const prepFormat = internalsMap.get(this), [format, ...rawFormattables] = prepFormat(methodName.includes("Range"), ...formattables);
246
+ return format[methodName](...rawFormattables);
247
+ }), internal.createNameDescriptors(methodName));
248
+ }
249
+
250
+ function createProxiedMethod(methodName) {
251
+ return Object.defineProperties((function(...args) {
252
+ return internalsMap.get(this).rawFormat[methodName](...args);
253
+ }), internal.createNameDescriptors(methodName));
254
+ }
255
+
256
+ function createFormatPrepperForBranding(branding) {
257
+ const config = classFormatConfigs[branding];
258
+ if (!config) {
259
+ throw new TypeError(internal.invalidFormatType(branding));
260
+ }
261
+ return internal.createFormatPrepper(config, internal.memoize(internal.createFormatForPrep), 1);
262
+ }
263
+
264
+ var internal = require("./internal.cjs");
265
+
266
+ const slotsMap = new WeakMap, getSlots = slotsMap.get.bind(slotsMap), setSlots = slotsMap.set.bind(slotsMap), yearMonthOnlyRefiners = {
267
+ era: internal.requireStringOrUndefined,
268
+ eraYear: internal.requireIntegerOrUndefined,
269
+ year: internal.requireInteger,
270
+ month: internal.requirePositiveInteger,
271
+ daysInMonth: internal.requirePositiveInteger,
272
+ daysInYear: internal.requirePositiveInteger,
273
+ inLeapYear: internal.requireBoolean,
274
+ monthsInYear: internal.requirePositiveInteger
275
+ }, monthOnlyRefiners = {
276
+ monthCode: internal.requireString
277
+ }, dayOnlyRefiners = {
278
+ day: internal.requirePositiveInteger
279
+ }, dateOnlyRefiners = {
280
+ dayOfWeek: internal.requirePositiveInteger,
281
+ dayOfYear: internal.requirePositiveInteger,
282
+ weekOfYear: internal.requirePositiveIntegerOrUndefined,
283
+ yearOfWeek: internal.requireIntegerOrUndefined,
284
+ daysInWeek: internal.requirePositiveInteger
285
+ }, dateGetters = createCalendarGetters({
286
+ ...yearMonthOnlyRefiners,
287
+ ...monthOnlyRefiners,
288
+ ...dayOnlyRefiners,
289
+ ...dateOnlyRefiners
290
+ }), yearMonthGetters = createCalendarGetters({
291
+ ...yearMonthOnlyRefiners,
292
+ ...monthOnlyRefiners
293
+ }), monthDayGetters = createCalendarGetters({
294
+ ...monthOnlyRefiners,
295
+ ...dayOnlyRefiners
296
+ }), calendarIdGetters = {
297
+ calendarId: slots => slots.calendar
298
+ }, durationGetters = internal.mapPropNames((propName => slots => slots[propName]), internal.durationFieldNamesAsc.concat("sign")), timeGetters = internal.mapPropNames(((_name, i) => slots => slots[internal.isoTimeFieldNamesAsc[i]]), internal.timeFieldNamesAsc), epochGetters = {
299
+ epochMilliseconds: internal.getEpochMilli,
300
+ epochNanoseconds: internal.getEpochNano
301
+ }, [Duration, createDuration, getDurationSlots] = createSlotClass(internal.DurationBranding, internal.constructDurationSlots, {
302
+ ...durationGetters,
303
+ blank: internal.getDurationBlank
304
+ }, {
305
+ with: (slots, mod) => createDuration(internal.durationWithFields(slots, mod)),
306
+ negated: slots => createDuration(internal.negateDuration(slots)),
307
+ abs: slots => createDuration(internal.absDuration(slots)),
308
+ add: (slots, otherArg, options) => createDuration(internal.addDurations(refinePublicRelativeTo, internal.createNativeStandardOps, internal.queryNativeTimeZone, 0, slots, toDurationSlots(otherArg), options)),
309
+ subtract: (slots, otherArg, options) => createDuration(internal.addDurations(refinePublicRelativeTo, internal.createNativeStandardOps, internal.queryNativeTimeZone, 1, slots, toDurationSlots(otherArg), options)),
310
+ round: (slots, options) => createDuration(internal.roundDuration(refinePublicRelativeTo, internal.createNativeStandardOps, internal.queryNativeTimeZone, slots, options)),
311
+ total: (slots, options) => internal.totalDuration(refinePublicRelativeTo, internal.createNativeStandardOps, internal.queryNativeTimeZone, slots, options),
312
+ toLocaleString(slots, locales, options) {
313
+ return Intl.DurationFormat ? new Intl.DurationFormat(locales, options).format(this) : internal.formatDurationIso(slots);
314
+ },
315
+ toString: internal.formatDurationIso,
316
+ toJSON: slots => internal.formatDurationIso(slots),
317
+ valueOf: neverValueOf
318
+ }, {
319
+ from: arg => createDuration(toDurationSlots(arg)),
320
+ compare: (durationArg0, durationArg1, options) => internal.compareDurations(refinePublicRelativeTo, internal.createNativeStandardOps, internal.queryNativeTimeZone, toDurationSlots(durationArg0), toDurationSlots(durationArg1), options)
321
+ }), classFormatConfigs = {
322
+ Instant: internal.instantConfig,
323
+ PlainDateTime: internal.dateTimeConfig,
324
+ PlainDate: internal.dateConfig,
325
+ PlainTime: internal.timeConfig,
326
+ PlainYearMonth: internal.yearMonthConfig,
327
+ PlainMonthDay: internal.monthDayConfig
328
+ }, prepInstantFormat = internal.createFormatPrepper(internal.instantConfig), prepZonedDateTimeFormat = internal.createFormatPrepper(internal.zonedConfig), prepPlainDateTimeFormat = internal.createFormatPrepper(internal.dateTimeConfig), prepPlainDateFormat = internal.createFormatPrepper(internal.dateConfig), prepPlainTimeFormat = internal.createFormatPrepper(internal.timeConfig), prepPlainYearMonthFormat = internal.createFormatPrepper(internal.yearMonthConfig), prepPlainMonthDayFormat = internal.createFormatPrepper(internal.monthDayConfig), [PlainTime, createPlainTime] = createSlotClass(internal.PlainTimeBranding, internal.constructPlainTimeSlots, timeGetters, {
329
+ with(_slots, mod, options) {
330
+ return createPlainTime(internal.plainTimeWithFields(this, rejectInvalidBag(mod), options));
331
+ },
332
+ add: (slots, durationArg) => createPlainTime(internal.movePlainTime(0, slots, toDurationSlots(durationArg))),
333
+ subtract: (slots, durationArg) => createPlainTime(internal.movePlainTime(1, slots, toDurationSlots(durationArg))),
334
+ until: (slots, otherArg, options) => createDuration(internal.diffPlainTimes(0, slots, toPlainTimeSlots(otherArg), options)),
335
+ since: (slots, otherArg, options) => createDuration(internal.diffPlainTimes(1, slots, toPlainTimeSlots(otherArg), options)),
336
+ round: (slots, options) => createPlainTime(internal.roundPlainTime(slots, options)),
337
+ equals: (slots, other) => internal.plainTimesEqual(slots, toPlainTimeSlots(other)),
338
+ toLocaleString(slots, locales, options) {
339
+ const [format, epochMilli] = prepPlainTimeFormat(locales, options, slots);
340
+ return format.format(epochMilli);
341
+ },
342
+ toString: internal.formatPlainTimeIso,
343
+ toJSON: slots => internal.formatPlainTimeIso(slots),
344
+ valueOf: neverValueOf
345
+ }, {
346
+ from: (arg, options) => createPlainTime(toPlainTimeSlots(arg, options)),
347
+ compare: (arg0, arg1) => internal.compareIsoTimeFields(toPlainTimeSlots(arg0), toPlainTimeSlots(arg1))
348
+ }), [PlainDateTime, createPlainDateTime] = createSlotClass(internal.PlainDateTimeBranding, internal.bindArgs(internal.constructPlainDateTimeSlots, internal.refineCalendarId), {
349
+ ...calendarIdGetters,
350
+ ...dateGetters,
351
+ ...timeGetters
352
+ }, {
353
+ with: (slots, mod, options) => createPlainDateTime(internal.plainDateTimeWithFields(internal.createNativeStandardOps, slots, rejectInvalidBag(mod), options)),
354
+ withCalendar: (slots, calendarArg) => createPlainDateTime(internal.slotsWithCalendarId(slots, refineCalendarArg(calendarArg))),
355
+ withPlainTime: (slots, plainTimeArg) => createPlainDateTime(internal.plainDateTimeWithPlainTime(slots, optionalToPlainTimeFields(plainTimeArg))),
356
+ add: (slots, durationArg, options) => createPlainDateTime(internal.movePlainDateTime(internal.createNativeStandardOps, 0, slots, toDurationSlots(durationArg), options)),
357
+ subtract: (slots, durationArg, options) => createPlainDateTime(internal.movePlainDateTime(internal.createNativeStandardOps, 1, slots, toDurationSlots(durationArg), options)),
358
+ until: (slots, otherArg, options) => createDuration(internal.diffPlainDateTimes(internal.createNativeStandardOps, 0, slots, toPlainDateTimeSlots(otherArg), options)),
359
+ since: (slots, otherArg, options) => createDuration(internal.diffPlainDateTimes(internal.createNativeStandardOps, 1, slots, toPlainDateTimeSlots(otherArg), options)),
360
+ round: (slots, options) => createPlainDateTime(internal.roundPlainDateTime(slots, options)),
361
+ equals: (slots, otherArg) => internal.plainDateTimesEqual(slots, toPlainDateTimeSlots(otherArg)),
362
+ toZonedDateTime: (slots, timeZoneArg, options) => createZonedDateTime(internal.plainDateTimeToZonedDateTime(internal.queryNativeTimeZone, slots, refineTimeZoneArg(timeZoneArg), options)),
363
+ toPlainDate: slots => createPlainDate(internal.createPlainDateSlots(slots)),
364
+ toPlainTime: slots => createPlainTime(internal.createPlainTimeSlots(slots)),
365
+ toLocaleString(slots, locales, options) {
366
+ const [format, epochMilli] = prepPlainDateTimeFormat(locales, options, slots);
367
+ return format.format(epochMilli);
368
+ },
369
+ toString: internal.formatPlainDateTimeIso,
370
+ toJSON: slots => internal.formatPlainDateTimeIso(slots),
371
+ valueOf: neverValueOf
372
+ }, {
373
+ from: (arg, options) => createPlainDateTime(toPlainDateTimeSlots(arg, options)),
374
+ compare: (arg0, arg1) => internal.compareIsoDateTimeFields(toPlainDateTimeSlots(arg0), toPlainDateTimeSlots(arg1))
375
+ }), [PlainMonthDay, createPlainMonthDay, getPlainMonthDaySlots] = createSlotClass(internal.PlainMonthDayBranding, internal.bindArgs(internal.constructPlainMonthDaySlots, internal.refineCalendarId), {
376
+ ...calendarIdGetters,
377
+ ...monthDayGetters
378
+ }, {
379
+ with: (slots, mod, options) => createPlainMonthDay(internal.plainMonthDayWithFields(internal.createNativeStandardOps, slots, rejectInvalidBag(mod), options)),
380
+ equals: (slots, otherArg) => internal.plainMonthDaysEqual(slots, toPlainMonthDaySlots(otherArg)),
381
+ toPlainDate(slots, bag) {
382
+ return createPlainDate(internal.plainMonthDayToPlainDate(internal.createNativeStandardOps, slots, this, bag));
383
+ },
384
+ toLocaleString(slots, locales, options) {
385
+ const [format, epochMilli] = prepPlainMonthDayFormat(locales, options, slots);
386
+ return format.format(epochMilli);
387
+ },
388
+ toString: internal.formatPlainMonthDayIso,
389
+ toJSON: slots => internal.formatPlainMonthDayIso(slots),
390
+ valueOf: neverValueOf
391
+ }, {
392
+ from: (arg, options) => createPlainMonthDay(toPlainMonthDaySlots(arg, options))
393
+ }), [PlainYearMonth, createPlainYearMonth, getPlainYearMonthSlots] = createSlotClass(internal.PlainYearMonthBranding, internal.bindArgs(internal.constructPlainYearMonthSlots, internal.refineCalendarId), {
394
+ ...calendarIdGetters,
395
+ ...yearMonthGetters
396
+ }, {
397
+ with: (slots, mod, options) => createPlainYearMonth(internal.plainYearMonthWithFields(internal.createNativeStandardOps, slots, rejectInvalidBag(mod), options)),
398
+ add: (slots, durationArg, options) => createPlainYearMonth(internal.movePlainYearMonth(internal.createNativeStandardOps, 0, slots, toDurationSlots(durationArg), options)),
399
+ subtract: (slots, durationArg, options) => createPlainYearMonth(internal.movePlainYearMonth(internal.createNativeStandardOps, 1, slots, toDurationSlots(durationArg), options)),
400
+ until: (slots, otherArg, options) => createDuration(internal.diffPlainYearMonth(internal.createNativeStandardOps, 0, slots, toPlainYearMonthSlots(otherArg), options)),
401
+ since: (slots, otherArg, options) => createDuration(internal.diffPlainYearMonth(internal.createNativeStandardOps, 1, slots, toPlainYearMonthSlots(otherArg), options)),
402
+ equals: (slots, otherArg) => internal.plainYearMonthsEqual(slots, toPlainYearMonthSlots(otherArg)),
403
+ toPlainDate(slots, bag) {
404
+ return createPlainDate(internal.plainYearMonthToPlainDate(internal.createNativeStandardOps, slots, this, bag));
405
+ },
406
+ toLocaleString(slots, locales, options) {
407
+ const [format, epochMilli] = prepPlainYearMonthFormat(locales, options, slots);
408
+ return format.format(epochMilli);
409
+ },
410
+ toString: internal.formatPlainYearMonthIso,
411
+ toJSON: slots => internal.formatPlainYearMonthIso(slots),
412
+ valueOf: neverValueOf
413
+ }, {
414
+ from: (arg, options) => createPlainYearMonth(toPlainYearMonthSlots(arg, options)),
415
+ compare: (arg0, arg1) => internal.compareIsoDateFields(toPlainYearMonthSlots(arg0), toPlainYearMonthSlots(arg1))
416
+ }), [PlainDate, createPlainDate, getPlainDateSlots] = createSlotClass(internal.PlainDateBranding, internal.bindArgs(internal.constructPlainDateSlots, internal.refineCalendarId), {
417
+ ...calendarIdGetters,
418
+ ...dateGetters
419
+ }, {
420
+ with: (slots, mod, options) => createPlainDate(internal.plainDateWithFields(internal.createNativeStandardOps, slots, rejectInvalidBag(mod), options)),
421
+ withCalendar: (slots, calendarArg) => createPlainDate(internal.slotsWithCalendarId(slots, refineCalendarArg(calendarArg))),
422
+ add: (slots, durationArg, options) => createPlainDate(internal.movePlainDate(internal.createNativeStandardOps, 0, slots, toDurationSlots(durationArg), options)),
423
+ subtract: (slots, durationArg, options) => createPlainDate(internal.movePlainDate(internal.createNativeStandardOps, 1, slots, toDurationSlots(durationArg), options)),
424
+ until: (slots, otherArg, options) => createDuration(internal.diffPlainDates(internal.createNativeStandardOps, 0, slots, toPlainDateSlots(otherArg), options)),
425
+ since: (slots, otherArg, options) => createDuration(internal.diffPlainDates(internal.createNativeStandardOps, 1, slots, toPlainDateSlots(otherArg), options)),
426
+ equals: (slots, otherArg) => internal.plainDatesEqual(slots, toPlainDateSlots(otherArg)),
427
+ toZonedDateTime(slots, options) {
428
+ const optionsObj = internal.isObjectLike(options) ? options : {
429
+ timeZone: options
430
+ };
431
+ return createZonedDateTime(internal.plainDateToZonedDateTime(refineTimeZoneArg, toPlainTimeSlots, internal.queryNativeTimeZone, slots, optionsObj));
432
+ },
433
+ toPlainDateTime: (slots, plainTimeArg) => createPlainDateTime(internal.plainDateToPlainDateTime(slots, optionalToPlainTimeFields(plainTimeArg))),
434
+ toPlainYearMonth(slots) {
435
+ return createPlainYearMonth(internal.plainDateToPlainYearMonth(internal.createNativeStandardOps, slots, this));
436
+ },
437
+ toPlainMonthDay(slots) {
438
+ return createPlainMonthDay(internal.plainDateToPlainMonthDay(internal.createNativeStandardOps, slots, this));
439
+ },
440
+ toLocaleString(slots, locales, options) {
441
+ const [format, epochMilli] = prepPlainDateFormat(locales, options, slots);
442
+ return format.format(epochMilli);
443
+ },
444
+ toString: internal.formatPlainDateIso,
445
+ toJSON: slots => internal.formatPlainDateIso(slots),
446
+ valueOf: neverValueOf
447
+ }, {
448
+ from: (arg, options) => createPlainDate(toPlainDateSlots(arg, options)),
449
+ compare: (arg0, arg1) => internal.compareIsoDateFields(toPlainDateSlots(arg0), toPlainDateSlots(arg1))
450
+ }), [ZonedDateTime, createZonedDateTime] = createSlotClass(internal.ZonedDateTimeBranding, internal.bindArgs(internal.constructZonedDateTimeSlots, internal.refineCalendarId, internal.refineTimeZoneId), {
451
+ ...epochGetters,
452
+ ...calendarIdGetters,
453
+ ...adaptDateMethods(dateGetters),
454
+ ...adaptDateMethods(timeGetters),
455
+ offset: slots => internal.formatOffsetNano(slotsToIso(slots).offsetNanoseconds),
456
+ offsetNanoseconds: slots => slotsToIso(slots).offsetNanoseconds,
457
+ timeZoneId: slots => slots.timeZone,
458
+ hoursInDay: slots => internal.computeZonedHoursInDay(internal.queryNativeTimeZone, slots)
459
+ }, {
460
+ with: (slots, mod, options) => createZonedDateTime(internal.zonedDateTimeWithFields(internal.createNativeStandardOps, internal.queryNativeTimeZone, slots, rejectInvalidBag(mod), options)),
461
+ withCalendar: (slots, calendarArg) => createZonedDateTime(internal.slotsWithCalendarId(slots, refineCalendarArg(calendarArg))),
462
+ withTimeZone: (slots, timeZoneArg) => createZonedDateTime(internal.slotsWithTimeZoneId(slots, refineTimeZoneArg(timeZoneArg))),
463
+ withPlainTime: (slots, plainTimeArg) => createZonedDateTime(internal.zonedDateTimeWithPlainTime(internal.queryNativeTimeZone, slots, optionalToPlainTimeFields(plainTimeArg))),
464
+ add: (slots, durationArg, options) => createZonedDateTime(internal.moveZonedDateTime(internal.createNativeStandardOps, internal.queryNativeTimeZone, 0, slots, toDurationSlots(durationArg), options)),
465
+ subtract: (slots, durationArg, options) => createZonedDateTime(internal.moveZonedDateTime(internal.createNativeStandardOps, internal.queryNativeTimeZone, 1, slots, toDurationSlots(durationArg), options)),
466
+ until: (slots, otherArg, options) => createDuration(internal.createDurationSlots(internal.diffZonedDateTimes(internal.createNativeStandardOps, internal.queryNativeTimeZone, 0, slots, toZonedDateTimeSlots(otherArg), options))),
467
+ since: (slots, otherArg, options) => createDuration(internal.createDurationSlots(internal.diffZonedDateTimes(internal.createNativeStandardOps, internal.queryNativeTimeZone, 1, slots, toZonedDateTimeSlots(otherArg), options))),
468
+ round: (slots, options) => createZonedDateTime(internal.roundZonedDateTime(internal.queryNativeTimeZone, slots, options)),
469
+ startOfDay: slots => createZonedDateTime(internal.computeZonedStartOfDay(internal.queryNativeTimeZone, slots)),
470
+ equals: (slots, otherArg) => internal.zonedDateTimesEqual(slots, toZonedDateTimeSlots(otherArg)),
471
+ toInstant: slots => createInstant(internal.zonedDateTimeToInstant(slots)),
472
+ toPlainDateTime: slots => createPlainDateTime(internal.zonedDateTimeToPlainDateTime(internal.queryNativeTimeZone, slots)),
473
+ toPlainDate: slots => createPlainDate(internal.zonedDateTimeToPlainDate(internal.queryNativeTimeZone, slots)),
474
+ toPlainTime: slots => createPlainTime(internal.zonedDateTimeToPlainTime(internal.queryNativeTimeZone, slots)),
475
+ toLocaleString(slots, locales, options = {}) {
476
+ const [format, epochMilli] = prepZonedDateTimeFormat(locales, options, slots);
477
+ return format.format(epochMilli);
478
+ },
479
+ toString: (slots, options) => internal.formatZonedDateTimeIso(internal.queryNativeTimeZone, slots, options),
480
+ toJSON: slots => internal.formatZonedDateTimeIso(internal.queryNativeTimeZone, slots),
481
+ valueOf: neverValueOf,
482
+ getTimeZoneTransition(slots, options) {
483
+ const {timeZone: timeZoneId, epochNanoseconds: epochNano} = slots, direction = internal.refineDirectionOptions(options), newEpochNano = internal.queryNativeTimeZone(timeZoneId).getTransition(epochNano, direction);
484
+ return newEpochNano ? createZonedDateTime({
485
+ ...slots,
486
+ epochNanoseconds: newEpochNano
487
+ }) : null;
488
+ }
489
+ }, {
490
+ from: (arg, options) => createZonedDateTime(toZonedDateTimeSlots(arg, options)),
491
+ compare: (arg0, arg1) => internal.compareZonedDateTimes(toZonedDateTimeSlots(arg0), toZonedDateTimeSlots(arg1))
492
+ }), [Instant, createInstant, getInstantSlots] = createSlotClass(internal.InstantBranding, internal.constructInstantSlots, epochGetters, {
493
+ add: (slots, durationArg) => createInstant(internal.moveInstant(0, slots, toDurationSlots(durationArg))),
494
+ subtract: (slots, durationArg) => createInstant(internal.moveInstant(1, slots, toDurationSlots(durationArg))),
495
+ until: (slots, otherArg, options) => createDuration(internal.diffInstants(0, slots, toInstantSlots(otherArg), options)),
496
+ since: (slots, otherArg, options) => createDuration(internal.diffInstants(1, slots, toInstantSlots(otherArg), options)),
497
+ round: (slots, options) => createInstant(internal.roundInstant(slots, options)),
498
+ equals: (slots, otherArg) => internal.instantsEqual(slots, toInstantSlots(otherArg)),
499
+ toZonedDateTimeISO: (slots, timeZoneArg) => createZonedDateTime(internal.instantToZonedDateTime(slots, refineTimeZoneArg(timeZoneArg))),
500
+ toLocaleString(slots, locales, options) {
501
+ const [format, epochMilli] = prepInstantFormat(locales, options, slots);
502
+ return format.format(epochMilli);
503
+ },
504
+ toString: (slots, options) => internal.formatInstantIso(refineTimeZoneArg, internal.queryNativeTimeZone, slots, options),
505
+ toJSON: slots => internal.formatInstantIso(refineTimeZoneArg, internal.queryNativeTimeZone, slots),
506
+ valueOf: neverValueOf
507
+ }, {
508
+ from: arg => createInstant(toInstantSlots(arg)),
509
+ fromEpochMilliseconds: epochMilli => createInstant(internal.epochMilliToInstant(epochMilli)),
510
+ fromEpochNanoseconds: epochNano => createInstant(internal.epochNanoToInstant(epochNano)),
511
+ compare: (a, b) => internal.compareInstants(toInstantSlots(a), toInstantSlots(b))
512
+ }), Now = Object.defineProperties({}, {
513
+ ...internal.createStringTagDescriptors("Temporal.Now"),
514
+ ...internal.createPropDescriptors({
515
+ timeZoneId: () => internal.getCurrentTimeZoneId(),
516
+ instant: () => createInstant(internal.createInstantSlots(internal.getCurrentEpochNano())),
517
+ zonedDateTimeISO: (timeZoneArg = internal.getCurrentTimeZoneId()) => createZonedDateTime(internal.createZonedDateTimeSlots(internal.getCurrentEpochNano(), refineTimeZoneArg(timeZoneArg), internal.isoCalendarId)),
518
+ plainDateTimeISO: (timeZoneArg = internal.getCurrentTimeZoneId()) => createPlainDateTime(internal.createPlainDateTimeSlots(internal.getCurrentIsoDateTime(internal.queryNativeTimeZone(refineTimeZoneArg(timeZoneArg))), internal.isoCalendarId)),
519
+ plainDateISO: (timeZoneArg = internal.getCurrentTimeZoneId()) => createPlainDate(internal.createPlainDateSlots(internal.getCurrentIsoDateTime(internal.queryNativeTimeZone(refineTimeZoneArg(timeZoneArg))), internal.isoCalendarId)),
520
+ plainTimeISO: (timeZoneArg = internal.getCurrentTimeZoneId()) => createPlainTime(internal.createPlainTimeSlots(internal.getCurrentIsoDateTime(internal.queryNativeTimeZone(refineTimeZoneArg(timeZoneArg)))))
521
+ })
522
+ }), Temporal = Object.defineProperties({}, {
523
+ ...internal.createStringTagDescriptors("Temporal"),
524
+ ...internal.createPropDescriptors({
525
+ PlainYearMonth: PlainYearMonth,
526
+ PlainMonthDay: PlainMonthDay,
527
+ PlainDate: PlainDate,
528
+ PlainTime: PlainTime,
529
+ PlainDateTime: PlainDateTime,
530
+ ZonedDateTime: ZonedDateTime,
531
+ Instant: Instant,
532
+ Duration: Duration,
533
+ Now: Now
534
+ })
535
+ }), DateTimeFormat = function() {
536
+ function DateTimeFormatFunc(locales, options) {
537
+ return new DateTimeFormatNew(locales, options);
538
+ }
539
+ function DateTimeFormatNew(locales, options = Object.create(null)) {
540
+ internalsMap.set(this, ((locales, options) => {
541
+ const rawFormat = new internal.RawDateTimeFormat(locales, options), resolveOptions = rawFormat.resolvedOptions(), resolvedLocale = resolveOptions.locale, copiedOptions = internal.pluckProps(Object.keys(options), resolveOptions), queryFormatPrepperForBranding = internal.memoize(createFormatPrepperForBranding), prepFormat = (isRange, ...formattables) => {
542
+ if (isRange) {
543
+ if (2 !== formattables.length) {
544
+ throw new TypeError(internal.mismatchingFormatTypes);
545
+ }
546
+ for (const formattable of formattables) {
547
+ if (void 0 === formattable) {
548
+ throw new TypeError(internal.mismatchingFormatTypes);
549
+ }
550
+ }
551
+ }
552
+ isRange || void 0 !== formattables[0] || (formattables = []);
553
+ const formattableEssences = formattables.map((formattable => getSlots(formattable) || Number(formattable)));
554
+ let overallBranding, i = 0;
555
+ for (const formattableEssence of formattableEssences) {
556
+ const slotsBranding = "object" == typeof formattableEssence ? formattableEssence.branding : void 0;
557
+ if (i++ && slotsBranding !== overallBranding) {
558
+ throw new TypeError(internal.mismatchingFormatTypes);
559
+ }
560
+ overallBranding = slotsBranding;
561
+ }
562
+ return overallBranding ? queryFormatPrepperForBranding(overallBranding)(resolvedLocale, copiedOptions, ...formattableEssences) : [ rawFormat, ...formattableEssences ];
563
+ };
564
+ return prepFormat.rawFormat = rawFormat, prepFormat;
565
+ })(locales, options));
566
+ }
567
+ const members = internal.RawDateTimeFormat.prototype, memberDescriptors = Object.getOwnPropertyDescriptors(members), classDescriptors = Object.getOwnPropertyDescriptors(internal.RawDateTimeFormat);
568
+ for (const memberName in memberDescriptors) {
569
+ const memberDescriptor = memberDescriptors[memberName], formatLikeMethod = memberName.startsWith("format") && createFormatMethod(memberName);
570
+ "function" == typeof memberDescriptor.value ? memberDescriptor.value = "constructor" === memberName ? DateTimeFormatFunc : formatLikeMethod || createProxiedMethod(memberName) : formatLikeMethod && (memberDescriptor.get = function() {
571
+ if (!internalsMap.has(this)) {
572
+ throw new TypeError(internal.invalidCallingContext);
573
+ }
574
+ return (...args) => formatLikeMethod.apply(this, args);
575
+ }, Object.defineProperties(memberDescriptor.get, internal.createNameDescriptors(`get ${memberName}`)));
576
+ }
577
+ return classDescriptors.prototype.value = DateTimeFormatNew.prototype = Object.create({}, memberDescriptors),
578
+ Object.defineProperties(DateTimeFormatFunc, classDescriptors), DateTimeFormatFunc;
579
+ }(), internalsMap = new WeakMap, IntlExtended = Object.defineProperties(Object.create(Intl), internal.createPropDescriptors({
580
+ DateTimeFormat: DateTimeFormat
581
+ }));
582
+
583
+ exports.DateTimeFormat = DateTimeFormat, exports.IntlExtended = IntlExtended, exports.Temporal = Temporal,
584
+ exports.toTemporalInstant = function() {
585
+ const epochMilli = Date.prototype.valueOf.call(this);
586
+ return createInstant(internal.createInstantSlots(internal.numberToBigNano(internal.requireNumberIsInteger(epochMilli), internal.nanoInMilli)));
587
+ };