@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.
- package/LICENSE +21 -0
- package/README.md +214 -0
- package/chunks/classApi.cjs +587 -0
- package/chunks/classApi.js +582 -0
- package/chunks/internal.cjs +3076 -0
- package/chunks/internal.js +3280 -0
- package/global.cjs +11 -0
- package/global.d.cts +1 -0
- package/global.d.ts +1 -0
- package/global.esm.js +11 -0
- package/global.js +3422 -0
- package/global.min.js +1 -0
- package/impl.cjs +5 -0
- package/impl.d.cts +1 -0
- package/impl.d.ts +1 -0
- package/impl.js +1 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,3076 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function clampProp(props, propName, min, max, overflow) {
|
|
4
|
+
return clampEntity(propName, ((props, propName) => {
|
|
5
|
+
const propVal = props[propName];
|
|
6
|
+
if (void 0 === propVal) {
|
|
7
|
+
throw new TypeError(missingField(propName));
|
|
8
|
+
}
|
|
9
|
+
return propVal;
|
|
10
|
+
})(props, propName), min, max, overflow);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function clampEntity(entityName, num, min, max, overflow, choices) {
|
|
14
|
+
const clamped = clampNumber(num, min, max);
|
|
15
|
+
if (overflow && num !== clamped) {
|
|
16
|
+
throw new RangeError(numberOutOfRange(entityName, num, min, max, choices));
|
|
17
|
+
}
|
|
18
|
+
return clamped;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isObjectLike(arg) {
|
|
22
|
+
return null !== arg && /object|function/.test(typeof arg);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function memoize(generator, MapClass = Map) {
|
|
26
|
+
const map = new MapClass;
|
|
27
|
+
return (key, ...otherArgs) => {
|
|
28
|
+
if (map.has(key)) {
|
|
29
|
+
return map.get(key);
|
|
30
|
+
}
|
|
31
|
+
const val = generator(key, ...otherArgs);
|
|
32
|
+
return map.set(key, val), val;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createPropDescriptors(propVals, readonly) {
|
|
37
|
+
return mapProps((value => ({
|
|
38
|
+
value: value,
|
|
39
|
+
configurable: 1,
|
|
40
|
+
writable: !readonly
|
|
41
|
+
})), propVals);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function zipProps(propNamesRev, args) {
|
|
45
|
+
const res = {};
|
|
46
|
+
let i = propNamesRev.length;
|
|
47
|
+
for (const arg of args) {
|
|
48
|
+
res[propNamesRev[--i]] = arg;
|
|
49
|
+
}
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mapProps(transformer, props, extraArg) {
|
|
54
|
+
const res = {};
|
|
55
|
+
for (const propName in props) {
|
|
56
|
+
res[propName] = transformer(props[propName], propName, extraArg);
|
|
57
|
+
}
|
|
58
|
+
return res;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function mapPropNames(generator, propNames, extraArg) {
|
|
62
|
+
const props = {};
|
|
63
|
+
for (let i = 0; i < propNames.length; i++) {
|
|
64
|
+
const propName = propNames[i];
|
|
65
|
+
props[propName] = generator(propName, i, extraArg);
|
|
66
|
+
}
|
|
67
|
+
return props;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function remapProps(oldNames, newNames, oldProps) {
|
|
71
|
+
const newProps = {};
|
|
72
|
+
for (let i = 0; i < oldNames.length; i++) {
|
|
73
|
+
newProps[newNames[i]] = oldProps[oldNames[i]];
|
|
74
|
+
}
|
|
75
|
+
return newProps;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function pluckProps(propNames, props) {
|
|
79
|
+
const res = Object.create(null);
|
|
80
|
+
for (const propName of propNames) {
|
|
81
|
+
res[propName] = props[propName];
|
|
82
|
+
}
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function hasAnyPropsByName(props, names) {
|
|
87
|
+
for (const name of names) {
|
|
88
|
+
if (name in props) {
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function allPropsEqual(propNames, props0, props1) {
|
|
96
|
+
for (const propName of propNames) {
|
|
97
|
+
if (props0[propName] !== props1[propName]) {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function zeroOutProps(propNames, clearUntilI, props) {
|
|
105
|
+
const copy = {
|
|
106
|
+
...props
|
|
107
|
+
};
|
|
108
|
+
for (let i = 0; i < clearUntilI; i++) {
|
|
109
|
+
copy[propNames[i]] = 0;
|
|
110
|
+
}
|
|
111
|
+
return copy;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function bindArgs(f, ...boundArgs) {
|
|
115
|
+
return (...dynamicArgs) => f(...boundArgs, ...dynamicArgs);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function capitalize(s) {
|
|
119
|
+
return s[0].toUpperCase() + s.substring(1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function sortStrings(strs) {
|
|
123
|
+
return strs.slice().sort();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function padNumber(digits, num) {
|
|
127
|
+
return String(num).padStart(digits, "0");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function compareNumbers(a, b) {
|
|
131
|
+
return Math.sign(a - b);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function clampNumber(num, min, max) {
|
|
135
|
+
return Math.min(Math.max(num, min), max);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function divModFloor(num, divisor) {
|
|
139
|
+
return [ Math.floor(num / divisor), modFloor(num, divisor) ];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function modFloor(num, divisor) {
|
|
143
|
+
return (num % divisor + divisor) % divisor;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function divModTrunc(num, divisor) {
|
|
147
|
+
return [ divTrunc(num, divisor), modTrunc(num, divisor) ];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function divTrunc(num, divisor) {
|
|
151
|
+
return Math.trunc(num / divisor) || 0;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function modTrunc(num, divisor) {
|
|
155
|
+
return num % divisor || 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function hasHalf(num) {
|
|
159
|
+
return .5 === Math.abs(num % 1);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function givenFieldsToBigNano(fields, largestUnit, fieldNames) {
|
|
163
|
+
let timeNano = 0, days = 0;
|
|
164
|
+
for (let unit = 0; unit <= largestUnit; unit++) {
|
|
165
|
+
const fieldVal = fields[fieldNames[unit]], unitNano = unitNanoMap[unit], unitInDay = nanoInUtcDay / unitNano, [unitDays, leftoverUnits] = divModTrunc(fieldVal, unitInDay);
|
|
166
|
+
timeNano += leftoverUnits * unitNano, days += unitDays;
|
|
167
|
+
}
|
|
168
|
+
const [timeDays, leftoverNano] = divModTrunc(timeNano, nanoInUtcDay);
|
|
169
|
+
return [ days + timeDays, leftoverNano ];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function nanoToGivenFields(nano, largestUnit, fieldNames) {
|
|
173
|
+
const fields = {};
|
|
174
|
+
for (let unit = largestUnit; unit >= 0; unit--) {
|
|
175
|
+
const divisor = unitNanoMap[unit];
|
|
176
|
+
fields[fieldNames[unit]] = divTrunc(nano, divisor), nano = modTrunc(nano, divisor);
|
|
177
|
+
}
|
|
178
|
+
return fields;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function requirePositiveInteger(arg) {
|
|
182
|
+
return requireNumberIsPositive(requireInteger(arg));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function requireInteger(arg) {
|
|
186
|
+
return requireNumberIsInteger(requireNumber(arg));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function requirePropDefined(optionName, optionVal) {
|
|
190
|
+
if (null == optionVal) {
|
|
191
|
+
throw new RangeError(missingField(optionName));
|
|
192
|
+
}
|
|
193
|
+
return optionVal;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function requireObjectLike(arg) {
|
|
197
|
+
if (!isObjectLike(arg)) {
|
|
198
|
+
throw new TypeError(invalidObject);
|
|
199
|
+
}
|
|
200
|
+
return arg;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function requireType(typeName, arg, entityName = typeName) {
|
|
204
|
+
if (typeof arg !== typeName) {
|
|
205
|
+
throw new TypeError(invalidEntity(entityName, arg));
|
|
206
|
+
}
|
|
207
|
+
return arg;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function requireNumberIsInteger(num, entityName = "number") {
|
|
211
|
+
if (!Number.isInteger(num)) {
|
|
212
|
+
throw new RangeError(expectedInteger(entityName, num));
|
|
213
|
+
}
|
|
214
|
+
return num || 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function requireNumberIsPositive(num, entityName = "number") {
|
|
218
|
+
if (num <= 0) {
|
|
219
|
+
throw new RangeError(expectedPositive(entityName, num));
|
|
220
|
+
}
|
|
221
|
+
return num;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function toString(arg) {
|
|
225
|
+
if ("symbol" == typeof arg) {
|
|
226
|
+
throw new TypeError(forbiddenSymbolToString);
|
|
227
|
+
}
|
|
228
|
+
return String(arg);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function toStringViaPrimitive(arg, entityName) {
|
|
232
|
+
return isObjectLike(arg) ? String(arg) : requireString(arg, entityName);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function toBigInt(bi) {
|
|
236
|
+
if ("string" == typeof bi) {
|
|
237
|
+
return BigInt(bi);
|
|
238
|
+
}
|
|
239
|
+
if ("bigint" != typeof bi) {
|
|
240
|
+
throw new TypeError(invalidBigInt(bi));
|
|
241
|
+
}
|
|
242
|
+
return bi;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function toNumber(arg, entityName = "number") {
|
|
246
|
+
if ("bigint" == typeof arg) {
|
|
247
|
+
throw new TypeError(forbiddenBigIntToNumber(entityName));
|
|
248
|
+
}
|
|
249
|
+
if (arg = Number(arg), !Number.isFinite(arg)) {
|
|
250
|
+
throw new RangeError(expectedFinite(entityName, arg));
|
|
251
|
+
}
|
|
252
|
+
return arg;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function toInteger(arg, entityName) {
|
|
256
|
+
return Math.trunc(toNumber(arg, entityName)) || 0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function toStrictInteger(arg, entityName) {
|
|
260
|
+
return requireNumberIsInteger(toNumber(arg, entityName), entityName);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function toPositiveInteger(arg, entityName) {
|
|
264
|
+
return requireNumberIsPositive(toInteger(arg, entityName), entityName);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function createBigNano(days, timeNano) {
|
|
268
|
+
let [extraDays, newTimeNano] = divModTrunc(timeNano, nanoInUtcDay), newDays = days + extraDays;
|
|
269
|
+
const newDaysSign = Math.sign(newDays);
|
|
270
|
+
return newDaysSign && newDaysSign === -Math.sign(newTimeNano) && (newDays -= newDaysSign,
|
|
271
|
+
newTimeNano += newDaysSign * nanoInUtcDay), [ newDays, newTimeNano ];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function addBigNanos(a, b, sign = 1) {
|
|
275
|
+
return createBigNano(a[0] + b[0] * sign, a[1] + b[1] * sign);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function moveBigNano(a, b) {
|
|
279
|
+
return createBigNano(a[0], a[1] + b);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function diffBigNanos(a, b) {
|
|
283
|
+
return addBigNanos(b, a, -1);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function compareBigNanos(a, b) {
|
|
287
|
+
return compareNumbers(a[0], b[0]) || compareNumbers(a[1], b[1]);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function bigNanoOutside(subject, rangeStart, rangeEndExcl) {
|
|
291
|
+
return -1 === compareBigNanos(subject, rangeStart) || 1 === compareBigNanos(subject, rangeEndExcl);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function bigIntToBigNano(num, multiplierNano = 1) {
|
|
295
|
+
const wholeInDay = BigInt(nanoInUtcDay / multiplierNano);
|
|
296
|
+
return [ Number(num / wholeInDay), Number(num % wholeInDay) * multiplierNano ];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function numberToBigNano(num, multiplierNano = 1) {
|
|
300
|
+
const wholeInDay = nanoInUtcDay / multiplierNano, [days, remainder] = divModTrunc(num, wholeInDay);
|
|
301
|
+
return [ days, remainder * multiplierNano ];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function bigNanoToNumber(bigNano, divisorNano = 1, exact) {
|
|
305
|
+
const [days, timeNano] = bigNano, [whole, remainderNano] = divModTrunc(timeNano, divisorNano);
|
|
306
|
+
return days * (nanoInUtcDay / divisorNano) + (whole + (exact ? remainderNano / divisorNano : 0));
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function divModBigNano(bigNano, divisorNano, divModFunc = divModFloor) {
|
|
310
|
+
const [days, timeNano] = bigNano, [whole, remainderNano] = divModFunc(timeNano, divisorNano);
|
|
311
|
+
return [ days * (nanoInUtcDay / divisorNano) + whole, remainderNano ];
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function checkIsoYearMonthInBounds(isoFields) {
|
|
315
|
+
return clampProp(isoFields, "isoYear", isoYearMin, isoYearMax, 1), isoFields.isoYear === isoYearMin ? clampProp(isoFields, "isoMonth", 4, 12, 1) : isoFields.isoYear === isoYearMax && clampProp(isoFields, "isoMonth", 1, 9, 1),
|
|
316
|
+
isoFields;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function checkIsoDateInBounds(isoFields) {
|
|
320
|
+
return checkIsoDateTimeInBounds({
|
|
321
|
+
...isoFields,
|
|
322
|
+
...isoTimeFieldDefaults,
|
|
323
|
+
isoHour: 12
|
|
324
|
+
}), isoFields;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function checkIsoDateTimeInBounds(isoFields) {
|
|
328
|
+
const isoYear = clampProp(isoFields, "isoYear", isoYearMin, isoYearMax, 1), nudge = isoYear === isoYearMin ? 1 : isoYear === isoYearMax ? -1 : 0;
|
|
329
|
+
return nudge && checkEpochNanoInBounds(isoToEpochNano({
|
|
330
|
+
...isoFields,
|
|
331
|
+
isoDay: isoFields.isoDay + nudge,
|
|
332
|
+
isoNanosecond: isoFields.isoNanosecond - nudge
|
|
333
|
+
})), isoFields;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function checkEpochNanoInBounds(epochNano) {
|
|
337
|
+
if (!epochNano || bigNanoOutside(epochNano, epochNanoMin, epochNanoMax)) {
|
|
338
|
+
throw new RangeError(outOfBoundsDate);
|
|
339
|
+
}
|
|
340
|
+
return epochNano;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function isoTimeFieldsToNano(isoTimeFields) {
|
|
344
|
+
return givenFieldsToBigNano(isoTimeFields, 5, isoTimeFieldNamesAsc)[1];
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function nanoToIsoTimeAndDay(nano) {
|
|
348
|
+
const [dayDelta, timeNano] = divModFloor(nano, nanoInUtcDay);
|
|
349
|
+
return [ nanoToGivenFields(timeNano, 5, isoTimeFieldNamesAsc), dayDelta ];
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function epochNanoToSecMod(epochNano) {
|
|
353
|
+
return divModBigNano(epochNano, nanoInSec);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function isoToEpochMilli(isoDateTimeFields) {
|
|
357
|
+
return isoArgsToEpochMilli(isoDateTimeFields.isoYear, isoDateTimeFields.isoMonth, isoDateTimeFields.isoDay, isoDateTimeFields.isoHour, isoDateTimeFields.isoMinute, isoDateTimeFields.isoSecond, isoDateTimeFields.isoMillisecond);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function isoToEpochNano(isoFields) {
|
|
361
|
+
const epochMilli = isoToEpochMilli(isoFields);
|
|
362
|
+
if (void 0 !== epochMilli) {
|
|
363
|
+
const [days, milliRemainder] = divModTrunc(epochMilli, milliInDay);
|
|
364
|
+
return [ days, milliRemainder * nanoInMilli + (isoFields.isoMicrosecond || 0) * nanoInMicro + (isoFields.isoNanosecond || 0) ];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function isoToEpochNanoWithOffset(isoFields, offsetNano) {
|
|
369
|
+
const [newIsoTimeFields, dayDelta] = nanoToIsoTimeAndDay(isoTimeFieldsToNano(isoFields) - offsetNano);
|
|
370
|
+
return checkEpochNanoInBounds(isoToEpochNano({
|
|
371
|
+
...isoFields,
|
|
372
|
+
isoDay: isoFields.isoDay + dayDelta,
|
|
373
|
+
...newIsoTimeFields
|
|
374
|
+
}));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function isoArgsToEpochSec(...args) {
|
|
378
|
+
return isoArgsToEpochMilli(...args) / milliInSec;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function isoArgsToEpochMilli(...args) {
|
|
382
|
+
const [legacyDate, daysNudged] = isoToLegacyDate(...args), epochMilli = legacyDate.valueOf();
|
|
383
|
+
if (!isNaN(epochMilli)) {
|
|
384
|
+
return epochMilli - daysNudged * milliInDay;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function isoToLegacyDate(isoYear, isoMonth = 1, isoDay = 1, isoHour = 0, isoMinute = 0, isoSec = 0, isoMilli = 0) {
|
|
389
|
+
const daysNudged = isoYear === isoYearMin ? 1 : isoYear === isoYearMax ? -1 : 0, legacyDate = new Date(0);
|
|
390
|
+
return legacyDate.setUTCHours(isoHour, isoMinute, isoSec, isoMilli), legacyDate.setUTCFullYear(isoYear, isoMonth - 1, isoDay + daysNudged),
|
|
391
|
+
[ legacyDate, daysNudged ];
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function epochNanoToIso(epochNano, offsetNano) {
|
|
395
|
+
let [days, timeNano] = moveBigNano(epochNano, offsetNano);
|
|
396
|
+
timeNano < 0 && (timeNano += nanoInUtcDay, days -= 1);
|
|
397
|
+
const [timeMilli, nanoRemainder] = divModFloor(timeNano, nanoInMilli), [isoMicrosecond, isoNanosecond] = divModFloor(nanoRemainder, nanoInMicro);
|
|
398
|
+
return epochMilliToIso(days * milliInDay + timeMilli, isoMicrosecond, isoNanosecond);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function epochMilliToIso(epochMilli, isoMicrosecond = 0, isoNanosecond = 0) {
|
|
402
|
+
const daysOver = Math.ceil(Math.max(0, Math.abs(epochMilli) - maxMilli) / milliInDay) * Math.sign(epochMilli), legacyDate = new Date(epochMilli - daysOver * milliInDay);
|
|
403
|
+
return zipProps(isoDateTimeFieldNamesAsc, [ legacyDate.getUTCFullYear(), legacyDate.getUTCMonth() + 1, legacyDate.getUTCDate() + daysOver, legacyDate.getUTCHours(), legacyDate.getUTCMinutes(), legacyDate.getUTCSeconds(), legacyDate.getUTCMilliseconds(), isoMicrosecond, isoNanosecond ]);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function hashIntlFormatParts(intlFormat, epochMilli) {
|
|
407
|
+
if (epochMilli < -maxMilli) {
|
|
408
|
+
throw new RangeError(outOfBoundsDate);
|
|
409
|
+
}
|
|
410
|
+
const parts = intlFormat.formatToParts(epochMilli), hash = {};
|
|
411
|
+
for (const part of parts) {
|
|
412
|
+
hash[part.type] = part.value;
|
|
413
|
+
}
|
|
414
|
+
return hash;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function computeIsoDateParts(isoFields) {
|
|
418
|
+
return [ isoFields.isoYear, isoFields.isoMonth, isoFields.isoDay ];
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function computeIsoMonthCodeParts(_isoYear, isoMonth) {
|
|
422
|
+
return [ isoMonth, 0 ];
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function computeIsoMonthsInYear() {
|
|
426
|
+
return isoMonthsInYear;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function computeIsoDaysInMonth(isoYear, isoMonth) {
|
|
430
|
+
switch (isoMonth) {
|
|
431
|
+
case 2:
|
|
432
|
+
return computeIsoInLeapYear(isoYear) ? 29 : 28;
|
|
433
|
+
|
|
434
|
+
case 4:
|
|
435
|
+
case 6:
|
|
436
|
+
case 9:
|
|
437
|
+
case 11:
|
|
438
|
+
return 30;
|
|
439
|
+
}
|
|
440
|
+
return 31;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function computeIsoDaysInYear(isoYear) {
|
|
444
|
+
return computeIsoInLeapYear(isoYear) ? 366 : 365;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function computeIsoInLeapYear(isoYear) {
|
|
448
|
+
return isoYear % 4 == 0 && (isoYear % 100 != 0 || isoYear % 400 == 0);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function computeIsoDayOfWeek(isoDateFields) {
|
|
452
|
+
const [legacyDate, daysNudged] = isoToLegacyDate(isoDateFields.isoYear, isoDateFields.isoMonth, isoDateFields.isoDay);
|
|
453
|
+
return modFloor(legacyDate.getUTCDay() - daysNudged, 7) || 7;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
function computeIsoEraParts(isoFields) {
|
|
457
|
+
return this.id === gregoryCalendarId ? (({isoYear: isoYear}) => isoYear < 1 ? [ "gregory-inverse", 1 - isoYear ] : [ "gregory", isoYear ])(isoFields) : "japanese" === this.id ? queryJapaneseEraParts(isoFields) : [];
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function checkIsoDateTimeFields(isoDateTimeFields) {
|
|
461
|
+
return checkIsoDateFields(isoDateTimeFields), constrainIsoTimeFields(isoDateTimeFields, 1),
|
|
462
|
+
isoDateTimeFields;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function checkIsoDateFields(isoInternals) {
|
|
466
|
+
return constrainIsoDateFields(isoInternals, 1), isoInternals;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function isIsoDateFieldsValid(isoFields) {
|
|
470
|
+
return allPropsEqual(isoDateFieldNamesAsc, isoFields, constrainIsoDateFields(isoFields));
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function constrainIsoDateFields(isoFields, overflow) {
|
|
474
|
+
const {isoYear: isoYear} = isoFields, isoMonth = clampProp(isoFields, "isoMonth", 1, computeIsoMonthsInYear(), overflow);
|
|
475
|
+
return {
|
|
476
|
+
isoYear: isoYear,
|
|
477
|
+
isoMonth: isoMonth,
|
|
478
|
+
isoDay: clampProp(isoFields, "isoDay", 1, computeIsoDaysInMonth(isoYear, isoMonth), overflow)
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function constrainIsoTimeFields(isoTimeFields, overflow) {
|
|
483
|
+
return zipProps(isoTimeFieldNamesAsc, [ clampProp(isoTimeFields, "isoHour", 0, 23, overflow), clampProp(isoTimeFields, "isoMinute", 0, 59, overflow), clampProp(isoTimeFields, "isoSecond", 0, 59, overflow), clampProp(isoTimeFields, "isoMillisecond", 0, 999, overflow), clampProp(isoTimeFields, "isoMicrosecond", 0, 999, overflow), clampProp(isoTimeFields, "isoNanosecond", 0, 999, overflow) ]);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function refineOverflowOptions(options) {
|
|
487
|
+
return void 0 === options ? 0 : refineOverflow(requireObjectLike(options));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function refineZonedFieldOptions(options, defaultOffsetDisambig = 0) {
|
|
491
|
+
options = normalizeOptions(options);
|
|
492
|
+
const epochDisambig = refineEpochDisambig(options), offsetDisambig = refineOffsetDisambig(options, defaultOffsetDisambig);
|
|
493
|
+
return [ refineOverflow(options), offsetDisambig, epochDisambig ];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function refineDiffOptions(roundingModeInvert, options, defaultLargestUnit, maxUnit = 9, minUnit = 0, defaultRoundingMode = 4) {
|
|
497
|
+
options = normalizeOptions(options);
|
|
498
|
+
let largestUnit = refineLargestUnit(options, maxUnit, minUnit), roundingInc = parseRoundingIncInteger(options), roundingMode = refineRoundingMode(options, defaultRoundingMode);
|
|
499
|
+
const smallestUnit = refineSmallestUnit(options, maxUnit, minUnit, 1);
|
|
500
|
+
return null == largestUnit ? largestUnit = Math.max(defaultLargestUnit, smallestUnit) : checkLargestSmallestUnit(largestUnit, smallestUnit),
|
|
501
|
+
roundingInc = refineRoundingInc(roundingInc, smallestUnit, 1), roundingModeInvert && (roundingMode = (roundingMode => roundingMode < 4 ? (roundingMode + 2) % 4 : roundingMode)(roundingMode)),
|
|
502
|
+
[ largestUnit, smallestUnit, roundingInc, roundingMode ];
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function refineRoundingOptions(options, maxUnit = 6, solarMode) {
|
|
506
|
+
let roundingInc = parseRoundingIncInteger(options = normalizeOptionsOrString(options, smallestUnitStr));
|
|
507
|
+
const roundingMode = refineRoundingMode(options, 7);
|
|
508
|
+
let smallestUnit = refineSmallestUnit(options, maxUnit);
|
|
509
|
+
return smallestUnit = requirePropDefined(smallestUnitStr, smallestUnit), roundingInc = refineRoundingInc(roundingInc, smallestUnit, void 0, solarMode),
|
|
510
|
+
[ smallestUnit, roundingInc, roundingMode ];
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function refineDateDisplayOptions(options) {
|
|
514
|
+
return refineCalendarDisplay(normalizeOptions(options));
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function refineTimeDisplayOptions(options, maxSmallestUnit) {
|
|
518
|
+
return refineTimeDisplayTuple(normalizeOptions(options), maxSmallestUnit);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function refineTimeDisplayTuple(options, maxSmallestUnit = 4) {
|
|
522
|
+
const subsecDigits = refineSubsecDigits(options);
|
|
523
|
+
return [ refineRoundingMode(options, 4), ...refineSmallestUnitAndSubsecDigits(refineSmallestUnit(options, maxSmallestUnit), subsecDigits) ];
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function refineSmallestUnitAndSubsecDigits(smallestUnit, subsecDigits) {
|
|
527
|
+
return null != smallestUnit ? [ unitNanoMap[smallestUnit], smallestUnit < 4 ? 9 - 3 * smallestUnit : -1 ] : [ void 0 === subsecDigits ? 1 : 10 ** (9 - subsecDigits), subsecDigits ];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function parseRoundingIncInteger(options) {
|
|
531
|
+
const roundingInc = options[roundingIncName];
|
|
532
|
+
return void 0 === roundingInc ? 1 : toInteger(roundingInc, roundingIncName);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function refineRoundingInc(roundingInc, smallestUnit, allowManyLargeUnits, solarMode) {
|
|
536
|
+
const upUnitNano = solarMode ? nanoInUtcDay : unitNanoMap[smallestUnit + 1];
|
|
537
|
+
if (upUnitNano) {
|
|
538
|
+
const unitNano = unitNanoMap[smallestUnit];
|
|
539
|
+
if (upUnitNano % ((roundingInc = clampEntity(roundingIncName, roundingInc, 1, upUnitNano / unitNano - (solarMode ? 0 : 1), 1)) * unitNano)) {
|
|
540
|
+
throw new RangeError(invalidEntity(roundingIncName, roundingInc));
|
|
541
|
+
}
|
|
542
|
+
} else {
|
|
543
|
+
roundingInc = clampEntity(roundingIncName, roundingInc, 1, allowManyLargeUnits ? 10 ** 9 : 1, 1);
|
|
544
|
+
}
|
|
545
|
+
return roundingInc;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function refineSubsecDigits(options) {
|
|
549
|
+
let subsecDigits = options[subsecDigitsName];
|
|
550
|
+
if (void 0 !== subsecDigits) {
|
|
551
|
+
if ("number" != typeof subsecDigits) {
|
|
552
|
+
if ("auto" === toString(subsecDigits)) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
throw new RangeError(invalidEntity(subsecDigitsName, subsecDigits));
|
|
556
|
+
}
|
|
557
|
+
subsecDigits = clampEntity(subsecDigitsName, Math.floor(subsecDigits), 0, 9, 1);
|
|
558
|
+
}
|
|
559
|
+
return subsecDigits;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function normalizeOptions(options) {
|
|
563
|
+
return void 0 === options ? {} : requireObjectLike(options);
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function normalizeOptionsOrString(options, optionName) {
|
|
567
|
+
return "string" == typeof options ? {
|
|
568
|
+
[optionName]: options
|
|
569
|
+
} : requireObjectLike(options);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function fabricateOverflowOptions(overflow) {
|
|
573
|
+
return {
|
|
574
|
+
overflow: overflowMapNames[overflow]
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function refineUnitOption(optionName, options, maxUnit = 9, minUnit = 0, ensureDefined) {
|
|
579
|
+
let unitStr = options[optionName];
|
|
580
|
+
if (void 0 === unitStr) {
|
|
581
|
+
return ensureDefined ? minUnit : void 0;
|
|
582
|
+
}
|
|
583
|
+
if (unitStr = toString(unitStr), "auto" === unitStr) {
|
|
584
|
+
return ensureDefined ? minUnit : null;
|
|
585
|
+
}
|
|
586
|
+
let unit = unitNameMap[unitStr];
|
|
587
|
+
if (void 0 === unit && (unit = durationFieldIndexes[unitStr]), void 0 === unit) {
|
|
588
|
+
throw new RangeError(invalidChoice(optionName, unitStr, unitNameMap));
|
|
589
|
+
}
|
|
590
|
+
return clampEntity(optionName, unit, minUnit, maxUnit, 1, unitNamesAsc), unit;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function refineChoiceOption(optionName, enumNameMap, options, defaultChoice = 0) {
|
|
594
|
+
const enumArg = options[optionName];
|
|
595
|
+
if (void 0 === enumArg) {
|
|
596
|
+
return defaultChoice;
|
|
597
|
+
}
|
|
598
|
+
const enumStr = toString(enumArg), enumNum = enumNameMap[enumStr];
|
|
599
|
+
if (void 0 === enumNum) {
|
|
600
|
+
throw new RangeError(invalidChoice(optionName, enumStr, enumNameMap));
|
|
601
|
+
}
|
|
602
|
+
return enumNum;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function checkLargestSmallestUnit(largestUnit, smallestUnit) {
|
|
606
|
+
if (smallestUnit > largestUnit) {
|
|
607
|
+
throw new RangeError(flippedSmallestLargestUnit);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function createInstantSlots(epochNano) {
|
|
612
|
+
return {
|
|
613
|
+
branding: InstantBranding,
|
|
614
|
+
epochNanoseconds: epochNano
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function createZonedDateTimeSlots(epochNano, timeZoneId, calendarId) {
|
|
619
|
+
return {
|
|
620
|
+
branding: ZonedDateTimeBranding,
|
|
621
|
+
calendar: calendarId,
|
|
622
|
+
timeZone: timeZoneId,
|
|
623
|
+
epochNanoseconds: epochNano
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
function createPlainDateTimeSlots(isoFields, calendar = isoFields.calendar) {
|
|
628
|
+
return {
|
|
629
|
+
branding: PlainDateTimeBranding,
|
|
630
|
+
calendar: calendar,
|
|
631
|
+
...pluckProps(isoDateTimeFieldNamesAlpha, isoFields)
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function createPlainDateSlots(isoFields, calendar = isoFields.calendar) {
|
|
636
|
+
return {
|
|
637
|
+
branding: PlainDateBranding,
|
|
638
|
+
calendar: calendar,
|
|
639
|
+
...pluckProps(isoDateFieldNamesAlpha, isoFields)
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function createPlainYearMonthSlots(isoFields, calendar = isoFields.calendar) {
|
|
644
|
+
return {
|
|
645
|
+
branding: PlainYearMonthBranding,
|
|
646
|
+
calendar: calendar,
|
|
647
|
+
...pluckProps(isoDateFieldNamesAlpha, isoFields)
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
function createPlainMonthDaySlots(isoFields, calendar = isoFields.calendar) {
|
|
652
|
+
return {
|
|
653
|
+
branding: PlainMonthDayBranding,
|
|
654
|
+
calendar: calendar,
|
|
655
|
+
...pluckProps(isoDateFieldNamesAlpha, isoFields)
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function createPlainTimeSlots(isoFields) {
|
|
660
|
+
return {
|
|
661
|
+
branding: PlainTimeBranding,
|
|
662
|
+
...pluckProps(isoTimeFieldNamesAlpha, isoFields)
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function createDurationSlots(durationFields) {
|
|
667
|
+
return {
|
|
668
|
+
branding: DurationBranding,
|
|
669
|
+
sign: computeDurationSign(durationFields),
|
|
670
|
+
...pluckProps(durationFieldNamesAlpha, durationFields)
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function getEpochMilli(slots) {
|
|
675
|
+
return divModBigNano(slots.epochNanoseconds, nanoInMilli)[0];
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function extractEpochNano(slots) {
|
|
679
|
+
return slots.epochNanoseconds;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
function totalDayTimeDuration(durationFields, totalUnit) {
|
|
683
|
+
return bigNanoToNumber(durationFieldsToBigNano(durationFields), unitNanoMap[totalUnit], 1);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function clampRelativeDuration(calendarOps, durationFields, clampUnit, clampDistance, marker, markerToEpochNano, moveMarker) {
|
|
687
|
+
const unitName = durationFieldNamesAsc[clampUnit], durationPlusDistance = {
|
|
688
|
+
...durationFields,
|
|
689
|
+
[unitName]: durationFields[unitName] + clampDistance
|
|
690
|
+
}, marker0 = moveMarker(calendarOps, marker, durationFields), marker1 = moveMarker(calendarOps, marker, durationPlusDistance);
|
|
691
|
+
return [ markerToEpochNano(marker0), markerToEpochNano(marker1) ];
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function computeEpochNanoFrac(epochNanoProgress, epochNano0, epochNano1) {
|
|
695
|
+
const denom = bigNanoToNumber(diffBigNanos(epochNano0, epochNano1));
|
|
696
|
+
if (!denom) {
|
|
697
|
+
throw new RangeError(invalidProtocolResults);
|
|
698
|
+
}
|
|
699
|
+
return bigNanoToNumber(diffBigNanos(epochNano0, epochNanoProgress)) / denom;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function roundDateTime(isoFields, smallestUnit, roundingInc, roundingMode) {
|
|
703
|
+
return roundDateTimeToNano(isoFields, computeNanoInc(smallestUnit, roundingInc), roundingMode);
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function roundDateTimeToNano(isoFields, nanoInc, roundingMode) {
|
|
707
|
+
const [roundedIsoFields, dayDelta] = roundTimeToNano(isoFields, nanoInc, roundingMode);
|
|
708
|
+
return checkIsoDateTimeInBounds({
|
|
709
|
+
...moveByDays(isoFields, dayDelta),
|
|
710
|
+
...roundedIsoFields
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function roundTimeToNano(isoFields, nanoInc, roundingMode) {
|
|
715
|
+
return nanoToIsoTimeAndDay(roundByInc(isoTimeFieldsToNano(isoFields), nanoInc, roundingMode));
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function roundToMinute(offsetNano) {
|
|
719
|
+
return roundByInc(offsetNano, nanoInMinute, 7);
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
function computeNanoInc(smallestUnit, roundingInc) {
|
|
723
|
+
return unitNanoMap[smallestUnit] * roundingInc;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function computeDayInterval(isoFields) {
|
|
727
|
+
const isoFields0 = computeDayFloor(isoFields);
|
|
728
|
+
return [ isoFields0, moveByDays(isoFields0, 1) ];
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function computeDayFloor(isoFields) {
|
|
732
|
+
return clearIsoFields(6, isoFields);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function roundDayTimeDurationByInc(durationFields, nanoInc, roundingMode) {
|
|
736
|
+
const maxUnit = Math.min(getMaxDurationUnit(durationFields), 6);
|
|
737
|
+
return nanoToDurationDayTimeFields(roundBigNanoByInc(durationFieldsToBigNano(durationFields, maxUnit), nanoInc, roundingMode), maxUnit);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function roundRelativeDuration(durationFields, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, marker, markerToEpochNano, moveMarker) {
|
|
741
|
+
if (0 === smallestUnit && 1 === roundingInc) {
|
|
742
|
+
return durationFields;
|
|
743
|
+
}
|
|
744
|
+
const nudgeFunc = isUniformUnit(smallestUnit, marker) ? isZonedEpochSlots(marker) && smallestUnit < 6 && largestUnit >= 6 ? nudgeZonedTimeDuration : nudgeDayTimeDuration : nudgeRelativeDuration;
|
|
745
|
+
let [roundedDurationFields, roundedEpochNano, grewBigUnit] = nudgeFunc(durationFields, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, marker, markerToEpochNano, moveMarker);
|
|
746
|
+
return grewBigUnit && 7 !== smallestUnit && (roundedDurationFields = ((durationFields, endEpochNano, largestUnit, smallestUnit, calendarOps, marker, markerToEpochNano, moveMarker) => {
|
|
747
|
+
const sign = computeDurationSign(durationFields);
|
|
748
|
+
for (let currentUnit = smallestUnit + 1; currentUnit <= largestUnit; currentUnit++) {
|
|
749
|
+
if (7 === currentUnit && 7 !== largestUnit) {
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
const baseDurationFields = clearDurationFields(currentUnit, durationFields);
|
|
753
|
+
baseDurationFields[durationFieldNamesAsc[currentUnit]] += sign;
|
|
754
|
+
const beyondThresholdNano = bigNanoToNumber(diffBigNanos(markerToEpochNano(moveMarker(calendarOps, marker, baseDurationFields)), endEpochNano));
|
|
755
|
+
if (beyondThresholdNano && Math.sign(beyondThresholdNano) !== sign) {
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
durationFields = baseDurationFields;
|
|
759
|
+
}
|
|
760
|
+
return durationFields;
|
|
761
|
+
})(roundedDurationFields, roundedEpochNano, largestUnit, Math.max(6, smallestUnit), calendarOps, marker, markerToEpochNano, moveMarker)),
|
|
762
|
+
roundedDurationFields;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function roundBigNano(bigNano, smallestUnit, roundingInc, roundingMode, useDayOrigin) {
|
|
766
|
+
if (6 === smallestUnit) {
|
|
767
|
+
const daysExact = (bigNano => bigNano[0] + bigNano[1] / nanoInUtcDay)(bigNano);
|
|
768
|
+
return [ roundByInc(daysExact, roundingInc, roundingMode), 0 ];
|
|
769
|
+
}
|
|
770
|
+
return roundBigNanoByInc(bigNano, computeNanoInc(smallestUnit, roundingInc), roundingMode, useDayOrigin);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
function roundBigNanoByInc(bigNano, nanoInc, roundingMode, useDayOrigin) {
|
|
774
|
+
let [days, timeNano] = bigNano;
|
|
775
|
+
useDayOrigin && timeNano < 0 && (timeNano += nanoInUtcDay, days -= 1);
|
|
776
|
+
const [dayDelta, roundedTimeNano] = divModFloor(roundByInc(timeNano, nanoInc, roundingMode), nanoInUtcDay);
|
|
777
|
+
return createBigNano(days + dayDelta, roundedTimeNano);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function roundByInc(num, inc, roundingMode) {
|
|
781
|
+
return roundWithMode(num / inc, roundingMode) * inc;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function roundWithMode(num, roundingMode) {
|
|
785
|
+
return roundingModeFuncs[roundingMode](num);
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function nudgeDayTimeDuration(durationFields, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode) {
|
|
789
|
+
const sign = computeDurationSign(durationFields), bigNano = durationFieldsToBigNano(durationFields), roundedBigNano = roundBigNano(bigNano, smallestUnit, roundingInc, roundingMode), nanoDiff = diffBigNanos(bigNano, roundedBigNano), expandedBigUnit = Math.sign(roundedBigNano[0] - bigNano[0]) === sign, roundedDayTimeFields = nanoToDurationDayTimeFields(roundedBigNano, Math.min(largestUnit, 6));
|
|
790
|
+
return [ {
|
|
791
|
+
...durationFields,
|
|
792
|
+
...roundedDayTimeFields
|
|
793
|
+
}, addBigNanos(endEpochNano, nanoDiff), expandedBigUnit ];
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function nudgeZonedTimeDuration(durationFields, endEpochNano, _largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, marker, markerToEpochNano, moveMarker) {
|
|
797
|
+
const sign = computeDurationSign(durationFields) || 1, timeNano = bigNanoToNumber(durationFieldsToBigNano(durationFields, 5)), nanoInc = computeNanoInc(smallestUnit, roundingInc);
|
|
798
|
+
let roundedTimeNano = roundByInc(timeNano, nanoInc, roundingMode);
|
|
799
|
+
const [dayEpochNano0, dayEpochNano1] = clampRelativeDuration(calendarOps, {
|
|
800
|
+
...durationFields,
|
|
801
|
+
...durationTimeFieldDefaults
|
|
802
|
+
}, 6, sign, marker, markerToEpochNano, moveMarker), beyondDayNano = roundedTimeNano - bigNanoToNumber(diffBigNanos(dayEpochNano0, dayEpochNano1));
|
|
803
|
+
let dayDelta = 0;
|
|
804
|
+
beyondDayNano && Math.sign(beyondDayNano) !== sign ? endEpochNano = moveBigNano(dayEpochNano0, roundedTimeNano) : (dayDelta += sign,
|
|
805
|
+
roundedTimeNano = roundByInc(beyondDayNano, nanoInc, roundingMode), endEpochNano = moveBigNano(dayEpochNano1, roundedTimeNano));
|
|
806
|
+
const durationTimeFields = nanoToDurationTimeFields(roundedTimeNano);
|
|
807
|
+
return [ {
|
|
808
|
+
...durationFields,
|
|
809
|
+
...durationTimeFields,
|
|
810
|
+
days: durationFields.days + dayDelta
|
|
811
|
+
}, endEpochNano, Boolean(dayDelta) ];
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
function nudgeRelativeDuration(durationFields, endEpochNano, _largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, marker, markerToEpochNano, moveMarker) {
|
|
815
|
+
const sign = computeDurationSign(durationFields), smallestUnitFieldName = durationFieldNamesAsc[smallestUnit], baseDurationFields = clearDurationFields(smallestUnit, durationFields);
|
|
816
|
+
7 === smallestUnit && (durationFields = {
|
|
817
|
+
...durationFields,
|
|
818
|
+
weeks: durationFields.weeks + Math.trunc(durationFields.days / 7)
|
|
819
|
+
});
|
|
820
|
+
const truncedVal = divTrunc(durationFields[smallestUnitFieldName], roundingInc) * roundingInc;
|
|
821
|
+
baseDurationFields[smallestUnitFieldName] = truncedVal;
|
|
822
|
+
const [epochNano0, epochNano1] = clampRelativeDuration(calendarOps, baseDurationFields, smallestUnit, roundingInc * sign, marker, markerToEpochNano, moveMarker), exactVal = truncedVal + computeEpochNanoFrac(endEpochNano, epochNano0, epochNano1) * sign * roundingInc, roundedVal = roundByInc(exactVal, roundingInc, roundingMode), expanded = Math.sign(roundedVal - exactVal) === sign;
|
|
823
|
+
return baseDurationFields[smallestUnitFieldName] = roundedVal, [ baseDurationFields, expanded ? epochNano1 : epochNano0, expanded ];
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function formatDateLikeIso(calendarId, formatSimple, isoFields, calendarDisplay) {
|
|
827
|
+
const showCalendar = calendarDisplay > 1 || 0 === calendarDisplay && calendarId !== isoCalendarId;
|
|
828
|
+
return 1 === calendarDisplay ? calendarId === isoCalendarId ? formatSimple(isoFields) : formatIsoDateFields(isoFields) : showCalendar ? formatIsoDateFields(isoFields) + formatCalendarId(calendarId, 2 === calendarDisplay) : formatSimple(isoFields);
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function formatDurationFragments(fragObj) {
|
|
832
|
+
const parts = [];
|
|
833
|
+
for (const fragName in fragObj) {
|
|
834
|
+
const fragVal = fragObj[fragName];
|
|
835
|
+
fragVal && parts.push(fragVal, fragName);
|
|
836
|
+
}
|
|
837
|
+
return parts.join("");
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function formatIsoDateTimeFields(isoDateTimeFields, subsecDigits) {
|
|
841
|
+
return formatIsoDateFields(isoDateTimeFields) + "T" + formatIsoTimeFields(isoDateTimeFields, subsecDigits);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function formatIsoDateFields(isoDateFields) {
|
|
845
|
+
return formatIsoYearMonthFields(isoDateFields) + "-" + padNumber2(isoDateFields.isoDay);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
function formatIsoYearMonthFields(isoDateFields) {
|
|
849
|
+
const {isoYear: isoYear} = isoDateFields;
|
|
850
|
+
return (isoYear < 0 || isoYear > 9999 ? getSignStr(isoYear) + padNumber(6, Math.abs(isoYear)) : padNumber(4, isoYear)) + "-" + padNumber2(isoDateFields.isoMonth);
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function formatIsoMonthDayFields(isoDateFields) {
|
|
854
|
+
return padNumber2(isoDateFields.isoMonth) + "-" + padNumber2(isoDateFields.isoDay);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function formatIsoTimeFields(isoTimeFields, subsecDigits) {
|
|
858
|
+
const parts = [ padNumber2(isoTimeFields.isoHour), padNumber2(isoTimeFields.isoMinute) ];
|
|
859
|
+
return -1 !== subsecDigits && parts.push(padNumber2(isoTimeFields.isoSecond) + ((isoMillisecond, isoMicrosecond, isoNanosecond, subsecDigits) => formatSubsecNano(isoMillisecond * nanoInMilli + isoMicrosecond * nanoInMicro + isoNanosecond, subsecDigits))(isoTimeFields.isoMillisecond, isoTimeFields.isoMicrosecond, isoTimeFields.isoNanosecond, subsecDigits)),
|
|
860
|
+
parts.join(":");
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function formatOffsetNano(offsetNano, offsetDisplay = 0) {
|
|
864
|
+
if (1 === offsetDisplay) {
|
|
865
|
+
return "";
|
|
866
|
+
}
|
|
867
|
+
const [hour, nanoRemainder0] = divModFloor(Math.abs(offsetNano), nanoInHour), [minute, nanoRemainder1] = divModFloor(nanoRemainder0, nanoInMinute), [second, nanoRemainder2] = divModFloor(nanoRemainder1, nanoInSec);
|
|
868
|
+
return getSignStr(offsetNano) + padNumber2(hour) + ":" + padNumber2(minute) + (second || nanoRemainder2 ? ":" + padNumber2(second) + formatSubsecNano(nanoRemainder2) : "");
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function formatCalendar(calendarId, calendarDisplay) {
|
|
872
|
+
return 1 !== calendarDisplay && (calendarDisplay > 1 || 0 === calendarDisplay && calendarId !== isoCalendarId) ? formatCalendarId(calendarId, 2 === calendarDisplay) : "";
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
function formatCalendarId(calendarId, isCritical) {
|
|
876
|
+
return "[" + (isCritical ? "!" : "") + "u-ca=" + calendarId + "]";
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
function formatSubsecNano(totalNano, subsecDigits) {
|
|
880
|
+
let s = padNumber(9, totalNano);
|
|
881
|
+
return s = void 0 === subsecDigits ? s.replace(trailingZerosRE, "") : s.slice(0, subsecDigits),
|
|
882
|
+
s ? "." + s : "";
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
function getSignStr(num) {
|
|
886
|
+
return num < 0 ? "-" : "+";
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
function formatDurationNumber(n, force) {
|
|
890
|
+
return n || force ? n.toLocaleString("fullwide", {
|
|
891
|
+
useGrouping: 0
|
|
892
|
+
}) : "";
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
function getMatchingInstantFor(timeZoneOps, isoFields, offsetNano, offsetDisambig = 0, epochDisambig = 0, epochFuzzy, hasZ) {
|
|
896
|
+
if (void 0 !== offsetNano && 1 === offsetDisambig && (1 === offsetDisambig || hasZ)) {
|
|
897
|
+
return isoToEpochNanoWithOffset(isoFields, offsetNano);
|
|
898
|
+
}
|
|
899
|
+
const possibleEpochNanos = timeZoneOps.getPossibleInstantsFor(isoFields);
|
|
900
|
+
if (void 0 !== offsetNano && 3 !== offsetDisambig) {
|
|
901
|
+
const matchingEpochNano = ((possibleEpochNanos, isoDateTimeFields, offsetNano, fuzzy) => {
|
|
902
|
+
const zonedEpochNano = isoToEpochNano(isoDateTimeFields);
|
|
903
|
+
fuzzy && (offsetNano = roundToMinute(offsetNano));
|
|
904
|
+
for (const possibleEpochNano of possibleEpochNanos) {
|
|
905
|
+
let possibleOffsetNano = bigNanoToNumber(diffBigNanos(possibleEpochNano, zonedEpochNano));
|
|
906
|
+
if (fuzzy && (possibleOffsetNano = roundToMinute(possibleOffsetNano)), possibleOffsetNano === offsetNano) {
|
|
907
|
+
return possibleEpochNano;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
})(possibleEpochNanos, isoFields, offsetNano, epochFuzzy);
|
|
911
|
+
if (void 0 !== matchingEpochNano) {
|
|
912
|
+
return matchingEpochNano;
|
|
913
|
+
}
|
|
914
|
+
if (0 === offsetDisambig) {
|
|
915
|
+
throw new RangeError(invalidOffsetForTimeZone);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return hasZ ? isoToEpochNano(isoFields) : getSingleInstantFor(timeZoneOps, isoFields, epochDisambig, possibleEpochNanos);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
function getSingleInstantFor(timeZoneOps, isoFields, disambig = 0, possibleEpochNanos = timeZoneOps.getPossibleInstantsFor(isoFields)) {
|
|
922
|
+
if (1 === possibleEpochNanos.length) {
|
|
923
|
+
return possibleEpochNanos[0];
|
|
924
|
+
}
|
|
925
|
+
if (1 === disambig) {
|
|
926
|
+
throw new RangeError(ambigOffset);
|
|
927
|
+
}
|
|
928
|
+
if (possibleEpochNanos.length) {
|
|
929
|
+
return possibleEpochNanos[3 === disambig ? 1 : 0];
|
|
930
|
+
}
|
|
931
|
+
const zonedEpochNano = isoToEpochNano(isoFields), gapNano = ((timeZoneOps, zonedEpochNano) => {
|
|
932
|
+
const startOffsetNano = timeZoneOps.getOffsetNanosecondsFor(moveBigNano(zonedEpochNano, -nanoInUtcDay));
|
|
933
|
+
return (gapNano => {
|
|
934
|
+
if (gapNano > nanoInUtcDay) {
|
|
935
|
+
throw new RangeError(outOfBoundsDstGap);
|
|
936
|
+
}
|
|
937
|
+
return gapNano;
|
|
938
|
+
})(timeZoneOps.getOffsetNanosecondsFor(moveBigNano(zonedEpochNano, nanoInUtcDay)) - startOffsetNano);
|
|
939
|
+
})(timeZoneOps, zonedEpochNano), shiftNano = gapNano * (2 === disambig ? -1 : 1);
|
|
940
|
+
return (possibleEpochNanos = timeZoneOps.getPossibleInstantsFor(epochNanoToIso(zonedEpochNano, shiftNano)))[2 === disambig ? 0 : possibleEpochNanos.length - 1];
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
function getStartOfDayInstantFor(timeZoneOps, isoFields) {
|
|
944
|
+
const possibleEpochNanos = timeZoneOps.getPossibleInstantsFor(isoFields);
|
|
945
|
+
if (possibleEpochNanos.length) {
|
|
946
|
+
return possibleEpochNanos[0];
|
|
947
|
+
}
|
|
948
|
+
const zonedEpochNanoDayBefore = moveBigNano(isoToEpochNano(isoFields), -nanoInUtcDay);
|
|
949
|
+
return timeZoneOps.getTransition(zonedEpochNanoDayBefore, 1);
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function moveZonedEpochs(timeZoneOps, calendarOps, slots, durationFields, options) {
|
|
953
|
+
const timeOnlyNano = durationFieldsToBigNano(durationFields, 5);
|
|
954
|
+
let epochNano = slots.epochNanoseconds;
|
|
955
|
+
if (durationHasDateParts(durationFields)) {
|
|
956
|
+
const isoDateTimeFields = zonedEpochSlotsToIso(slots, timeZoneOps);
|
|
957
|
+
epochNano = addBigNanos(getSingleInstantFor(timeZoneOps, {
|
|
958
|
+
...moveDate(calendarOps, isoDateTimeFields, {
|
|
959
|
+
...durationFields,
|
|
960
|
+
...durationTimeFieldDefaults
|
|
961
|
+
}, options),
|
|
962
|
+
...pluckProps(isoTimeFieldNamesAsc, isoDateTimeFields)
|
|
963
|
+
}), timeOnlyNano);
|
|
964
|
+
} else {
|
|
965
|
+
epochNano = addBigNanos(epochNano, timeOnlyNano), refineOverflowOptions(options);
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
epochNanoseconds: checkEpochNanoInBounds(epochNano)
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function moveDateTime(calendarOps, isoDateTimeFields, durationFields, options) {
|
|
973
|
+
const [movedIsoTimeFields, dayDelta] = moveTime(isoDateTimeFields, durationFields);
|
|
974
|
+
return checkIsoDateTimeInBounds({
|
|
975
|
+
...moveDate(calendarOps, isoDateTimeFields, {
|
|
976
|
+
...durationFields,
|
|
977
|
+
...durationTimeFieldDefaults,
|
|
978
|
+
days: durationFields.days + dayDelta
|
|
979
|
+
}, options),
|
|
980
|
+
...movedIsoTimeFields
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function moveDate(calendarOps, isoDateFields, durationFields, options) {
|
|
985
|
+
if (durationFields.years || durationFields.months || durationFields.weeks) {
|
|
986
|
+
return calendarOps.dateAdd(isoDateFields, durationFields, options);
|
|
987
|
+
}
|
|
988
|
+
refineOverflowOptions(options);
|
|
989
|
+
const days = durationFields.days + durationFieldsToBigNano(durationFields, 5)[0];
|
|
990
|
+
return days ? checkIsoDateInBounds(moveByDays(isoDateFields, days)) : isoDateFields;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function moveToDayOfMonthUnsafe(calendarOps, isoFields, dayOfMonth = 1) {
|
|
994
|
+
return moveByDays(isoFields, dayOfMonth - calendarOps.day(isoFields));
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
function moveTime(isoFields, durationFields) {
|
|
998
|
+
const [durDays, durTimeNano] = durationFieldsToBigNano(durationFields, 5), [newIsoFields, overflowDays] = nanoToIsoTimeAndDay(isoTimeFieldsToNano(isoFields) + durTimeNano);
|
|
999
|
+
return [ newIsoFields, durDays + overflowDays ];
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
function moveByDays(isoFields, days) {
|
|
1003
|
+
return days ? {
|
|
1004
|
+
...isoFields,
|
|
1005
|
+
...epochMilliToIso(isoToEpochMilli(isoFields) + days * milliInDay)
|
|
1006
|
+
} : isoFields;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function createMarkerSystem(getCalendarOps, getTimeZoneOps, relativeToSlots) {
|
|
1010
|
+
const calendarOps = getCalendarOps(relativeToSlots.calendar);
|
|
1011
|
+
return isZonedEpochSlots(relativeToSlots) ? [ relativeToSlots, calendarOps, getTimeZoneOps(relativeToSlots.timeZone) ] : [ {
|
|
1012
|
+
...relativeToSlots,
|
|
1013
|
+
...isoTimeFieldDefaults
|
|
1014
|
+
}, calendarOps ];
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function createMarkerToEpochNano(timeZoneOps) {
|
|
1018
|
+
return timeZoneOps ? extractEpochNano : isoToEpochNano;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
function createMoveMarker(timeZoneOps) {
|
|
1022
|
+
return timeZoneOps ? bindArgs(moveZonedEpochs, timeZoneOps) : moveDateTime;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function createDiffMarkers(timeZoneOps) {
|
|
1026
|
+
return timeZoneOps ? bindArgs(diffZonedEpochsExact, timeZoneOps) : diffDateTimesExact;
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function isZonedEpochSlots(marker) {
|
|
1030
|
+
return marker && marker.epochNanoseconds;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function isUniformUnit(unit, marker) {
|
|
1034
|
+
return unit <= 6 - (isZonedEpochSlots(marker) ? 1 : 0);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
function negateDuration(slots) {
|
|
1038
|
+
return createDurationSlots(negateDurationFields(slots));
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
function negateDurationFields(fields) {
|
|
1042
|
+
const res = {};
|
|
1043
|
+
for (const fieldName of durationFieldNamesAsc) {
|
|
1044
|
+
res[fieldName] = -1 * fields[fieldName] || 0;
|
|
1045
|
+
}
|
|
1046
|
+
return res;
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
function computeDurationSign(fields, fieldNames = durationFieldNamesAsc) {
|
|
1050
|
+
let sign = 0;
|
|
1051
|
+
for (const fieldName of fieldNames) {
|
|
1052
|
+
const fieldSign = Math.sign(fields[fieldName]);
|
|
1053
|
+
if (fieldSign) {
|
|
1054
|
+
if (sign && sign !== fieldSign) {
|
|
1055
|
+
throw new RangeError(forbiddenDurationSigns);
|
|
1056
|
+
}
|
|
1057
|
+
sign = fieldSign;
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
return sign;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function checkDurationUnits(fields) {
|
|
1064
|
+
for (const calendarUnit of durationCalendarFieldNamesAsc) {
|
|
1065
|
+
clampEntity(calendarUnit, fields[calendarUnit], -maxCalendarUnit, maxCalendarUnit, 1);
|
|
1066
|
+
}
|
|
1067
|
+
return checkDurationTimeUnit(bigNanoToNumber(durationFieldsToBigNano(fields), nanoInSec)),
|
|
1068
|
+
fields;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
function checkDurationTimeUnit(n) {
|
|
1072
|
+
if (!Number.isSafeInteger(n)) {
|
|
1073
|
+
throw new RangeError(outOfBoundsDuration);
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
function durationFieldsToBigNano(fields, largestUnit = 6) {
|
|
1078
|
+
return givenFieldsToBigNano(fields, largestUnit, durationFieldNamesAsc);
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function nanoToDurationDayTimeFields(bigNano, largestUnit = 6) {
|
|
1082
|
+
const [days, timeNano] = bigNano, dayTimeFields = nanoToGivenFields(timeNano, largestUnit, durationFieldNamesAsc);
|
|
1083
|
+
if (dayTimeFields[durationFieldNamesAsc[largestUnit]] += days * (nanoInUtcDay / unitNanoMap[largestUnit]),
|
|
1084
|
+
!Number.isFinite(dayTimeFields[durationFieldNamesAsc[largestUnit]])) {
|
|
1085
|
+
throw new RangeError(outOfBoundsDate);
|
|
1086
|
+
}
|
|
1087
|
+
return dayTimeFields;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
function nanoToDurationTimeFields(nano, largestUnit = 5) {
|
|
1091
|
+
return nanoToGivenFields(nano, largestUnit, durationFieldNamesAsc);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function durationHasDateParts(fields) {
|
|
1095
|
+
return Boolean(computeDurationSign(fields, durationDateFieldNamesAsc));
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
function getMaxDurationUnit(fields) {
|
|
1099
|
+
let unit = 9;
|
|
1100
|
+
for (;unit > 0 && !fields[durationFieldNamesAsc[unit]]; unit--) {}
|
|
1101
|
+
return unit;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function createSplitTuple(startEpochSec, endEpochSec) {
|
|
1105
|
+
return [ startEpochSec, endEpochSec ];
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
function computePeriod(epochSec) {
|
|
1109
|
+
const startEpochSec = Math.floor(epochSec / periodDur) * periodDur;
|
|
1110
|
+
return [ startEpochSec, startEpochSec + periodDur ];
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function parseOffsetNano(s) {
|
|
1114
|
+
const offsetNano = parseOffsetNanoMaybe(s);
|
|
1115
|
+
if (void 0 === offsetNano) {
|
|
1116
|
+
throw new RangeError(failedParse(s));
|
|
1117
|
+
}
|
|
1118
|
+
return offsetNano;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
function parsePlainDate(s, isPlainYearMonth, isPlainMonthDay) {
|
|
1122
|
+
let organized = parseDateTimeLike(requireString(s));
|
|
1123
|
+
if (!organized || organized.hasZ) {
|
|
1124
|
+
throw new RangeError(failedParse(s));
|
|
1125
|
+
}
|
|
1126
|
+
return isPlainYearMonth ? organized.calendar === isoCalendarId && (organized = -271821 === organized.isoYear && 4 === organized.isoMonth ? {
|
|
1127
|
+
...organized,
|
|
1128
|
+
isoDay: 20,
|
|
1129
|
+
...isoTimeFieldDefaults
|
|
1130
|
+
} : {
|
|
1131
|
+
...organized,
|
|
1132
|
+
isoDay: 1,
|
|
1133
|
+
...isoTimeFieldDefaults
|
|
1134
|
+
}) : isPlainMonthDay && organized.calendar === isoCalendarId && (organized = {
|
|
1135
|
+
...organized,
|
|
1136
|
+
isoYear: isoEpochFirstLeapYear
|
|
1137
|
+
}), createPlainDateSlots(organized.hasTime ? finalizeDateTime(organized) : finalizeDate(organized));
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
function requireIsoCalendar(organized) {
|
|
1141
|
+
if (organized.calendar !== isoCalendarId) {
|
|
1142
|
+
throw new RangeError(invalidSubstring(organized.calendar));
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
function finalizeZonedDateTime(organized, offsetNano, offsetDisambig = 0, epochDisambig = 0) {
|
|
1147
|
+
const timeZoneId = resolveTimeZoneId(organized.timeZone), timeZoneImpl = queryNativeTimeZone(timeZoneId);
|
|
1148
|
+
let epochNano;
|
|
1149
|
+
return checkIsoDateTimeFields(organized), epochNano = organized.hasTime ? getMatchingInstantFor(timeZoneImpl, organized, offsetNano, offsetDisambig, epochDisambig, !timeZoneImpl.offsetNano, organized.hasZ) : getStartOfDayInstantFor(timeZoneImpl, organized),
|
|
1150
|
+
createZonedDateTimeSlots(epochNano, timeZoneId, resolveCalendarId(organized.calendar));
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
function finalizeDateTime(organized) {
|
|
1154
|
+
return resolveSlotsCalendar(checkIsoDateTimeInBounds(checkIsoDateTimeFields(organized)));
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
function finalizeDate(organized) {
|
|
1158
|
+
return resolveSlotsCalendar(checkIsoDateInBounds(checkIsoDateFields(organized)));
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
function resolveSlotsCalendar(organized) {
|
|
1162
|
+
return {
|
|
1163
|
+
...organized,
|
|
1164
|
+
calendar: resolveCalendarId(organized.calendar)
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
function parseDateTimeLike(s) {
|
|
1169
|
+
const parts = dateTimeRegExp.exec(s);
|
|
1170
|
+
return parts ? (parts => {
|
|
1171
|
+
const zOrOffset = parts[10], hasZ = "Z" === (zOrOffset || "").toUpperCase();
|
|
1172
|
+
return {
|
|
1173
|
+
isoYear: organizeIsoYearParts(parts),
|
|
1174
|
+
isoMonth: parseInt(parts[4]),
|
|
1175
|
+
isoDay: parseInt(parts[5]),
|
|
1176
|
+
...organizeTimeParts(parts.slice(5)),
|
|
1177
|
+
...organizeAnnotationParts(parts[16]),
|
|
1178
|
+
hasTime: Boolean(parts[6]),
|
|
1179
|
+
hasZ: hasZ,
|
|
1180
|
+
offset: hasZ ? void 0 : zOrOffset
|
|
1181
|
+
};
|
|
1182
|
+
})(parts) : void 0;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
function parseYearMonthOnly(s) {
|
|
1186
|
+
const parts = yearMonthRegExp.exec(s);
|
|
1187
|
+
return parts ? (parts => ({
|
|
1188
|
+
isoYear: organizeIsoYearParts(parts),
|
|
1189
|
+
isoMonth: parseInt(parts[4]),
|
|
1190
|
+
isoDay: 1,
|
|
1191
|
+
...organizeAnnotationParts(parts[5])
|
|
1192
|
+
}))(parts) : void 0;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
function parseMonthDayOnly(s) {
|
|
1196
|
+
const parts = monthDayRegExp.exec(s);
|
|
1197
|
+
return parts ? (parts => ({
|
|
1198
|
+
isoYear: isoEpochFirstLeapYear,
|
|
1199
|
+
isoMonth: parseInt(parts[1]),
|
|
1200
|
+
isoDay: parseInt(parts[2]),
|
|
1201
|
+
...organizeAnnotationParts(parts[3])
|
|
1202
|
+
}))(parts) : void 0;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
function parseOffsetNanoMaybe(s, onlyHourMinute) {
|
|
1206
|
+
const parts = offsetRegExp.exec(s);
|
|
1207
|
+
return parts ? ((parts, onlyHourMinute) => {
|
|
1208
|
+
const firstSubMinutePart = parts[4] || parts[5];
|
|
1209
|
+
if (onlyHourMinute && firstSubMinutePart) {
|
|
1210
|
+
throw new RangeError(invalidSubstring(firstSubMinutePart));
|
|
1211
|
+
}
|
|
1212
|
+
return (offsetNano => {
|
|
1213
|
+
if (Math.abs(offsetNano) >= nanoInUtcDay) {
|
|
1214
|
+
throw new RangeError(outOfBoundsOffset);
|
|
1215
|
+
}
|
|
1216
|
+
return offsetNano;
|
|
1217
|
+
})((parseInt0(parts[2]) * nanoInHour + parseInt0(parts[3]) * nanoInMinute + parseInt0(parts[4]) * nanoInSec + parseSubsecNano(parts[5] || "")) * parseSign(parts[1]));
|
|
1218
|
+
})(parts, onlyHourMinute) : void 0;
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
function organizeIsoYearParts(parts) {
|
|
1222
|
+
const yearSign = parseSign(parts[1]), year = parseInt(parts[2] || parts[3]);
|
|
1223
|
+
if (yearSign < 0 && !year) {
|
|
1224
|
+
throw new RangeError(invalidSubstring(-0));
|
|
1225
|
+
}
|
|
1226
|
+
return yearSign * year;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
function organizeTimeParts(parts) {
|
|
1230
|
+
const isoSecond = parseInt0(parts[3]);
|
|
1231
|
+
return {
|
|
1232
|
+
...nanoToIsoTimeAndDay(parseSubsecNano(parts[4] || ""))[0],
|
|
1233
|
+
isoHour: parseInt0(parts[1]),
|
|
1234
|
+
isoMinute: parseInt0(parts[2]),
|
|
1235
|
+
isoSecond: 60 === isoSecond ? 59 : isoSecond
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
function organizeAnnotationParts(s) {
|
|
1240
|
+
let calendarIsCritical, timeZoneId;
|
|
1241
|
+
const calendarIds = [];
|
|
1242
|
+
if (s.replace(annotationRegExp, ((whole, criticalStr, mainStr) => {
|
|
1243
|
+
const isCritical = Boolean(criticalStr), [val, name] = mainStr.split("=").reverse();
|
|
1244
|
+
if (name) {
|
|
1245
|
+
if ("u-ca" === name) {
|
|
1246
|
+
calendarIds.push(val), calendarIsCritical || (calendarIsCritical = isCritical);
|
|
1247
|
+
} else if (isCritical || /[A-Z]/.test(name)) {
|
|
1248
|
+
throw new RangeError(invalidSubstring(whole));
|
|
1249
|
+
}
|
|
1250
|
+
} else {
|
|
1251
|
+
if (timeZoneId) {
|
|
1252
|
+
throw new RangeError(invalidSubstring(whole));
|
|
1253
|
+
}
|
|
1254
|
+
timeZoneId = val;
|
|
1255
|
+
}
|
|
1256
|
+
return "";
|
|
1257
|
+
})), calendarIds.length > 1 && calendarIsCritical) {
|
|
1258
|
+
throw new RangeError(invalidSubstring(s));
|
|
1259
|
+
}
|
|
1260
|
+
return {
|
|
1261
|
+
timeZone: timeZoneId,
|
|
1262
|
+
calendar: calendarIds[0] || isoCalendarId
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function parseSubsecNano(fracStr) {
|
|
1267
|
+
return parseInt(fracStr.padEnd(9, "0"));
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
function createRegExp(meat) {
|
|
1271
|
+
return new RegExp(`^${meat}$`, "i");
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function parseSign(s) {
|
|
1275
|
+
return s && "+" !== s ? -1 : 1;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
function parseInt0(s) {
|
|
1279
|
+
return void 0 === s ? 0 : parseInt(s);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function resolveTimeZoneId(id) {
|
|
1283
|
+
const essence = getTimeZoneEssence(id);
|
|
1284
|
+
return "number" == typeof essence ? formatOffsetNano(essence) : essence ? (id => {
|
|
1285
|
+
if (badCharactersRegExp.test(id)) {
|
|
1286
|
+
throw new RangeError(invalidTimeZone(id));
|
|
1287
|
+
}
|
|
1288
|
+
if (icuRegExp.test(id)) {
|
|
1289
|
+
throw new RangeError(forbiddenIcuTimeZone);
|
|
1290
|
+
}
|
|
1291
|
+
return id.toLowerCase().split("/").map(((part, partI) => (part.length <= 3 || /\d/.test(part)) && !/etc|yap/.test(part) ? part.toUpperCase() : part.replace(/baja|dumont|[a-z]+/g, ((a, i) => a.length <= 2 && !partI || "in" === a || "chat" === a ? a.toUpperCase() : a.length > 2 || !i ? capitalize(a).replace(/island|noronha|murdo|rivadavia|urville/, capitalize) : a)))).join("/");
|
|
1292
|
+
})(id) : utcTimeZoneId;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
function getTimeZoneAtomic(id) {
|
|
1296
|
+
const essence = getTimeZoneEssence(id);
|
|
1297
|
+
return "number" == typeof essence ? essence : essence ? essence.resolvedOptions().timeZone : utcTimeZoneId;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
function getTimeZoneEssence(id) {
|
|
1301
|
+
const offsetNano = parseOffsetNanoMaybe(id = id.toUpperCase(), 1);
|
|
1302
|
+
return void 0 !== offsetNano ? offsetNano : id !== utcTimeZoneId ? queryTimeZoneIntlFormat(id) : void 0;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
function compareInstants(instantSlots0, instantSlots1) {
|
|
1306
|
+
return compareBigNanos(instantSlots0.epochNanoseconds, instantSlots1.epochNanoseconds);
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
function compareZonedDateTimes(zonedDateTimeSlots0, zonedDateTimeSlots1) {
|
|
1310
|
+
return compareBigNanos(zonedDateTimeSlots0.epochNanoseconds, zonedDateTimeSlots1.epochNanoseconds);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
function compareIsoDateTimeFields(isoFields0, isoFields1) {
|
|
1314
|
+
return compareIsoDateFields(isoFields0, isoFields1) || compareIsoTimeFields(isoFields0, isoFields1);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
function compareIsoDateFields(isoFields0, isoFields1) {
|
|
1318
|
+
return compareNumbers(isoToEpochMilli(isoFields0), isoToEpochMilli(isoFields1));
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
function compareIsoTimeFields(isoFields0, isoFields1) {
|
|
1322
|
+
return compareNumbers(isoTimeFieldsToNano(isoFields0), isoTimeFieldsToNano(isoFields1));
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
function isTimeZoneIdsEqual(a, b) {
|
|
1326
|
+
if (a === b) {
|
|
1327
|
+
return 1;
|
|
1328
|
+
}
|
|
1329
|
+
try {
|
|
1330
|
+
return getTimeZoneAtomic(a) === getTimeZoneAtomic(b);
|
|
1331
|
+
} catch (_a) {}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
function diffDateLike(invert, getCalendarOps, startIsoFields, endIsoFields, largestUnit, smallestUnit, roundingInc, roundingMode, smallestPrecision = 6) {
|
|
1335
|
+
const startEpochNano = isoToEpochNano(startIsoFields), endEpochNano = isoToEpochNano(endIsoFields);
|
|
1336
|
+
if (void 0 === startEpochNano || void 0 === endEpochNano) {
|
|
1337
|
+
throw new RangeError(outOfBoundsDate);
|
|
1338
|
+
}
|
|
1339
|
+
let durationFields;
|
|
1340
|
+
if (compareBigNanos(endEpochNano, startEpochNano)) {
|
|
1341
|
+
if (6 === largestUnit) {
|
|
1342
|
+
durationFields = diffEpochNanos(startEpochNano, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode);
|
|
1343
|
+
} else {
|
|
1344
|
+
const calendarOps = getCalendarOps();
|
|
1345
|
+
durationFields = calendarOps.dateUntil(startIsoFields, endIsoFields, largestUnit),
|
|
1346
|
+
smallestUnit === smallestPrecision && 1 === roundingInc || (durationFields = roundRelativeDuration(durationFields, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, startIsoFields, isoToEpochNano, moveDate));
|
|
1347
|
+
}
|
|
1348
|
+
} else {
|
|
1349
|
+
durationFields = durationFieldDefaults;
|
|
1350
|
+
}
|
|
1351
|
+
return createDurationSlots(invert ? negateDurationFields(durationFields) : durationFields);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
function diffZonedEpochsExact(timeZoneOps, calendarOps, slots0, slots1, largestUnit, origOptions) {
|
|
1355
|
+
const sign = compareBigNanos(slots1.epochNanoseconds, slots0.epochNanoseconds);
|
|
1356
|
+
return sign ? largestUnit < 6 ? diffEpochNanosExact(slots0.epochNanoseconds, slots1.epochNanoseconds, largestUnit) : diffZonedEpochsBig(calendarOps, timeZoneOps, slots0, slots1, sign, largestUnit, origOptions) : durationFieldDefaults;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
function diffDateTimesExact(calendarOps, startIsoFields, endIsoFields, largestUnit, origOptions) {
|
|
1360
|
+
const startEpochNano = isoToEpochNano(startIsoFields), endEpochNano = isoToEpochNano(endIsoFields), sign = compareBigNanos(endEpochNano, startEpochNano);
|
|
1361
|
+
return sign ? largestUnit <= 6 ? diffEpochNanosExact(startEpochNano, endEpochNano, largestUnit) : diffDateTimesBig(calendarOps, startIsoFields, endIsoFields, sign, largestUnit, origOptions) : durationFieldDefaults;
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function diffZonedEpochsBig(calendarOps, timeZoneOps, slots0, slots1, sign, largestUnit, origOptions) {
|
|
1365
|
+
const [isoFields0, isoFields1, remainderNano] = ((timeZoneOps, slots0, slots1, sign) => {
|
|
1366
|
+
function updateMid() {
|
|
1367
|
+
return midIsoFields = {
|
|
1368
|
+
...moveByDays(endIsoFields, dayCorrection++ * -sign),
|
|
1369
|
+
...startIsoTimeFields
|
|
1370
|
+
}, midEpochNano = getSingleInstantFor(timeZoneOps, midIsoFields), compareBigNanos(endEpochNano, midEpochNano) === -sign;
|
|
1371
|
+
}
|
|
1372
|
+
const startIsoFields = zonedEpochSlotsToIso(slots0, timeZoneOps), startIsoTimeFields = pluckProps(isoTimeFieldNamesAsc, startIsoFields), endIsoFields = zonedEpochSlotsToIso(slots1, timeZoneOps), endEpochNano = slots1.epochNanoseconds;
|
|
1373
|
+
let dayCorrection = 0;
|
|
1374
|
+
const timeDiffNano = diffTimes(startIsoFields, endIsoFields);
|
|
1375
|
+
let midIsoFields, midEpochNano;
|
|
1376
|
+
if (Math.sign(timeDiffNano) === -sign && dayCorrection++, updateMid() && (-1 === sign || updateMid())) {
|
|
1377
|
+
throw new RangeError(invalidProtocolResults);
|
|
1378
|
+
}
|
|
1379
|
+
const remainderNano = bigNanoToNumber(diffBigNanos(midEpochNano, endEpochNano));
|
|
1380
|
+
return [ startIsoFields, midIsoFields, remainderNano ];
|
|
1381
|
+
})(timeZoneOps, slots0, slots1, sign);
|
|
1382
|
+
var startIsoFields, endIsoFields;
|
|
1383
|
+
return {
|
|
1384
|
+
...6 === largestUnit ? (startIsoFields = isoFields0, endIsoFields = isoFields1,
|
|
1385
|
+
{
|
|
1386
|
+
...durationFieldDefaults,
|
|
1387
|
+
days: diffDays(startIsoFields, endIsoFields)
|
|
1388
|
+
}) : calendarOps.dateUntil(isoFields0, isoFields1, largestUnit, origOptions),
|
|
1389
|
+
...nanoToDurationTimeFields(remainderNano)
|
|
1390
|
+
};
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
function diffDateTimesBig(calendarOps, startIsoFields, endIsoFields, sign, largestUnit, origOptions) {
|
|
1394
|
+
const [startIsoDate, endIsoDate, timeNano] = ((startIsoDateTime, endIsoDateTime, sign) => {
|
|
1395
|
+
let endIsoDate = endIsoDateTime, timeDiffNano = diffTimes(startIsoDateTime, endIsoDateTime);
|
|
1396
|
+
return Math.sign(timeDiffNano) === -sign && (endIsoDate = moveByDays(endIsoDateTime, -sign),
|
|
1397
|
+
timeDiffNano += nanoInUtcDay * sign), [ startIsoDateTime, endIsoDate, timeDiffNano ];
|
|
1398
|
+
})(startIsoFields, endIsoFields, sign);
|
|
1399
|
+
return {
|
|
1400
|
+
...calendarOps.dateUntil(startIsoDate, endIsoDate, largestUnit, origOptions),
|
|
1401
|
+
...nanoToDurationTimeFields(timeNano)
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
function diffEpochNanos(startEpochNano, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode) {
|
|
1406
|
+
return {
|
|
1407
|
+
...durationFieldDefaults,
|
|
1408
|
+
...nanoToDurationDayTimeFields(roundBigNano(diffBigNanos(startEpochNano, endEpochNano), smallestUnit, roundingInc, roundingMode), largestUnit)
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
function diffEpochNanosExact(startEpochNano, endEpochNano, largestUnit) {
|
|
1413
|
+
return {
|
|
1414
|
+
...durationFieldDefaults,
|
|
1415
|
+
...nanoToDurationDayTimeFields(diffBigNanos(startEpochNano, endEpochNano), largestUnit)
|
|
1416
|
+
};
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
function diffDays(startIsoFields, endIsoFields) {
|
|
1420
|
+
return diffEpochMilliByDay(isoToEpochMilli(startIsoFields), isoToEpochMilli(endIsoFields));
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
function diffEpochMilliByDay(epochMilli0, epochMilli1) {
|
|
1424
|
+
return Math.trunc((epochMilli1 - epochMilli0) / milliInDay);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
function diffTimes(isoTime0, isoTime1) {
|
|
1428
|
+
return isoTimeFieldsToNano(isoTime1) - isoTimeFieldsToNano(isoTime0);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
function getCommonCalendarId(a, b) {
|
|
1432
|
+
if (a !== b) {
|
|
1433
|
+
throw new RangeError(mismatchingCalendars);
|
|
1434
|
+
}
|
|
1435
|
+
return a;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
function computeNativeWeekOfYear(isoFields) {
|
|
1439
|
+
return this.weekParts(isoFields)[0];
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function computeNativeYearOfWeek(isoFields) {
|
|
1443
|
+
return this.weekParts(isoFields)[1];
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
function computeNativeDayOfYear(isoFields) {
|
|
1447
|
+
const [year] = this.dateParts(isoFields);
|
|
1448
|
+
return diffEpochMilliByDay(this.epochMilli(year), isoToEpochMilli(isoFields)) + 1;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
function parseMonthCode(monthCode) {
|
|
1452
|
+
const m = monthCodeRegExp.exec(monthCode);
|
|
1453
|
+
if (!m) {
|
|
1454
|
+
throw new RangeError(invalidMonthCode(monthCode));
|
|
1455
|
+
}
|
|
1456
|
+
return [ parseInt(m[1]), Boolean(m[2]) ];
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
function formatMonthCode(monthCodeNumber, isLeapMonth) {
|
|
1460
|
+
return "M" + padNumber2(monthCodeNumber) + (isLeapMonth ? "L" : "");
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
function monthCodeNumberToMonth(monthCodeNumber, isLeapMonth, leapMonth) {
|
|
1464
|
+
return monthCodeNumber + (isLeapMonth || leapMonth && monthCodeNumber >= leapMonth ? 1 : 0);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
function monthToMonthCodeNumber(month, leapMonth) {
|
|
1468
|
+
return month - (leapMonth && month >= leapMonth ? 1 : 0);
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function eraYearToYear(eraYear, eraOrigin) {
|
|
1472
|
+
return (eraOrigin + eraYear) * (Math.sign(eraOrigin) || 1) || 0;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
function getCalendarEraOrigins(native) {
|
|
1476
|
+
return eraOriginsByCalendarId[getCalendarIdBase(native)];
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
function getCalendarLeapMonthMeta(native) {
|
|
1480
|
+
return leapMonthMetas[getCalendarIdBase(native)];
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
function getCalendarIdBase(native) {
|
|
1484
|
+
return computeCalendarIdBase(native.id || isoCalendarId);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
function createIntlFieldCache(epochMilliToIntlFields) {
|
|
1488
|
+
return memoize((isoDateFields => {
|
|
1489
|
+
const epochMilli = isoToEpochMilli(isoDateFields);
|
|
1490
|
+
return epochMilliToIntlFields(epochMilli);
|
|
1491
|
+
}), WeakMap);
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
function createIntlYearDataCache(epochMilliToIntlFields) {
|
|
1495
|
+
const yearCorrection = epochMilliToIntlFields(0).year - isoEpochOriginYear;
|
|
1496
|
+
return memoize((year => {
|
|
1497
|
+
let intlFields, epochMilli = isoArgsToEpochMilli(year - yearCorrection), iterations = 0;
|
|
1498
|
+
const millisReversed = [], monthStringsReversed = [];
|
|
1499
|
+
do {
|
|
1500
|
+
epochMilli += 400 * milliInDay;
|
|
1501
|
+
} while ((intlFields = epochMilliToIntlFields(epochMilli)).year <= year);
|
|
1502
|
+
do {
|
|
1503
|
+
if (epochMilli += (1 - intlFields.day) * milliInDay, intlFields.year === year && (millisReversed.push(epochMilli),
|
|
1504
|
+
monthStringsReversed.push(intlFields.monthString)), epochMilli -= milliInDay, ++iterations > 100 || epochMilli < -maxMilli) {
|
|
1505
|
+
throw new RangeError(invalidProtocolResults);
|
|
1506
|
+
}
|
|
1507
|
+
} while ((intlFields = epochMilliToIntlFields(epochMilli)).year >= year);
|
|
1508
|
+
return {
|
|
1509
|
+
monthEpochMillis: millisReversed.reverse(),
|
|
1510
|
+
monthStringToIndex: mapPropNamesToIndex(monthStringsReversed.reverse())
|
|
1511
|
+
};
|
|
1512
|
+
}));
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
function parseIntlYear(intlParts, calendarIdBase) {
|
|
1516
|
+
let era, eraYear, year = parseIntlPartsYear(intlParts);
|
|
1517
|
+
if (intlParts.era) {
|
|
1518
|
+
const eraOrigins = eraOriginsByCalendarId[calendarIdBase], eraRemaps = eraRemapsByCalendarId[calendarIdBase] || {};
|
|
1519
|
+
void 0 !== eraOrigins && (era = "islamic" === calendarIdBase ? "ah" : intlParts.era.normalize("NFD").toLowerCase().replace(/[^a-z0-9]/g, ""),
|
|
1520
|
+
"bc" === era || "b" === era ? era = "bce" : "ad" === era || "a" === era ? era = "ce" : "beforeroc" === era && (era = "broc"),
|
|
1521
|
+
era = eraRemaps[era] || era, eraYear = year, year = eraYearToYear(eraYear, eraOrigins[era] || 0));
|
|
1522
|
+
}
|
|
1523
|
+
return {
|
|
1524
|
+
era: era,
|
|
1525
|
+
eraYear: eraYear,
|
|
1526
|
+
year: year
|
|
1527
|
+
};
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
function parseIntlPartsYear(intlParts) {
|
|
1531
|
+
return parseInt(intlParts.relatedYear || intlParts.year);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
function computeIntlDateParts(isoFields) {
|
|
1535
|
+
const {year: year, monthString: monthString, day: day} = this.queryFields(isoFields), {monthStringToIndex: monthStringToIndex} = this.queryYearData(year);
|
|
1536
|
+
return [ year, monthStringToIndex[monthString] + 1, day ];
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
function computeIntlEpochMilli(year, month = 1, day = 1) {
|
|
1540
|
+
return this.queryYearData(year).monthEpochMillis[month - 1] + (day - 1) * milliInDay;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
function computeIntlMonthCodeParts(year, month) {
|
|
1544
|
+
const leapMonth = computeIntlLeapMonth.call(this, year);
|
|
1545
|
+
return [ monthToMonthCodeNumber(month, leapMonth), leapMonth === month ];
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
function computeIntlLeapMonth(year) {
|
|
1549
|
+
const currentMonthStrings = queryMonthStrings(this, year), prevMonthStrings = queryMonthStrings(this, year - 1), currentLength = currentMonthStrings.length;
|
|
1550
|
+
if (currentLength > prevMonthStrings.length) {
|
|
1551
|
+
const leapMonthMeta = getCalendarLeapMonthMeta(this);
|
|
1552
|
+
if (leapMonthMeta < 0) {
|
|
1553
|
+
return -leapMonthMeta;
|
|
1554
|
+
}
|
|
1555
|
+
for (let i = 0; i < currentLength; i++) {
|
|
1556
|
+
if (currentMonthStrings[i] !== prevMonthStrings[i]) {
|
|
1557
|
+
return i + 1;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
function computeIntlDaysInYear(year) {
|
|
1564
|
+
return diffEpochMilliByDay(computeIntlEpochMilli.call(this, year), computeIntlEpochMilli.call(this, year + 1));
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
function computeIntlDaysInMonth(year, month) {
|
|
1568
|
+
const {monthEpochMillis: monthEpochMillis} = this.queryYearData(year);
|
|
1569
|
+
let nextMonth = month + 1, nextMonthEpochMilli = monthEpochMillis;
|
|
1570
|
+
return nextMonth > monthEpochMillis.length && (nextMonth = 1, nextMonthEpochMilli = this.queryYearData(year + 1).monthEpochMillis),
|
|
1571
|
+
diffEpochMilliByDay(monthEpochMillis[month - 1], nextMonthEpochMilli[nextMonth - 1]);
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
function computeIntlMonthsInYear(year) {
|
|
1575
|
+
return this.queryYearData(year).monthEpochMillis.length;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
function computeIntlEraParts(isoFields) {
|
|
1579
|
+
const intlFields = this.queryFields(isoFields);
|
|
1580
|
+
return [ intlFields.era, intlFields.eraYear ];
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function queryMonthStrings(intlCalendar, year) {
|
|
1584
|
+
return Object.keys(intlCalendar.queryYearData(year).monthStringToIndex);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
function resolveCalendarId(id) {
|
|
1588
|
+
if ((id = id.toLowerCase()) !== isoCalendarId && id !== gregoryCalendarId) {
|
|
1589
|
+
const canonId = queryCalendarIntlFormat(id).resolvedOptions().calendar;
|
|
1590
|
+
if (computeCalendarIdBase(id) !== computeCalendarIdBase(canonId)) {
|
|
1591
|
+
throw new RangeError(invalidCalendar(id));
|
|
1592
|
+
}
|
|
1593
|
+
return canonId;
|
|
1594
|
+
}
|
|
1595
|
+
return id;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
function computeCalendarIdBase(id) {
|
|
1599
|
+
return "islamicc" === id && (id = "islamic"), id.split("-")[0];
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
function createNativeOpsCreator(isoOps, intlOps) {
|
|
1603
|
+
return calendarId => calendarId === isoCalendarId ? isoOps : calendarId === gregoryCalendarId || "japanese" === calendarId ? Object.assign(Object.create(isoOps), {
|
|
1604
|
+
id: calendarId
|
|
1605
|
+
}) : Object.assign(Object.create(intlOps), queryIntlCalendar(calendarId));
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
function refineCalendarFields(calendarOps, bag, validFieldNames, requiredFieldNames = [], forcedValidFieldNames = []) {
|
|
1609
|
+
return refineFields(bag, [ ...calendarOps.fields(validFieldNames), ...forcedValidFieldNames ].sort(), requiredFieldNames);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
function refineFields(bag, validFieldNames, requiredFieldNames, disallowEmpty = !requiredFieldNames) {
|
|
1613
|
+
const res = {};
|
|
1614
|
+
let prevFieldName, anyMatching = 0;
|
|
1615
|
+
for (const fieldName of validFieldNames) {
|
|
1616
|
+
if (fieldName === prevFieldName) {
|
|
1617
|
+
throw new RangeError(duplicateFields(fieldName));
|
|
1618
|
+
}
|
|
1619
|
+
if ("constructor" === fieldName || "__proto__" === fieldName) {
|
|
1620
|
+
throw new RangeError(forbiddenField(fieldName));
|
|
1621
|
+
}
|
|
1622
|
+
let fieldVal = bag[fieldName];
|
|
1623
|
+
if (void 0 !== fieldVal) {
|
|
1624
|
+
anyMatching = 1, builtinRefiners[fieldName] && (fieldVal = builtinRefiners[fieldName](fieldVal, fieldName)),
|
|
1625
|
+
res[fieldName] = fieldVal;
|
|
1626
|
+
} else if (requiredFieldNames) {
|
|
1627
|
+
if (requiredFieldNames.includes(fieldName)) {
|
|
1628
|
+
throw new TypeError(missingField(fieldName));
|
|
1629
|
+
}
|
|
1630
|
+
res[fieldName] = timeFieldDefaults[fieldName];
|
|
1631
|
+
}
|
|
1632
|
+
prevFieldName = fieldName;
|
|
1633
|
+
}
|
|
1634
|
+
if (disallowEmpty && !anyMatching) {
|
|
1635
|
+
throw new TypeError(noValidFields(validFieldNames));
|
|
1636
|
+
}
|
|
1637
|
+
return res;
|
|
1638
|
+
}
|
|
1639
|
+
|
|
1640
|
+
function refineTimeBag(fields, overflow) {
|
|
1641
|
+
return constrainIsoTimeFields(timeFieldsToIso({
|
|
1642
|
+
...timeFieldDefaults,
|
|
1643
|
+
...fields
|
|
1644
|
+
}), overflow);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function convertToIso(calendarOps, input, inputFieldNames, extra, extraFieldNames) {
|
|
1648
|
+
input = pluckProps(inputFieldNames = calendarOps.fields(inputFieldNames), input),
|
|
1649
|
+
extra = refineFields(extra, extraFieldNames = calendarOps.fields(extraFieldNames), []);
|
|
1650
|
+
let mergedFields = calendarOps.mergeFields(input, extra);
|
|
1651
|
+
return mergedFields = refineFields(mergedFields, [ ...inputFieldNames, ...extraFieldNames ].sort(), []),
|
|
1652
|
+
calendarOps.dateFromFields(mergedFields);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
function refineYear(calendarNative, fields) {
|
|
1656
|
+
const eraOrigins = getCalendarEraOrigins(calendarNative), eraRemaps = eraRemapsByCalendarId[calendarNative.id || ""] || {};
|
|
1657
|
+
let {era: era, eraYear: eraYear, year: year} = fields;
|
|
1658
|
+
if (void 0 !== era || void 0 !== eraYear) {
|
|
1659
|
+
if (void 0 === era || void 0 === eraYear) {
|
|
1660
|
+
throw new TypeError(mismatchingEraParts);
|
|
1661
|
+
}
|
|
1662
|
+
if (!eraOrigins) {
|
|
1663
|
+
throw new RangeError(forbiddenEraParts);
|
|
1664
|
+
}
|
|
1665
|
+
const eraOrigin = eraOrigins[eraRemaps[era] || era];
|
|
1666
|
+
if (void 0 === eraOrigin) {
|
|
1667
|
+
throw new RangeError(invalidEra(era));
|
|
1668
|
+
}
|
|
1669
|
+
const yearByEra = eraYearToYear(eraYear, eraOrigin);
|
|
1670
|
+
if (void 0 !== year && year !== yearByEra) {
|
|
1671
|
+
throw new RangeError(mismatchingYearAndEra);
|
|
1672
|
+
}
|
|
1673
|
+
year = yearByEra;
|
|
1674
|
+
} else if (void 0 === year) {
|
|
1675
|
+
throw new TypeError(missingYear(eraOrigins));
|
|
1676
|
+
}
|
|
1677
|
+
return year;
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function refineMonth(calendarNative, fields, year, overflow) {
|
|
1681
|
+
let {month: month, monthCode: monthCode} = fields;
|
|
1682
|
+
if (void 0 !== monthCode) {
|
|
1683
|
+
const monthByCode = ((calendarNative, monthCode, year, overflow) => {
|
|
1684
|
+
const leapMonth = calendarNative.leapMonth(year), [monthCodeNumber, wantsLeapMonth] = parseMonthCode(monthCode);
|
|
1685
|
+
let month = monthCodeNumberToMonth(monthCodeNumber, wantsLeapMonth, leapMonth);
|
|
1686
|
+
if (wantsLeapMonth) {
|
|
1687
|
+
const leapMonthMeta = getCalendarLeapMonthMeta(calendarNative);
|
|
1688
|
+
if (void 0 === leapMonthMeta) {
|
|
1689
|
+
throw new RangeError(invalidLeapMonth);
|
|
1690
|
+
}
|
|
1691
|
+
if (leapMonthMeta > 0) {
|
|
1692
|
+
if (month > leapMonthMeta) {
|
|
1693
|
+
throw new RangeError(invalidLeapMonth);
|
|
1694
|
+
}
|
|
1695
|
+
if (void 0 === leapMonth) {
|
|
1696
|
+
if (1 === overflow) {
|
|
1697
|
+
throw new RangeError(invalidLeapMonth);
|
|
1698
|
+
}
|
|
1699
|
+
month--;
|
|
1700
|
+
}
|
|
1701
|
+
} else {
|
|
1702
|
+
if (month !== -leapMonthMeta) {
|
|
1703
|
+
throw new RangeError(invalidLeapMonth);
|
|
1704
|
+
}
|
|
1705
|
+
if (void 0 === leapMonth && 1 === overflow) {
|
|
1706
|
+
throw new RangeError(invalidLeapMonth);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
return month;
|
|
1711
|
+
})(calendarNative, monthCode, year, overflow);
|
|
1712
|
+
if (void 0 !== month && month !== monthByCode) {
|
|
1713
|
+
throw new RangeError(mismatchingMonthAndCode);
|
|
1714
|
+
}
|
|
1715
|
+
month = monthByCode, overflow = 1;
|
|
1716
|
+
} else if (void 0 === month) {
|
|
1717
|
+
throw new TypeError(missingMonth);
|
|
1718
|
+
}
|
|
1719
|
+
return clampEntity("month", month, 1, calendarNative.monthsInYearPart(year), overflow);
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
function refineDay(calendarNative, fields, month, year, overflow) {
|
|
1723
|
+
return clampProp(fields, "day", 1, calendarNative.daysInMonthParts(year, month), overflow);
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
function spliceFields(dest, additional, allPropNames, deletablePropNames) {
|
|
1727
|
+
let anyMatching = 0;
|
|
1728
|
+
const nonMatchingPropNames = [];
|
|
1729
|
+
for (const propName of allPropNames) {
|
|
1730
|
+
void 0 !== additional[propName] ? anyMatching = 1 : nonMatchingPropNames.push(propName);
|
|
1731
|
+
}
|
|
1732
|
+
if (Object.assign(dest, additional), anyMatching) {
|
|
1733
|
+
for (const deletablePropName of deletablePropNames || nonMatchingPropNames) {
|
|
1734
|
+
delete dest[deletablePropName];
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
function computeDateEssentials(slots) {
|
|
1740
|
+
const calendarOps = createNativePartOps(slots.calendar), [year, month, day] = calendarOps.dateParts(slots), [monthCodeNumber, isLeapMonth] = calendarOps.monthCodeParts(year, month);
|
|
1741
|
+
return {
|
|
1742
|
+
year: year,
|
|
1743
|
+
monthCode: formatMonthCode(monthCodeNumber, isLeapMonth),
|
|
1744
|
+
day: day
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
function createOptionsTransformer(standardNames, fallbacks, exclusions) {
|
|
1749
|
+
const excludedNameSet = new Set(exclusions);
|
|
1750
|
+
return (options, strictOptions) => {
|
|
1751
|
+
const hasAnyExclusions = exclusions && hasAnyPropsByName(options, exclusions);
|
|
1752
|
+
if (!hasAnyPropsByName(options = ((propNames, props) => {
|
|
1753
|
+
const filteredProps = {};
|
|
1754
|
+
for (const propName in props) {
|
|
1755
|
+
propNames.has(propName) || (filteredProps[propName] = props[propName]);
|
|
1756
|
+
}
|
|
1757
|
+
return filteredProps;
|
|
1758
|
+
})(excludedNameSet, options), standardNames)) {
|
|
1759
|
+
if (strictOptions && hasAnyExclusions) {
|
|
1760
|
+
throw new TypeError("Invalid formatting options");
|
|
1761
|
+
}
|
|
1762
|
+
options = {
|
|
1763
|
+
...fallbacks,
|
|
1764
|
+
...options
|
|
1765
|
+
};
|
|
1766
|
+
}
|
|
1767
|
+
return exclusions && (options.timeZone = utcTimeZoneId, [ "full", "long" ].includes(options.timeStyle) && (options.timeStyle = "medium")),
|
|
1768
|
+
options;
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
function createFormatForPrep(forcedTimeZoneId, locales, options, transformOptions, strictOptions) {
|
|
1773
|
+
if (options = transformOptions(options, strictOptions), forcedTimeZoneId) {
|
|
1774
|
+
if (void 0 !== options.timeZone) {
|
|
1775
|
+
throw new TypeError(forbiddenFormatTimeZone);
|
|
1776
|
+
}
|
|
1777
|
+
options.timeZone = forcedTimeZoneId;
|
|
1778
|
+
}
|
|
1779
|
+
return new RawDateTimeFormat(locales, options);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
function toEpochMillis(config, resolvedOptions, slotsList) {
|
|
1783
|
+
const [, slotsToEpochMilli, strictCalendarCheck] = config;
|
|
1784
|
+
return slotsList.map((slots => (slots.calendar && ((internalCalendarId, resolvedCalendarId, strictCalendarCheck) => {
|
|
1785
|
+
if ((strictCalendarCheck || internalCalendarId !== isoCalendarId) && internalCalendarId !== resolvedCalendarId) {
|
|
1786
|
+
throw new RangeError(mismatchingCalendars);
|
|
1787
|
+
}
|
|
1788
|
+
})(slots.calendar, resolvedOptions.calendar, strictCalendarCheck), slotsToEpochMilli(slots, resolvedOptions))));
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
function getCurrentEpochNano() {
|
|
1792
|
+
return numberToBigNano(Date.now(), nanoInMilli);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
const expectedInteger = (entityName, num) => `Non-integer ${entityName}: ${num}`, expectedPositive = (entityName, num) => `Non-positive ${entityName}: ${num}`, expectedFinite = (entityName, num) => `Non-finite ${entityName}: ${num}`, forbiddenBigIntToNumber = entityName => `Cannot convert bigint to ${entityName}`, invalidBigInt = arg => `Invalid bigint: ${arg}`, forbiddenSymbolToString = "Cannot convert Symbol to string", invalidObject = "Invalid object", numberOutOfRange = (entityName, val, min, max, choices) => choices ? numberOutOfRange(entityName, choices[val], choices[min], choices[max]) : invalidEntity(entityName, val) + `; must be between ${min}-${max}`, invalidEntity = (fieldName, val) => `Invalid ${fieldName}: ${val}`, missingField = fieldName => `Missing ${fieldName}`, forbiddenField = fieldName => `Invalid field ${fieldName}`, duplicateFields = fieldName => `Duplicate field ${fieldName}`, noValidFields = validFields => "No valid fields: " + validFields.join(), invalidChoice = (fieldName, val, choiceMap) => invalidEntity(fieldName, val) + "; must be " + Object.keys(choiceMap).join(), forbiddenEraParts = "Forbidden era/eraYear", mismatchingEraParts = "Mismatching era/eraYear", mismatchingYearAndEra = "Mismatching year/eraYear", invalidEra = era => `Invalid era: ${era}`, missingYear = allowEra => "Missing year" + (allowEra ? "/era/eraYear" : ""), invalidMonthCode = monthCode => `Invalid monthCode: ${monthCode}`, mismatchingMonthAndCode = "Mismatching month/monthCode", missingMonth = "Missing month/monthCode", invalidLeapMonth = "Invalid leap month", invalidProtocolResults = "Invalid protocol results", invalidCalendar = calendarId => invalidEntity("Calendar", calendarId), mismatchingCalendars = "Mismatching Calendars", invalidTimeZone = calendarId => invalidEntity("TimeZone", calendarId), forbiddenIcuTimeZone = "Forbidden ICU TimeZone", outOfBoundsOffset = "Out-of-bounds offset", outOfBoundsDstGap = "Out-of-bounds TimeZone gap", invalidOffsetForTimeZone = "Invalid TimeZone offset", ambigOffset = "Ambiguous offset", outOfBoundsDate = "Out-of-bounds date", outOfBoundsDuration = "Out-of-bounds duration", forbiddenDurationSigns = "Cannot mix duration signs", flippedSmallestLargestUnit = "smallestUnit > largestUnit", failedParse = s => `Cannot parse: ${s}`, invalidSubstring = substring => `Invalid substring: ${substring}`, forbiddenFormatTimeZone = "Cannot specify TimeZone", mapPropNamesToIndex = bindArgs(mapPropNames, ((_propVal, i) => i)), mapPropNamesToConstant = bindArgs(mapPropNames, ((_propVal, _i, constant) => constant)), padNumber2 = bindArgs(padNumber, 2), unitNameMap = {
|
|
1796
|
+
nanosecond: 0,
|
|
1797
|
+
microsecond: 1,
|
|
1798
|
+
millisecond: 2,
|
|
1799
|
+
second: 3,
|
|
1800
|
+
minute: 4,
|
|
1801
|
+
hour: 5,
|
|
1802
|
+
day: 6,
|
|
1803
|
+
week: 7,
|
|
1804
|
+
month: 8,
|
|
1805
|
+
year: 9
|
|
1806
|
+
}, unitNamesAsc = Object.keys(unitNameMap), milliInDay = 864e5, milliInSec = 1e3, nanoInMicro = 1e3, nanoInMilli = 1e6, nanoInSec = 1e9, nanoInMinute = 6e10, nanoInHour = 36e11, nanoInUtcDay = 864e11, unitNanoMap = [ 1, nanoInMicro, nanoInMilli, nanoInSec, nanoInMinute, nanoInHour, nanoInUtcDay ], timeFieldNamesAsc = unitNamesAsc.slice(0, 6), timeFieldNamesAlpha = sortStrings(timeFieldNamesAsc), timeZoneFieldNames = [ "timeZone" ], timeAndOffsetFieldNames = [ ...timeFieldNamesAsc, "offset" ], timeAndZoneFieldNames = [ ...timeAndOffsetFieldNames, ...timeZoneFieldNames ], eraYearFieldNames = [ "era", "eraYear" ], allYearFieldNames = [ ...eraYearFieldNames, "year" ], yearFieldNames = [ "year" ], monthCodeFieldNames = [ "monthCode" ], monthFieldNames = [ "month", ...monthCodeFieldNames ], dayFieldNames = [ "day" ], yearMonthFieldNames = [ ...monthFieldNames, ...yearFieldNames ], yearMonthCodeFieldNames = [ ...monthCodeFieldNames, ...yearFieldNames ], dateFieldNamesAlpha = [ ...dayFieldNames, ...yearMonthFieldNames ], monthDayFieldNames = [ ...dayFieldNames, ...monthFieldNames ], monthCodeDayFieldNames = [ ...dayFieldNames, ...monthCodeFieldNames ], timeFieldDefaults = mapPropNamesToConstant(timeFieldNamesAsc, 0), isoCalendarId = "iso8601", gregoryCalendarId = "gregory", eraOriginsByCalendarId = {
|
|
1807
|
+
[gregoryCalendarId]: {
|
|
1808
|
+
"gregory-inverse": -1,
|
|
1809
|
+
gregory: 0
|
|
1810
|
+
},
|
|
1811
|
+
japanese: {
|
|
1812
|
+
"japanese-inverse": -1,
|
|
1813
|
+
japanese: 0,
|
|
1814
|
+
meiji: 1867,
|
|
1815
|
+
taisho: 1911,
|
|
1816
|
+
showa: 1925,
|
|
1817
|
+
heisei: 1988,
|
|
1818
|
+
reiwa: 2018
|
|
1819
|
+
},
|
|
1820
|
+
ethiopic: {
|
|
1821
|
+
ethioaa: 0,
|
|
1822
|
+
ethiopic: 5500
|
|
1823
|
+
},
|
|
1824
|
+
coptic: {
|
|
1825
|
+
"coptic-inverse": -1,
|
|
1826
|
+
coptic: 0
|
|
1827
|
+
},
|
|
1828
|
+
roc: {
|
|
1829
|
+
"roc-inverse": -1,
|
|
1830
|
+
roc: 0
|
|
1831
|
+
},
|
|
1832
|
+
buddhist: {
|
|
1833
|
+
be: 0
|
|
1834
|
+
},
|
|
1835
|
+
islamic: {
|
|
1836
|
+
ah: 0
|
|
1837
|
+
},
|
|
1838
|
+
indian: {
|
|
1839
|
+
saka: 0
|
|
1840
|
+
},
|
|
1841
|
+
persian: {
|
|
1842
|
+
ap: 0
|
|
1843
|
+
}
|
|
1844
|
+
}, eraRemapsByCalendarId = {
|
|
1845
|
+
[gregoryCalendarId]: {
|
|
1846
|
+
bce: "gregory-inverse",
|
|
1847
|
+
ce: "gregory"
|
|
1848
|
+
},
|
|
1849
|
+
japanese: {
|
|
1850
|
+
bce: "japanese-inverse",
|
|
1851
|
+
ce: "japanese"
|
|
1852
|
+
},
|
|
1853
|
+
ethiopic: {
|
|
1854
|
+
era0: "ethioaa",
|
|
1855
|
+
era1: "ethiopic"
|
|
1856
|
+
},
|
|
1857
|
+
coptic: {
|
|
1858
|
+
era0: "coptic-inverse",
|
|
1859
|
+
era1: "coptic"
|
|
1860
|
+
},
|
|
1861
|
+
roc: {
|
|
1862
|
+
broc: "roc-inverse",
|
|
1863
|
+
minguo: "roc"
|
|
1864
|
+
}
|
|
1865
|
+
}, leapMonthMetas = {
|
|
1866
|
+
chinese: 13,
|
|
1867
|
+
dangi: 13,
|
|
1868
|
+
hebrew: -6
|
|
1869
|
+
}, requireString = bindArgs(requireType, "string"), requireBoolean = bindArgs(requireType, "boolean"), requireNumber = bindArgs(requireType, "number"), durationFieldNamesAsc = unitNamesAsc.map((unitName => unitName + "s")), durationFieldNamesAlpha = sortStrings(durationFieldNamesAsc), durationTimeFieldNamesAsc = durationFieldNamesAsc.slice(0, 6), durationDateFieldNamesAsc = durationFieldNamesAsc.slice(6), durationCalendarFieldNamesAsc = durationDateFieldNamesAsc.slice(1), durationFieldIndexes = mapPropNamesToIndex(durationFieldNamesAsc), durationFieldDefaults = mapPropNamesToConstant(durationFieldNamesAsc, 0), durationTimeFieldDefaults = mapPropNamesToConstant(durationTimeFieldNamesAsc, 0), clearDurationFields = bindArgs(zeroOutProps, durationFieldNamesAsc), isoTimeFieldNamesAsc = [ "isoNanosecond", "isoMicrosecond", "isoMillisecond", "isoSecond", "isoMinute", "isoHour" ], isoDateFieldNamesAsc = [ "isoDay", "isoMonth", "isoYear" ], isoDateTimeFieldNamesAsc = [ ...isoTimeFieldNamesAsc, ...isoDateFieldNamesAsc ], isoDateFieldNamesAlpha = sortStrings(isoDateFieldNamesAsc), isoTimeFieldNamesAlpha = sortStrings(isoTimeFieldNamesAsc), isoDateTimeFieldNamesAlpha = sortStrings(isoDateTimeFieldNamesAsc), isoTimeFieldDefaults = mapPropNamesToConstant(isoTimeFieldNamesAlpha, 0), clearIsoFields = bindArgs(zeroOutProps, isoDateTimeFieldNamesAsc), maxMilli = 1e8 * milliInDay, epochNanoMax = [ 1e8, 0 ], epochNanoMin = [ -1e8, 0 ], isoYearMax = 275760, isoYearMin = -271821, RawDateTimeFormat = Intl.DateTimeFormat, isoEpochOriginYear = 1970, isoEpochFirstLeapYear = 1972, isoMonthsInYear = 12, primaryJapaneseEraMilli = isoArgsToEpochMilli(1868, 9, 8), queryJapaneseEraParts = memoize((isoFields => {
|
|
1870
|
+
const epochMilli = isoToEpochMilli(isoFields);
|
|
1871
|
+
if (epochMilli < primaryJapaneseEraMilli) {
|
|
1872
|
+
const {isoYear: isoYear} = isoFields;
|
|
1873
|
+
return isoYear < 1 ? [ "japanese-inverse", 1 - isoYear ] : [ "japanese", isoYear ];
|
|
1874
|
+
}
|
|
1875
|
+
const intlParts = hashIntlFormatParts(queryCalendarIntlFormat("japanese"), epochMilli), {era: era, eraYear: eraYear} = parseIntlYear(intlParts, "japanese");
|
|
1876
|
+
return [ era, eraYear ];
|
|
1877
|
+
}), WeakMap), smallestUnitStr = "smallestUnit", roundingIncName = "roundingIncrement", subsecDigitsName = "fractionalSecondDigits", overflowMap = {
|
|
1878
|
+
constrain: 0,
|
|
1879
|
+
reject: 1
|
|
1880
|
+
}, overflowMapNames = Object.keys(overflowMap), directionMap = {
|
|
1881
|
+
previous: -1,
|
|
1882
|
+
next: 1
|
|
1883
|
+
}, refineSmallestUnit = bindArgs(refineUnitOption, smallestUnitStr), refineLargestUnit = bindArgs(refineUnitOption, "largestUnit"), refineTotalUnit = bindArgs(refineUnitOption, "unit"), refineOverflow = bindArgs(refineChoiceOption, "overflow", overflowMap), refineEpochDisambig = bindArgs(refineChoiceOption, "disambiguation", {
|
|
1884
|
+
compatible: 0,
|
|
1885
|
+
reject: 1,
|
|
1886
|
+
earlier: 2,
|
|
1887
|
+
later: 3
|
|
1888
|
+
}), refineOffsetDisambig = bindArgs(refineChoiceOption, "offset", {
|
|
1889
|
+
reject: 0,
|
|
1890
|
+
use: 1,
|
|
1891
|
+
prefer: 2,
|
|
1892
|
+
ignore: 3
|
|
1893
|
+
}), refineCalendarDisplay = bindArgs(refineChoiceOption, "calendarName", {
|
|
1894
|
+
auto: 0,
|
|
1895
|
+
never: 1,
|
|
1896
|
+
critical: 2,
|
|
1897
|
+
always: 3
|
|
1898
|
+
}), refineTimeZoneDisplay = bindArgs(refineChoiceOption, "timeZoneName", {
|
|
1899
|
+
auto: 0,
|
|
1900
|
+
never: 1,
|
|
1901
|
+
critical: 2
|
|
1902
|
+
}), refineOffsetDisplay = bindArgs(refineChoiceOption, "offset", {
|
|
1903
|
+
auto: 0,
|
|
1904
|
+
never: 1
|
|
1905
|
+
}), refineRoundingMode = bindArgs(refineChoiceOption, "roundingMode", {
|
|
1906
|
+
floor: 0,
|
|
1907
|
+
halfFloor: 1,
|
|
1908
|
+
ceil: 2,
|
|
1909
|
+
halfCeil: 3,
|
|
1910
|
+
trunc: 4,
|
|
1911
|
+
halfTrunc: 5,
|
|
1912
|
+
expand: 6,
|
|
1913
|
+
halfExpand: 7,
|
|
1914
|
+
halfEven: 8
|
|
1915
|
+
}), PlainYearMonthBranding = "PlainYearMonth", PlainMonthDayBranding = "PlainMonthDay", PlainDateBranding = "PlainDate", PlainDateTimeBranding = "PlainDateTime", PlainTimeBranding = "PlainTime", ZonedDateTimeBranding = "ZonedDateTime", InstantBranding = "Instant", DurationBranding = "Duration", roundingModeFuncs = [ Math.floor, num => hasHalf(num) ? Math.floor(num) : Math.round(num), Math.ceil, num => hasHalf(num) ? Math.ceil(num) : Math.round(num), Math.trunc, num => hasHalf(num) ? Math.trunc(num) || 0 : Math.round(num), num => num < 0 ? Math.floor(num) : Math.ceil(num), num => Math.sign(num) * Math.round(Math.abs(num)) || 0, num => hasHalf(num) ? (num = Math.trunc(num) || 0) + num % 2 : Math.round(num) ], utcTimeZoneId = "UTC", periodDur = 5184e3, minPossibleTransition = isoArgsToEpochSec(1847), maxPossibleTransition = isoArgsToEpochSec(new Date(0).getUTCFullYear() + 10), trailingZerosRE = /0+$/, zonedEpochSlotsToIso = memoize(((slots, getTimeZoneOps) => {
|
|
1916
|
+
const {epochNanoseconds: epochNanoseconds} = slots, offsetNanoseconds = (getTimeZoneOps.getOffsetNanosecondsFor ? getTimeZoneOps : getTimeZoneOps(slots.timeZone)).getOffsetNanosecondsFor(epochNanoseconds), isoDateTimeFields = epochNanoToIso(epochNanoseconds, offsetNanoseconds);
|
|
1917
|
+
return {
|
|
1918
|
+
calendar: slots.calendar,
|
|
1919
|
+
...isoDateTimeFields,
|
|
1920
|
+
offsetNanoseconds: offsetNanoseconds
|
|
1921
|
+
};
|
|
1922
|
+
}), WeakMap), maxCalendarUnit = 2 ** 32 - 1, queryNativeTimeZone = memoize((timeZoneId => {
|
|
1923
|
+
const essence = getTimeZoneEssence(timeZoneId);
|
|
1924
|
+
return "object" == typeof essence ? new IntlTimeZone(essence) : new FixedTimeZone(essence || 0);
|
|
1925
|
+
}));
|
|
1926
|
+
|
|
1927
|
+
class FixedTimeZone {
|
|
1928
|
+
constructor(offsetNano) {
|
|
1929
|
+
this.offsetNano = offsetNano;
|
|
1930
|
+
}
|
|
1931
|
+
getOffsetNanosecondsFor() {
|
|
1932
|
+
return this.offsetNano;
|
|
1933
|
+
}
|
|
1934
|
+
getPossibleInstantsFor(isoDateTimeFields) {
|
|
1935
|
+
return (isoFields => {
|
|
1936
|
+
const bigNano = isoToEpochNano({
|
|
1937
|
+
...isoFields,
|
|
1938
|
+
...isoTimeFieldDefaults
|
|
1939
|
+
});
|
|
1940
|
+
if (!bigNano || Math.abs(bigNano[0]) > 1e8) {
|
|
1941
|
+
throw new RangeError(outOfBoundsDate);
|
|
1942
|
+
}
|
|
1943
|
+
})(isoDateTimeFields), [ isoToEpochNanoWithOffset(isoDateTimeFields, this.offsetNano) ];
|
|
1944
|
+
}
|
|
1945
|
+
getTransition() {}
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
class IntlTimeZone {
|
|
1949
|
+
constructor(format) {
|
|
1950
|
+
this.tzStore = (computeOffsetSec => {
|
|
1951
|
+
function getOffsetSec(epochSec) {
|
|
1952
|
+
const clampedEpochSec = clampNumber(epochSec, minTransition, maxTransition), [startEpochSec, endEpochSec] = computePeriod(clampedEpochSec), startOffsetSec = getSample(startEpochSec), endOffsetSec = getSample(endEpochSec);
|
|
1953
|
+
return startOffsetSec === endOffsetSec ? startOffsetSec : pinch(getSplit(startEpochSec, endEpochSec), startOffsetSec, endOffsetSec, epochSec);
|
|
1954
|
+
}
|
|
1955
|
+
function pinch(split, startOffsetSec, endOffsetSec, forEpochSec) {
|
|
1956
|
+
let offsetSec, splitDurSec;
|
|
1957
|
+
for (;(void 0 === forEpochSec || void 0 === (offsetSec = forEpochSec < split[0] ? startOffsetSec : forEpochSec >= split[1] ? endOffsetSec : void 0)) && (splitDurSec = split[1] - split[0]); ) {
|
|
1958
|
+
const middleEpochSec = split[0] + Math.floor(splitDurSec / 2);
|
|
1959
|
+
computeOffsetSec(middleEpochSec) === endOffsetSec ? split[1] = middleEpochSec : split[0] = middleEpochSec + 1;
|
|
1960
|
+
}
|
|
1961
|
+
return offsetSec;
|
|
1962
|
+
}
|
|
1963
|
+
const getSample = memoize(computeOffsetSec), getSplit = memoize(createSplitTuple);
|
|
1964
|
+
let minTransition = minPossibleTransition, maxTransition = maxPossibleTransition;
|
|
1965
|
+
return {
|
|
1966
|
+
getPossibleEpochSec(zonedEpochSec) {
|
|
1967
|
+
const wideOffsetSec0 = getOffsetSec(zonedEpochSec - 86400), wideOffsetSec1 = getOffsetSec(zonedEpochSec + 86400), wideUtcEpochSec0 = zonedEpochSec - wideOffsetSec0, wideUtcEpochSec1 = zonedEpochSec - wideOffsetSec1;
|
|
1968
|
+
if (wideOffsetSec0 === wideOffsetSec1) {
|
|
1969
|
+
return [ wideUtcEpochSec0 ];
|
|
1970
|
+
}
|
|
1971
|
+
const narrowOffsetSec0 = getOffsetSec(wideUtcEpochSec0);
|
|
1972
|
+
return narrowOffsetSec0 === getOffsetSec(wideUtcEpochSec1) ? [ zonedEpochSec - narrowOffsetSec0 ] : wideOffsetSec0 > wideOffsetSec1 ? [ wideUtcEpochSec0, wideUtcEpochSec1 ] : [];
|
|
1973
|
+
},
|
|
1974
|
+
getOffsetSec: getOffsetSec,
|
|
1975
|
+
getTransition(epochSec, direction) {
|
|
1976
|
+
const clampedEpochSec = clampNumber(epochSec, minTransition, maxTransition);
|
|
1977
|
+
let [startEpochSec, endEpochSec] = computePeriod(clampedEpochSec);
|
|
1978
|
+
const inc = periodDur * direction, inBounds = direction < 0 ? () => endEpochSec > minTransition || (minTransition = clampedEpochSec,
|
|
1979
|
+
0) : () => startEpochSec < maxTransition || (maxTransition = clampedEpochSec, 0);
|
|
1980
|
+
for (;inBounds(); ) {
|
|
1981
|
+
const startOffsetSec = getSample(startEpochSec), endOffsetSec = getSample(endEpochSec);
|
|
1982
|
+
if (startOffsetSec !== endOffsetSec) {
|
|
1983
|
+
const split = getSplit(startEpochSec, endEpochSec);
|
|
1984
|
+
pinch(split, startOffsetSec, endOffsetSec);
|
|
1985
|
+
const transitionEpochSec = split[0];
|
|
1986
|
+
if ((compareNumbers(transitionEpochSec, epochSec) || 1) === direction) {
|
|
1987
|
+
return transitionEpochSec;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
startEpochSec += inc, endEpochSec += inc;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
})((format => epochSec => {
|
|
1995
|
+
const intlParts = hashIntlFormatParts(format, epochSec * milliInSec);
|
|
1996
|
+
return isoArgsToEpochSec(parseIntlPartsYear(intlParts), parseInt(intlParts.month), parseInt(intlParts.day), parseInt(intlParts.hour), parseInt(intlParts.minute), parseInt(intlParts.second)) - epochSec;
|
|
1997
|
+
})(format));
|
|
1998
|
+
}
|
|
1999
|
+
getOffsetNanosecondsFor(epochNano) {
|
|
2000
|
+
return this.tzStore.getOffsetSec((epochNano => epochNanoToSecMod(epochNano)[0])(epochNano)) * nanoInSec;
|
|
2001
|
+
}
|
|
2002
|
+
getPossibleInstantsFor(isoFields) {
|
|
2003
|
+
const [zonedEpochSec, subsecNano] = [ isoArgsToEpochSec((isoDateTimeFields = isoFields).isoYear, isoDateTimeFields.isoMonth, isoDateTimeFields.isoDay, isoDateTimeFields.isoHour, isoDateTimeFields.isoMinute, isoDateTimeFields.isoSecond), isoDateTimeFields.isoMillisecond * nanoInMilli + isoDateTimeFields.isoMicrosecond * nanoInMicro + isoDateTimeFields.isoNanosecond ];
|
|
2004
|
+
var isoDateTimeFields;
|
|
2005
|
+
return this.tzStore.getPossibleEpochSec(zonedEpochSec).map((epochSec => checkEpochNanoInBounds(moveBigNano(numberToBigNano(epochSec, nanoInSec), subsecNano))));
|
|
2006
|
+
}
|
|
2007
|
+
getTransition(epochNano, direction) {
|
|
2008
|
+
const [epochSec, subsecNano] = epochNanoToSecMod(epochNano), resEpochSec = this.tzStore.getTransition(epochSec + (direction > 0 || subsecNano ? 1 : 0), direction);
|
|
2009
|
+
if (void 0 !== resEpochSec) {
|
|
2010
|
+
return numberToBigNano(resEpochSec, nanoInSec);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
|
|
2015
|
+
const timeRegExpStr = "(\\d{2})(?::?(\\d{2})(?::?(\\d{2})(?:[.,](\\d{1,9}))?)?)?", offsetRegExpStr = "([+-])" + timeRegExpStr, dateTimeRegExpStr = "(?:(?:([+-])(\\d{6}))|(\\d{4}))-?(\\d{2})-?(\\d{2})(?:[T ]" + timeRegExpStr + "(Z|" + offsetRegExpStr + ")?)?", yearMonthRegExp = createRegExp("(?:(?:([+-])(\\d{6}))|(\\d{4}))-?(\\d{2})((?:\\[(!?)([^\\]]*)\\]){0,9})"), monthDayRegExp = createRegExp("(?:--)?(\\d{2})-?(\\d{2})((?:\\[(!?)([^\\]]*)\\]){0,9})"), dateTimeRegExp = createRegExp(dateTimeRegExpStr + "((?:\\[(!?)([^\\]]*)\\]){0,9})"), timeRegExp = createRegExp("T?" + timeRegExpStr + "(?:" + offsetRegExpStr + ")?((?:\\[(!?)([^\\]]*)\\]){0,9})"), offsetRegExp = createRegExp(offsetRegExpStr), annotationRegExp = new RegExp("\\[(!?)([^\\]]*)\\]", "g"), durationRegExp = createRegExp("([+-])?P(\\d+Y)?(\\d+M)?(\\d+W)?(\\d+D)?(?:T(?:(\\d+)(?:[.,](\\d{1,9}))?H)?(?:(\\d+)(?:[.,](\\d{1,9}))?M)?(?:(\\d+)(?:[.,](\\d{1,9}))?S)?)?"), queryTimeZoneIntlFormat = memoize((id => new RawDateTimeFormat("en-GB", {
|
|
2016
|
+
timeZone: id,
|
|
2017
|
+
era: "short",
|
|
2018
|
+
year: "numeric",
|
|
2019
|
+
month: "numeric",
|
|
2020
|
+
day: "numeric",
|
|
2021
|
+
hour: "numeric",
|
|
2022
|
+
minute: "numeric",
|
|
2023
|
+
second: "numeric"
|
|
2024
|
+
}))), icuRegExp = /^(AC|AE|AG|AR|AS|BE|BS|CA|CN|CS|CT|EA|EC|IE|IS|JS|MI|NE|NS|PL|PN|PR|PS|SS|VS)T$/, badCharactersRegExp = /[^\w\/:+-]+/, monthCodeRegExp = /^M(\d{2})(L?)$/, queryIntlCalendar = memoize((calendarId => {
|
|
2025
|
+
function epochMilliToIntlFields(epochMilli) {
|
|
2026
|
+
return ((intlParts, calendarIdBase) => ({
|
|
2027
|
+
...parseIntlYear(intlParts, calendarIdBase),
|
|
2028
|
+
monthString: intlParts.month,
|
|
2029
|
+
day: parseInt(intlParts.day)
|
|
2030
|
+
}))(hashIntlFormatParts(intlFormat, epochMilli), calendarIdBase);
|
|
2031
|
+
}
|
|
2032
|
+
const intlFormat = queryCalendarIntlFormat(calendarId), calendarIdBase = computeCalendarIdBase(calendarId);
|
|
2033
|
+
return {
|
|
2034
|
+
id: calendarId,
|
|
2035
|
+
queryFields: createIntlFieldCache(epochMilliToIntlFields),
|
|
2036
|
+
queryYearData: createIntlYearDataCache(epochMilliToIntlFields)
|
|
2037
|
+
};
|
|
2038
|
+
})), queryCalendarIntlFormat = memoize((id => new RawDateTimeFormat("en-GB", {
|
|
2039
|
+
calendar: id,
|
|
2040
|
+
timeZone: utcTimeZoneId,
|
|
2041
|
+
era: "short",
|
|
2042
|
+
year: "numeric",
|
|
2043
|
+
month: "short",
|
|
2044
|
+
day: "numeric"
|
|
2045
|
+
}))), nativeStandardBase = {
|
|
2046
|
+
dateAdd(isoDateFields, durationFields, options) {
|
|
2047
|
+
const overflow = refineOverflowOptions(options);
|
|
2048
|
+
let epochMilli, {years: years, months: months, weeks: weeks, days: days} = durationFields;
|
|
2049
|
+
if (days += durationFieldsToBigNano(durationFields, 5)[0], years || months) {
|
|
2050
|
+
epochMilli = ((moveOps, isoDateFields, years, months, overflow) => {
|
|
2051
|
+
let [year, month, day] = moveOps.dateParts(isoDateFields);
|
|
2052
|
+
if (years) {
|
|
2053
|
+
const [monthCodeNumber, isLeapMonth] = moveOps.monthCodeParts(year, month);
|
|
2054
|
+
year += years, month = monthCodeNumberToMonth(monthCodeNumber, isLeapMonth, moveOps.leapMonth(year)),
|
|
2055
|
+
month = clampEntity("month", month, 1, moveOps.monthsInYearPart(year), overflow);
|
|
2056
|
+
}
|
|
2057
|
+
return months && ([year, month] = moveOps.monthAdd(year, month, months)), day = clampEntity("day", day, 1, moveOps.daysInMonthParts(year, month), overflow),
|
|
2058
|
+
moveOps.epochMilli(year, month, day);
|
|
2059
|
+
})(this, isoDateFields, years, months, overflow);
|
|
2060
|
+
} else {
|
|
2061
|
+
if (!weeks && !days) {
|
|
2062
|
+
return isoDateFields;
|
|
2063
|
+
}
|
|
2064
|
+
epochMilli = isoToEpochMilli(isoDateFields);
|
|
2065
|
+
}
|
|
2066
|
+
if (void 0 === epochMilli) {
|
|
2067
|
+
throw new RangeError(outOfBoundsDate);
|
|
2068
|
+
}
|
|
2069
|
+
return epochMilli += (7 * weeks + days) * milliInDay, checkIsoDateInBounds(epochMilliToIso(epochMilli));
|
|
2070
|
+
},
|
|
2071
|
+
dateUntil(startIsoFields, endIsoFields, largestUnit) {
|
|
2072
|
+
if (largestUnit <= 7) {
|
|
2073
|
+
let weeks = 0, days = diffDays({
|
|
2074
|
+
...startIsoFields,
|
|
2075
|
+
...isoTimeFieldDefaults
|
|
2076
|
+
}, {
|
|
2077
|
+
...endIsoFields,
|
|
2078
|
+
...isoTimeFieldDefaults
|
|
2079
|
+
});
|
|
2080
|
+
return 7 === largestUnit && ([weeks, days] = divModTrunc(days, 7)), {
|
|
2081
|
+
...durationFieldDefaults,
|
|
2082
|
+
weeks: weeks,
|
|
2083
|
+
days: days
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
const yearMonthDayStart = this.dateParts(startIsoFields), yearMonthDayEnd = this.dateParts(endIsoFields);
|
|
2087
|
+
let [years, months, days] = ((calendarNative, year0, month0, day0, year1, month1, day1) => {
|
|
2088
|
+
let yearDiff = year1 - year0, monthDiff = month1 - month0, dayDiff = day1 - day0;
|
|
2089
|
+
if (yearDiff || monthDiff) {
|
|
2090
|
+
const sign = Math.sign(yearDiff || monthDiff);
|
|
2091
|
+
let daysInMonth1 = calendarNative.daysInMonthParts(year1, month1), dayCorrect = 0;
|
|
2092
|
+
if (Math.sign(dayDiff) === -sign) {
|
|
2093
|
+
const origDaysInMonth1 = daysInMonth1;
|
|
2094
|
+
[year1, month1] = calendarNative.monthAdd(year1, month1, -sign), yearDiff = year1 - year0,
|
|
2095
|
+
monthDiff = month1 - month0, daysInMonth1 = calendarNative.daysInMonthParts(year1, month1),
|
|
2096
|
+
dayCorrect = sign < 0 ? -origDaysInMonth1 : daysInMonth1;
|
|
2097
|
+
}
|
|
2098
|
+
if (dayDiff = day1 - Math.min(day0, daysInMonth1) + dayCorrect, yearDiff) {
|
|
2099
|
+
const [monthCodeNumber0, isLeapYear0] = calendarNative.monthCodeParts(year0, month0), [monthCodeNumber1, isLeapYear1] = calendarNative.monthCodeParts(year1, month1);
|
|
2100
|
+
if (monthDiff = monthCodeNumber1 - monthCodeNumber0 || Number(isLeapYear1) - Number(isLeapYear0),
|
|
2101
|
+
Math.sign(monthDiff) === -sign) {
|
|
2102
|
+
const monthCorrect = sign < 0 && -calendarNative.monthsInYearPart(year1);
|
|
2103
|
+
yearDiff = (year1 -= sign) - year0, monthDiff = month1 - monthCodeNumberToMonth(monthCodeNumber0, isLeapYear0, calendarNative.leapMonth(year1)) + (monthCorrect || calendarNative.monthsInYearPart(year1));
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
return [ yearDiff, monthDiff, dayDiff ];
|
|
2108
|
+
})(this, ...yearMonthDayStart, ...yearMonthDayEnd);
|
|
2109
|
+
return 8 === largestUnit && (months += this.monthsInYearSpan(years, yearMonthDayStart[0]),
|
|
2110
|
+
years = 0), {
|
|
2111
|
+
...durationFieldDefaults,
|
|
2112
|
+
years: years,
|
|
2113
|
+
months: months,
|
|
2114
|
+
days: days
|
|
2115
|
+
};
|
|
2116
|
+
},
|
|
2117
|
+
dateFromFields(fields, options) {
|
|
2118
|
+
const overflow = refineOverflowOptions(options), year = refineYear(this, fields), month = refineMonth(this, fields, year, overflow), day = refineDay(this, fields, month, year, overflow);
|
|
2119
|
+
return createPlainDateSlots(checkIsoDateInBounds(this.isoFields(year, month, day)), this.id || isoCalendarId);
|
|
2120
|
+
},
|
|
2121
|
+
yearMonthFromFields(fields, options) {
|
|
2122
|
+
const overflow = refineOverflowOptions(options), year = refineYear(this, fields), month = refineMonth(this, fields, year, overflow);
|
|
2123
|
+
return createPlainYearMonthSlots(checkIsoYearMonthInBounds(this.isoFields(year, month, 1)), this.id || isoCalendarId);
|
|
2124
|
+
},
|
|
2125
|
+
monthDayFromFields(fields, options) {
|
|
2126
|
+
const overflow = refineOverflowOptions(options);
|
|
2127
|
+
let day, monthCodeNumber, isLeapMonth, yearMaybe = void 0 !== fields.eraYear || void 0 !== fields.year ? refineYear(this, fields) : void 0;
|
|
2128
|
+
const isIso = !this.id;
|
|
2129
|
+
if (void 0 === yearMaybe && isIso && (yearMaybe = isoEpochFirstLeapYear), void 0 !== yearMaybe) {
|
|
2130
|
+
const month = refineMonth(this, fields, yearMaybe, overflow);
|
|
2131
|
+
day = refineDay(this, fields, month, yearMaybe, overflow);
|
|
2132
|
+
const leapMonth = this.leapMonth(yearMaybe);
|
|
2133
|
+
monthCodeNumber = monthToMonthCodeNumber(month, leapMonth), isLeapMonth = month === leapMonth;
|
|
2134
|
+
} else {
|
|
2135
|
+
if (void 0 === fields.monthCode) {
|
|
2136
|
+
throw new TypeError(missingMonth);
|
|
2137
|
+
}
|
|
2138
|
+
if ([monthCodeNumber, isLeapMonth] = parseMonthCode(fields.monthCode), this.id && this.id !== gregoryCalendarId && "japanese" !== this.id) {
|
|
2139
|
+
if (this.id && "coptic" === computeCalendarIdBase(this.id) && 0 === overflow) {
|
|
2140
|
+
const maxLengthOfMonthCodeInAnyYear = isLeapMonth || 13 !== monthCodeNumber ? 30 : 6;
|
|
2141
|
+
day = fields.day, day = clampNumber(day, 1, maxLengthOfMonthCodeInAnyYear);
|
|
2142
|
+
} else if (this.id && "chinese" === computeCalendarIdBase(this.id) && 0 === overflow) {
|
|
2143
|
+
const maxLengthOfMonthCodeInAnyYear = !isLeapMonth || 1 !== monthCodeNumber && 9 !== monthCodeNumber && 10 !== monthCodeNumber && 11 !== monthCodeNumber && 12 !== monthCodeNumber ? 30 : 29;
|
|
2144
|
+
day = fields.day, day = clampNumber(day, 1, maxLengthOfMonthCodeInAnyYear);
|
|
2145
|
+
} else {
|
|
2146
|
+
day = fields.day;
|
|
2147
|
+
}
|
|
2148
|
+
} else {
|
|
2149
|
+
day = refineDay(this, fields, refineMonth(this, fields, isoEpochFirstLeapYear, overflow), isoEpochFirstLeapYear, overflow);
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
const res = this.yearMonthForMonthDay(monthCodeNumber, isLeapMonth, day);
|
|
2153
|
+
if (!res) {
|
|
2154
|
+
throw new RangeError("Cannot guess year");
|
|
2155
|
+
}
|
|
2156
|
+
const [finalYear, finalMonth] = res;
|
|
2157
|
+
return createPlainMonthDaySlots(checkIsoDateInBounds(this.isoFields(finalYear, finalMonth, day)), this.id || isoCalendarId);
|
|
2158
|
+
},
|
|
2159
|
+
fields(fieldNames) {
|
|
2160
|
+
return getCalendarEraOrigins(this) && fieldNames.includes("year") ? [ ...fieldNames, ...eraYearFieldNames ] : fieldNames;
|
|
2161
|
+
},
|
|
2162
|
+
mergeFields(baseFields, additionalFields) {
|
|
2163
|
+
const merged = Object.assign(Object.create(null), baseFields);
|
|
2164
|
+
return spliceFields(merged, additionalFields, monthFieldNames), getCalendarEraOrigins(this) && (spliceFields(merged, additionalFields, allYearFieldNames),
|
|
2165
|
+
"japanese" === this.id && spliceFields(merged, additionalFields, monthDayFieldNames, eraYearFieldNames)),
|
|
2166
|
+
merged;
|
|
2167
|
+
},
|
|
2168
|
+
inLeapYear(isoFields) {
|
|
2169
|
+
const [year] = this.dateParts(isoFields);
|
|
2170
|
+
return this.inLeapYearPart(year);
|
|
2171
|
+
},
|
|
2172
|
+
monthsInYear(isoFields) {
|
|
2173
|
+
const [year] = this.dateParts(isoFields);
|
|
2174
|
+
return this.monthsInYearPart(year);
|
|
2175
|
+
},
|
|
2176
|
+
daysInMonth(isoFields) {
|
|
2177
|
+
const [year, month] = this.dateParts(isoFields);
|
|
2178
|
+
return this.daysInMonthParts(year, month);
|
|
2179
|
+
},
|
|
2180
|
+
daysInYear(isoFields) {
|
|
2181
|
+
const [year] = this.dateParts(isoFields);
|
|
2182
|
+
return this.daysInYearPart(year);
|
|
2183
|
+
},
|
|
2184
|
+
dayOfYear: computeNativeDayOfYear,
|
|
2185
|
+
era(isoFields) {
|
|
2186
|
+
return this.eraParts(isoFields)[0];
|
|
2187
|
+
},
|
|
2188
|
+
eraYear(isoFields) {
|
|
2189
|
+
return this.eraParts(isoFields)[1];
|
|
2190
|
+
},
|
|
2191
|
+
monthCode(isoFields) {
|
|
2192
|
+
const [year, month] = this.dateParts(isoFields), [monthCodeNumber, isLeapMonth] = this.monthCodeParts(year, month);
|
|
2193
|
+
return formatMonthCode(monthCodeNumber, isLeapMonth);
|
|
2194
|
+
},
|
|
2195
|
+
dayOfWeek: computeIsoDayOfWeek,
|
|
2196
|
+
daysInWeek() {
|
|
2197
|
+
return 7;
|
|
2198
|
+
}
|
|
2199
|
+
}, isoPartOps = {
|
|
2200
|
+
dateParts: computeIsoDateParts,
|
|
2201
|
+
eraParts: computeIsoEraParts,
|
|
2202
|
+
monthCodeParts: computeIsoMonthCodeParts
|
|
2203
|
+
}, isoWeekOps = {
|
|
2204
|
+
dayOfYear: computeNativeDayOfYear,
|
|
2205
|
+
dateParts: computeIsoDateParts,
|
|
2206
|
+
epochMilli: isoArgsToEpochMilli,
|
|
2207
|
+
weekOfYear: computeNativeWeekOfYear,
|
|
2208
|
+
yearOfWeek: computeNativeYearOfWeek,
|
|
2209
|
+
weekParts(isoDateFields) {
|
|
2210
|
+
function computeWeekShift(yDayOfWeek) {
|
|
2211
|
+
return (7 - yDayOfWeek < minDaysInWeek ? 7 : 0) - yDayOfWeek;
|
|
2212
|
+
}
|
|
2213
|
+
function computeWeeksInYear(delta) {
|
|
2214
|
+
const daysInYear = computeIsoDaysInYear(yearOfWeek + delta), sign = delta || 1, y1WeekShift = computeWeekShift(modFloor(y0DayOfWeek + daysInYear * sign, 7));
|
|
2215
|
+
return weeksInYear = (daysInYear + (y1WeekShift - y0WeekShift) * sign) / 7;
|
|
2216
|
+
}
|
|
2217
|
+
const minDaysInWeek = this.id ? 1 : 4, isoDayOfWeek = computeIsoDayOfWeek(isoDateFields), isoDayOfYear = this.dayOfYear(isoDateFields), dayOfWeek = modFloor(isoDayOfWeek - 1, 7), dayOfYear = isoDayOfYear - 1, y0DayOfWeek = modFloor(dayOfWeek - dayOfYear, 7), y0WeekShift = computeWeekShift(y0DayOfWeek);
|
|
2218
|
+
let weeksInYear, weekOfYear = Math.floor((dayOfYear - y0WeekShift) / 7) + 1, yearOfWeek = isoDateFields.isoYear;
|
|
2219
|
+
return weekOfYear ? weekOfYear > computeWeeksInYear(0) && (weekOfYear = 1, yearOfWeek++) : (weekOfYear = computeWeeksInYear(-1),
|
|
2220
|
+
yearOfWeek--), [ weekOfYear, yearOfWeek, weeksInYear ];
|
|
2221
|
+
}
|
|
2222
|
+
}, isoStandardOps = {
|
|
2223
|
+
...nativeStandardBase,
|
|
2224
|
+
...isoWeekOps,
|
|
2225
|
+
dateParts: computeIsoDateParts,
|
|
2226
|
+
eraParts: computeIsoEraParts,
|
|
2227
|
+
monthCodeParts: computeIsoMonthCodeParts,
|
|
2228
|
+
yearMonthForMonthDay(monthCodeNumber, isLeapMonth) {
|
|
2229
|
+
if (!isLeapMonth) {
|
|
2230
|
+
return [ isoEpochFirstLeapYear, monthCodeNumber ];
|
|
2231
|
+
}
|
|
2232
|
+
},
|
|
2233
|
+
inLeapYearPart: computeIsoInLeapYear,
|
|
2234
|
+
leapMonth() {},
|
|
2235
|
+
monthsInYearPart: computeIsoMonthsInYear,
|
|
2236
|
+
monthsInYearSpan: yearDelta => yearDelta * isoMonthsInYear,
|
|
2237
|
+
daysInMonthParts: computeIsoDaysInMonth,
|
|
2238
|
+
daysInYearPart: computeIsoDaysInYear,
|
|
2239
|
+
isoFields(year, month, day) {
|
|
2240
|
+
return {
|
|
2241
|
+
isoYear: year,
|
|
2242
|
+
isoMonth: month,
|
|
2243
|
+
isoDay: day
|
|
2244
|
+
};
|
|
2245
|
+
},
|
|
2246
|
+
epochMilli: isoArgsToEpochMilli,
|
|
2247
|
+
monthAdd(year, month, monthDelta) {
|
|
2248
|
+
return year += divTrunc(monthDelta, isoMonthsInYear), (month += modTrunc(monthDelta, isoMonthsInYear)) < 1 ? (year--,
|
|
2249
|
+
month += isoMonthsInYear) : month > isoMonthsInYear && (year++, month -= isoMonthsInYear),
|
|
2250
|
+
[ year, month ];
|
|
2251
|
+
},
|
|
2252
|
+
year(isoFields) {
|
|
2253
|
+
return isoFields.isoYear;
|
|
2254
|
+
},
|
|
2255
|
+
month(isoFields) {
|
|
2256
|
+
return isoFields.isoMonth;
|
|
2257
|
+
},
|
|
2258
|
+
day: isoFields => isoFields.isoDay
|
|
2259
|
+
}, intlPartOps = {
|
|
2260
|
+
dateParts: computeIntlDateParts,
|
|
2261
|
+
eraParts: computeIntlEraParts,
|
|
2262
|
+
monthCodeParts: computeIntlMonthCodeParts
|
|
2263
|
+
}, intlWeekOps = {
|
|
2264
|
+
dayOfYear: computeNativeDayOfYear,
|
|
2265
|
+
dateParts: computeIntlDateParts,
|
|
2266
|
+
epochMilli: computeIntlEpochMilli,
|
|
2267
|
+
weekOfYear: computeNativeWeekOfYear,
|
|
2268
|
+
yearOfWeek: computeNativeYearOfWeek,
|
|
2269
|
+
weekParts() {
|
|
2270
|
+
return [];
|
|
2271
|
+
}
|
|
2272
|
+
}, intlStandardOps = {
|
|
2273
|
+
...nativeStandardBase,
|
|
2274
|
+
...intlWeekOps,
|
|
2275
|
+
dateParts: computeIntlDateParts,
|
|
2276
|
+
eraParts: computeIntlEraParts,
|
|
2277
|
+
monthCodeParts: computeIntlMonthCodeParts,
|
|
2278
|
+
yearMonthForMonthDay(monthCodeNumber, isLeapMonth, day) {
|
|
2279
|
+
const startIsoYear = this.id && "chinese" === computeCalendarIdBase(this.id) ? ((monthCodeNumber, isLeapMonth, day) => {
|
|
2280
|
+
if (isLeapMonth) {
|
|
2281
|
+
switch (monthCodeNumber) {
|
|
2282
|
+
case 1:
|
|
2283
|
+
return 1651;
|
|
2284
|
+
|
|
2285
|
+
case 2:
|
|
2286
|
+
return day < 30 ? 1947 : 1765;
|
|
2287
|
+
|
|
2288
|
+
case 3:
|
|
2289
|
+
return day < 30 ? 1966 : 1955;
|
|
2290
|
+
|
|
2291
|
+
case 4:
|
|
2292
|
+
return day < 30 ? 1963 : 1944;
|
|
2293
|
+
|
|
2294
|
+
case 5:
|
|
2295
|
+
return day < 30 ? 1971 : 1952;
|
|
2296
|
+
|
|
2297
|
+
case 6:
|
|
2298
|
+
return day < 30 ? 1960 : 1941;
|
|
2299
|
+
|
|
2300
|
+
case 7:
|
|
2301
|
+
return day < 30 ? 1968 : 1938;
|
|
2302
|
+
|
|
2303
|
+
case 8:
|
|
2304
|
+
return day < 30 ? 1957 : 1718;
|
|
2305
|
+
|
|
2306
|
+
case 9:
|
|
2307
|
+
return 1832;
|
|
2308
|
+
|
|
2309
|
+
case 10:
|
|
2310
|
+
return 1870;
|
|
2311
|
+
|
|
2312
|
+
case 11:
|
|
2313
|
+
return 1814;
|
|
2314
|
+
|
|
2315
|
+
case 12:
|
|
2316
|
+
return 1890;
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
return 1972;
|
|
2320
|
+
})(monthCodeNumber, isLeapMonth, day) : isoEpochFirstLeapYear;
|
|
2321
|
+
let [startYear, startMonth, startDay] = computeIntlDateParts.call(this, {
|
|
2322
|
+
isoYear: startIsoYear,
|
|
2323
|
+
isoMonth: isoMonthsInYear,
|
|
2324
|
+
isoDay: 31
|
|
2325
|
+
});
|
|
2326
|
+
const startYearLeapMonth = computeIntlLeapMonth.call(this, startYear), startMonthIsLeap = startMonth === startYearLeapMonth;
|
|
2327
|
+
1 === (compareNumbers(monthCodeNumber, monthToMonthCodeNumber(startMonth, startYearLeapMonth)) || compareNumbers(Number(isLeapMonth), Number(startMonthIsLeap)) || compareNumbers(day, startDay)) && startYear--;
|
|
2328
|
+
for (let yearMove = 0; yearMove < 100; yearMove++) {
|
|
2329
|
+
const tryYear = startYear - yearMove, tryLeapMonth = computeIntlLeapMonth.call(this, tryYear), tryMonth = monthCodeNumberToMonth(monthCodeNumber, isLeapMonth, tryLeapMonth);
|
|
2330
|
+
if (isLeapMonth === (tryMonth === tryLeapMonth) && day <= computeIntlDaysInMonth.call(this, tryYear, tryMonth)) {
|
|
2331
|
+
return [ tryYear, tryMonth ];
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
},
|
|
2335
|
+
inLeapYearPart(year) {
|
|
2336
|
+
const days = computeIntlDaysInYear.call(this, year);
|
|
2337
|
+
return days > computeIntlDaysInYear.call(this, year - 1) && days > computeIntlDaysInYear.call(this, year + 1);
|
|
2338
|
+
},
|
|
2339
|
+
leapMonth: computeIntlLeapMonth,
|
|
2340
|
+
monthsInYearPart: computeIntlMonthsInYear,
|
|
2341
|
+
monthsInYearSpan(yearDelta, yearStart) {
|
|
2342
|
+
const yearEnd = yearStart + yearDelta, yearSign = Math.sign(yearDelta), yearCorrection = yearSign < 0 ? -1 : 0;
|
|
2343
|
+
let months = 0;
|
|
2344
|
+
for (let year = yearStart; year !== yearEnd; year += yearSign) {
|
|
2345
|
+
months += computeIntlMonthsInYear.call(this, year + yearCorrection);
|
|
2346
|
+
}
|
|
2347
|
+
return months;
|
|
2348
|
+
},
|
|
2349
|
+
daysInMonthParts: computeIntlDaysInMonth,
|
|
2350
|
+
daysInYearPart: computeIntlDaysInYear,
|
|
2351
|
+
isoFields(year, month, day) {
|
|
2352
|
+
return epochMilliToIso(computeIntlEpochMilli.call(this, year, month, day));
|
|
2353
|
+
},
|
|
2354
|
+
epochMilli: computeIntlEpochMilli,
|
|
2355
|
+
monthAdd(year, month, monthDelta) {
|
|
2356
|
+
if (monthDelta) {
|
|
2357
|
+
if (month += monthDelta, !Number.isSafeInteger(month)) {
|
|
2358
|
+
throw new RangeError(outOfBoundsDate);
|
|
2359
|
+
}
|
|
2360
|
+
if (monthDelta < 0) {
|
|
2361
|
+
for (;month < 1; ) {
|
|
2362
|
+
month += computeIntlMonthsInYear.call(this, --year);
|
|
2363
|
+
}
|
|
2364
|
+
} else {
|
|
2365
|
+
let monthsInYear;
|
|
2366
|
+
for (;month > (monthsInYear = computeIntlMonthsInYear.call(this, year)); ) {
|
|
2367
|
+
month -= monthsInYear, year++;
|
|
2368
|
+
}
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
return [ year, month ];
|
|
2372
|
+
},
|
|
2373
|
+
year(isoFields) {
|
|
2374
|
+
return this.queryFields(isoFields).year;
|
|
2375
|
+
},
|
|
2376
|
+
month(isoFields) {
|
|
2377
|
+
const {year: year, monthString: monthString} = this.queryFields(isoFields), {monthStringToIndex: monthStringToIndex} = this.queryYearData(year);
|
|
2378
|
+
return monthStringToIndex[monthString] + 1;
|
|
2379
|
+
},
|
|
2380
|
+
day(isoFields) {
|
|
2381
|
+
return this.queryFields(isoFields).day;
|
|
2382
|
+
}
|
|
2383
|
+
}, createNativePartOps = createNativeOpsCreator(isoPartOps, intlPartOps), createNativeStandardOps = createNativeOpsCreator(isoStandardOps, intlStandardOps), builtinRefiners = {
|
|
2384
|
+
...{
|
|
2385
|
+
era: toStringViaPrimitive,
|
|
2386
|
+
eraYear: toInteger,
|
|
2387
|
+
year: toInteger,
|
|
2388
|
+
month: toPositiveInteger,
|
|
2389
|
+
monthCode(monthCode) {
|
|
2390
|
+
const s = toStringViaPrimitive(monthCode);
|
|
2391
|
+
return parseMonthCode(s), s;
|
|
2392
|
+
},
|
|
2393
|
+
day: toPositiveInteger
|
|
2394
|
+
},
|
|
2395
|
+
...mapPropNamesToConstant(timeFieldNamesAsc, toInteger),
|
|
2396
|
+
...mapPropNamesToConstant(durationFieldNamesAsc, toStrictInteger),
|
|
2397
|
+
offset(offsetString) {
|
|
2398
|
+
const s = toStringViaPrimitive(offsetString);
|
|
2399
|
+
return parseOffsetNano(s), s;
|
|
2400
|
+
}
|
|
2401
|
+
}, timeFieldsToIso = bindArgs(remapProps, timeFieldNamesAsc, isoTimeFieldNamesAsc), isoTimeFieldsToCal = bindArgs(remapProps, isoTimeFieldNamesAsc, timeFieldNamesAsc), timeZoneNameStrs = [ "timeZoneName" ], monthDayFallbacks = {
|
|
2402
|
+
month: "numeric",
|
|
2403
|
+
day: "numeric"
|
|
2404
|
+
}, yearMonthFallbacks = {
|
|
2405
|
+
year: "numeric",
|
|
2406
|
+
month: "numeric"
|
|
2407
|
+
}, dateFallbacks = {
|
|
2408
|
+
...yearMonthFallbacks,
|
|
2409
|
+
day: "numeric"
|
|
2410
|
+
}, timeFallbacks = {
|
|
2411
|
+
hour: "numeric",
|
|
2412
|
+
minute: "numeric",
|
|
2413
|
+
second: "numeric"
|
|
2414
|
+
}, dateTimeFallbacks = {
|
|
2415
|
+
...dateFallbacks,
|
|
2416
|
+
...timeFallbacks
|
|
2417
|
+
}, zonedFallbacks = {
|
|
2418
|
+
...dateTimeFallbacks,
|
|
2419
|
+
timeZoneName: "short"
|
|
2420
|
+
}, yearMonthFallbackNames = Object.keys(yearMonthFallbacks), monthDayFallbackNames = Object.keys(monthDayFallbacks), dateFallbackNames = Object.keys(dateFallbacks), timeFallbackNames = Object.keys(timeFallbacks), dateStyleNames = [ "dateStyle" ], yearMonthStandardNames = [ ...yearMonthFallbackNames, ...dateStyleNames ], monthDayStandardNames = [ ...monthDayFallbackNames, ...dateStyleNames ], dateStandardNames = [ ...dateFallbackNames, ...dateStyleNames, "weekday" ], timeStandardNames = [ ...timeFallbackNames, "dayPeriod", "timeStyle", "fractionalSecondDigits" ], dateTimeStandardNames = [ ...dateStandardNames, ...timeStandardNames ], dateExclusions = [ ...timeZoneNameStrs, ...timeStandardNames ], timeExclusions = [ ...timeZoneNameStrs, ...dateStandardNames ], yearMonthExclusions = [ ...timeZoneNameStrs, "day", "weekday", ...timeStandardNames ], monthDayExclusions = [ ...timeZoneNameStrs, "year", "weekday", ...timeStandardNames ], transformInstantOptions = createOptionsTransformer(dateTimeStandardNames, dateTimeFallbacks), transformZonedOptions = createOptionsTransformer(dateTimeStandardNames, zonedFallbacks), transformDateTimeOptions = createOptionsTransformer(dateTimeStandardNames, dateTimeFallbacks, timeZoneNameStrs), transformDateOptions = createOptionsTransformer(dateStandardNames, dateFallbacks, dateExclusions), transformTimeOptions = createOptionsTransformer(timeStandardNames, timeFallbacks, timeExclusions), transformYearMonthOptions = createOptionsTransformer(yearMonthStandardNames, yearMonthFallbacks, yearMonthExclusions), transformMonthDayOptions = createOptionsTransformer(monthDayStandardNames, monthDayFallbacks, monthDayExclusions), emptyOptions = {}, nonBuggyIsoResolve = new RawDateTimeFormat(void 0, {
|
|
2421
|
+
calendar: isoCalendarId
|
|
2422
|
+
}).resolvedOptions().calendar === isoCalendarId, instantConfig = [ transformInstantOptions, getEpochMilli ], zonedConfig = [ transformZonedOptions, getEpochMilli, 0, (slots0, slots1) => {
|
|
2423
|
+
const timeZoneId = slots0.timeZone;
|
|
2424
|
+
if (slots1 && slots1.timeZone !== timeZoneId) {
|
|
2425
|
+
throw new RangeError("Mismatching TimeZones");
|
|
2426
|
+
}
|
|
2427
|
+
return timeZoneId;
|
|
2428
|
+
} ], dateTimeConfig = [ transformDateTimeOptions, isoToEpochMilli ], dateConfig = [ transformDateOptions, isoToEpochMilli ], timeConfig = [ transformTimeOptions, isoFields => isoTimeFieldsToNano(isoFields) / nanoInMilli ], yearMonthConfig = [ transformYearMonthOptions, isoToEpochMilli, nonBuggyIsoResolve ], monthDayConfig = [ transformMonthDayOptions, isoToEpochMilli, nonBuggyIsoResolve ];
|
|
2429
|
+
|
|
2430
|
+
let currentTimeZoneId;
|
|
2431
|
+
|
|
2432
|
+
exports.DurationBranding = DurationBranding, exports.InstantBranding = InstantBranding,
|
|
2433
|
+
exports.PlainDateBranding = PlainDateBranding, exports.PlainDateTimeBranding = PlainDateTimeBranding,
|
|
2434
|
+
exports.PlainMonthDayBranding = PlainMonthDayBranding, exports.PlainTimeBranding = PlainTimeBranding,
|
|
2435
|
+
exports.PlainYearMonthBranding = PlainYearMonthBranding, exports.RawDateTimeFormat = RawDateTimeFormat,
|
|
2436
|
+
exports.ZonedDateTimeBranding = ZonedDateTimeBranding, exports.absDuration = slots => -1 === slots.sign ? negateDuration(slots) : slots,
|
|
2437
|
+
exports.addDurations = (refineRelativeTo, getCalendarOps, getTimeZoneOps, doSubtract, slots, otherSlots, options) => {
|
|
2438
|
+
const relativeToSlots = refineRelativeTo(normalizeOptions(options).relativeTo), maxUnit = Math.max(getMaxDurationUnit(slots), getMaxDurationUnit(otherSlots));
|
|
2439
|
+
if (isUniformUnit(maxUnit, relativeToSlots)) {
|
|
2440
|
+
return createDurationSlots(checkDurationUnits(((a, b, largestUnit, doSubtract) => {
|
|
2441
|
+
const combined = addBigNanos(durationFieldsToBigNano(a), durationFieldsToBigNano(b), doSubtract ? -1 : 1);
|
|
2442
|
+
if (!Number.isFinite(combined[0])) {
|
|
2443
|
+
throw new RangeError(outOfBoundsDate);
|
|
2444
|
+
}
|
|
2445
|
+
return {
|
|
2446
|
+
...durationFieldDefaults,
|
|
2447
|
+
...nanoToDurationDayTimeFields(combined, largestUnit)
|
|
2448
|
+
};
|
|
2449
|
+
})(slots, otherSlots, maxUnit, doSubtract)));
|
|
2450
|
+
}
|
|
2451
|
+
if (!relativeToSlots) {
|
|
2452
|
+
throw new RangeError("Missing relativeTo");
|
|
2453
|
+
}
|
|
2454
|
+
doSubtract && (otherSlots = negateDurationFields(otherSlots));
|
|
2455
|
+
const [marker, calendarOps, timeZoneOps] = createMarkerSystem(getCalendarOps, getTimeZoneOps, relativeToSlots), moveMarker = createMoveMarker(timeZoneOps), diffMarkers = createDiffMarkers(timeZoneOps), midMarker = moveMarker(calendarOps, marker, slots);
|
|
2456
|
+
return createDurationSlots(diffMarkers(calendarOps, marker, moveMarker(calendarOps, midMarker, otherSlots), maxUnit));
|
|
2457
|
+
}, exports.bindArgs = bindArgs, exports.compareDurations = (refineRelativeTo, getCalendarOps, getTimeZoneOps, durationSlots0, durationSlots1, options) => {
|
|
2458
|
+
const relativeToSlots = refineRelativeTo(normalizeOptions(options).relativeTo), maxUnit = Math.max(getMaxDurationUnit(durationSlots0), getMaxDurationUnit(durationSlots1));
|
|
2459
|
+
if (allPropsEqual(durationFieldNamesAsc, durationSlots0, durationSlots1)) {
|
|
2460
|
+
return 0;
|
|
2461
|
+
}
|
|
2462
|
+
if (isUniformUnit(maxUnit, relativeToSlots)) {
|
|
2463
|
+
return compareBigNanos(durationFieldsToBigNano(durationSlots0), durationFieldsToBigNano(durationSlots1));
|
|
2464
|
+
}
|
|
2465
|
+
if (!relativeToSlots) {
|
|
2466
|
+
throw new RangeError("Missing relativeTo");
|
|
2467
|
+
}
|
|
2468
|
+
const [marker, calendarOps, timeZoneOps] = createMarkerSystem(getCalendarOps, getTimeZoneOps, relativeToSlots), markerToEpochNano = createMarkerToEpochNano(timeZoneOps), moveMarker = createMoveMarker(timeZoneOps);
|
|
2469
|
+
return compareBigNanos(markerToEpochNano(moveMarker(calendarOps, marker, durationSlots0)), markerToEpochNano(moveMarker(calendarOps, marker, durationSlots1)));
|
|
2470
|
+
}, exports.compareInstants = compareInstants, exports.compareIsoDateFields = compareIsoDateFields,
|
|
2471
|
+
exports.compareIsoDateTimeFields = compareIsoDateTimeFields, exports.compareIsoTimeFields = compareIsoTimeFields,
|
|
2472
|
+
exports.compareZonedDateTimes = compareZonedDateTimes, exports.computeZonedHoursInDay = (getTimeZoneOps, slots) => {
|
|
2473
|
+
const timeZoneOps = getTimeZoneOps(slots.timeZone), isoFields = zonedEpochSlotsToIso(slots, timeZoneOps), [isoFields0, isoFields1] = computeDayInterval(isoFields), hoursExact = bigNanoToNumber(diffBigNanos(getStartOfDayInstantFor(timeZoneOps, isoFields0), getStartOfDayInstantFor(timeZoneOps, isoFields1)), nanoInHour, 1);
|
|
2474
|
+
if (hoursExact <= 0) {
|
|
2475
|
+
throw new RangeError(invalidProtocolResults);
|
|
2476
|
+
}
|
|
2477
|
+
return hoursExact;
|
|
2478
|
+
}, exports.computeZonedStartOfDay = (getTimeZoneOps, slots) => {
|
|
2479
|
+
const {timeZone: timeZone, calendar: calendar} = slots;
|
|
2480
|
+
return createZonedDateTimeSlots(((computeAlignment, timeZoneOps, slots) => getStartOfDayInstantFor(timeZoneOps, computeAlignment(zonedEpochSlotsToIso(slots, timeZoneOps))))(computeDayFloor, getTimeZoneOps(timeZone), slots), timeZone, calendar);
|
|
2481
|
+
}, exports.constructDurationSlots = (years = 0, months = 0, weeks = 0, days = 0, hours = 0, minutes = 0, seconds = 0, milliseconds = 0, microseconds = 0, nanoseconds = 0) => createDurationSlots(checkDurationUnits(mapProps(toStrictInteger, zipProps(durationFieldNamesAsc, [ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds ])))),
|
|
2482
|
+
exports.constructInstantSlots = epochNano => createInstantSlots(checkEpochNanoInBounds(bigIntToBigNano(toBigInt(epochNano)))),
|
|
2483
|
+
exports.constructPlainDateSlots = (refineCalendarArg, isoYear, isoMonth, isoDay, calendarArg = isoCalendarId) => createPlainDateSlots(checkIsoDateInBounds(checkIsoDateFields(mapProps(toInteger, {
|
|
2484
|
+
isoYear: isoYear,
|
|
2485
|
+
isoMonth: isoMonth,
|
|
2486
|
+
isoDay: isoDay
|
|
2487
|
+
}))), refineCalendarArg(calendarArg)), exports.constructPlainDateTimeSlots = (refineCalendarArg, isoYear, isoMonth, isoDay, isoHour = 0, isoMinute = 0, isoSecond = 0, isoMillisecond = 0, isoMicrosecond = 0, isoNanosecond = 0, calendarArg = isoCalendarId) => createPlainDateTimeSlots(checkIsoDateTimeInBounds(checkIsoDateTimeFields(mapProps(toInteger, zipProps(isoDateTimeFieldNamesAsc, [ isoYear, isoMonth, isoDay, isoHour, isoMinute, isoSecond, isoMillisecond, isoMicrosecond, isoNanosecond ])))), refineCalendarArg(calendarArg)),
|
|
2488
|
+
exports.constructPlainMonthDaySlots = (refineCalendarArg, isoMonth, isoDay, calendarArg = isoCalendarId, referenceIsoYear = isoEpochFirstLeapYear) => {
|
|
2489
|
+
const isoMonthInt = toInteger(isoMonth), isoDayInt = toInteger(isoDay), calendarId = refineCalendarArg(calendarArg);
|
|
2490
|
+
return createPlainMonthDaySlots(checkIsoDateInBounds(checkIsoDateFields({
|
|
2491
|
+
isoYear: toInteger(referenceIsoYear),
|
|
2492
|
+
isoMonth: isoMonthInt,
|
|
2493
|
+
isoDay: isoDayInt
|
|
2494
|
+
})), calendarId);
|
|
2495
|
+
}, exports.constructPlainTimeSlots = (isoHour = 0, isoMinute = 0, isoSecond = 0, isoMillisecond = 0, isoMicrosecond = 0, isoNanosecond = 0) => createPlainTimeSlots(constrainIsoTimeFields(mapProps(toInteger, zipProps(isoTimeFieldNamesAsc, [ isoHour, isoMinute, isoSecond, isoMillisecond, isoMicrosecond, isoNanosecond ])), 1)),
|
|
2496
|
+
exports.constructPlainYearMonthSlots = (refineCalendarArg, isoYear, isoMonth, calendarArg = isoCalendarId, referenceIsoDay = 1) => {
|
|
2497
|
+
const isoYearInt = toInteger(isoYear), isoMonthInt = toInteger(isoMonth), calendarId = refineCalendarArg(calendarArg);
|
|
2498
|
+
return createPlainYearMonthSlots(checkIsoYearMonthInBounds(checkIsoDateFields({
|
|
2499
|
+
isoYear: isoYearInt,
|
|
2500
|
+
isoMonth: isoMonthInt,
|
|
2501
|
+
isoDay: toInteger(referenceIsoDay)
|
|
2502
|
+
})), calendarId);
|
|
2503
|
+
}, exports.constructZonedDateTimeSlots = (refineCalendarArg, refineTimeZoneArg, epochNano, timeZoneArg, calendarArg = isoCalendarId) => createZonedDateTimeSlots(checkEpochNanoInBounds(bigIntToBigNano(toBigInt(epochNano))), refineTimeZoneArg(timeZoneArg), refineCalendarArg(calendarArg)),
|
|
2504
|
+
exports.createDurationSlots = createDurationSlots, exports.createFormatForPrep = createFormatForPrep,
|
|
2505
|
+
exports.createFormatPrepper = (config, queryFormat = createFormatForPrep, strictOptions = 0) => {
|
|
2506
|
+
const [transformOptions, , , getForcedTimeZoneId] = config;
|
|
2507
|
+
return (locales, options = emptyOptions, ...slotsList) => {
|
|
2508
|
+
const subformat = queryFormat(getForcedTimeZoneId && getForcedTimeZoneId(...slotsList), locales, options, transformOptions, strictOptions), resolvedOptions = subformat.resolvedOptions();
|
|
2509
|
+
return [ subformat, ...toEpochMillis(config, resolvedOptions, slotsList) ];
|
|
2510
|
+
};
|
|
2511
|
+
}, exports.createGetterDescriptors = getters => mapProps((getter => ({
|
|
2512
|
+
get: getter,
|
|
2513
|
+
configurable: 1
|
|
2514
|
+
})), getters), exports.createInstantSlots = createInstantSlots, exports.createNameDescriptors = name => createPropDescriptors({
|
|
2515
|
+
name: name
|
|
2516
|
+
}, 1), exports.createNativeStandardOps = createNativeStandardOps, exports.createPlainDateSlots = createPlainDateSlots,
|
|
2517
|
+
exports.createPlainDateTimeSlots = createPlainDateTimeSlots, exports.createPlainTimeSlots = createPlainTimeSlots,
|
|
2518
|
+
exports.createPropDescriptors = createPropDescriptors, exports.createStringTagDescriptors = value => ({
|
|
2519
|
+
[Symbol.toStringTag]: {
|
|
2520
|
+
value: value,
|
|
2521
|
+
configurable: 1
|
|
2522
|
+
}
|
|
2523
|
+
}), exports.createZonedDateTimeSlots = createZonedDateTimeSlots, exports.dateConfig = dateConfig,
|
|
2524
|
+
exports.dateTimeConfig = dateTimeConfig, exports.diffInstants = (invert, instantSlots0, instantSlots1, options) => {
|
|
2525
|
+
const optionsTuple = refineDiffOptions(invert, options, 3, 5), durationFields = diffEpochNanos(instantSlots0.epochNanoseconds, instantSlots1.epochNanoseconds, ...optionsTuple);
|
|
2526
|
+
return createDurationSlots(invert ? negateDurationFields(durationFields) : durationFields);
|
|
2527
|
+
}, exports.diffPlainDateTimes = (getCalendarOps, invert, plainDateTimeSlots0, plainDateTimeSlots1, options) => {
|
|
2528
|
+
const calendarId = getCommonCalendarId(plainDateTimeSlots0.calendar, plainDateTimeSlots1.calendar), [largestUnit, smallestUnit, roundingInc, roundingMode] = refineDiffOptions(invert, options, 6), startEpochNano = isoToEpochNano(plainDateTimeSlots0), endEpochNano = isoToEpochNano(plainDateTimeSlots1), sign = compareBigNanos(endEpochNano, startEpochNano);
|
|
2529
|
+
let durationFields;
|
|
2530
|
+
if (sign) {
|
|
2531
|
+
if (largestUnit <= 6) {
|
|
2532
|
+
durationFields = diffEpochNanos(startEpochNano, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode);
|
|
2533
|
+
} else {
|
|
2534
|
+
const calendarOps = getCalendarOps(calendarId);
|
|
2535
|
+
durationFields = diffDateTimesBig(calendarOps, plainDateTimeSlots0, plainDateTimeSlots1, sign, largestUnit, options),
|
|
2536
|
+
durationFields = roundRelativeDuration(durationFields, endEpochNano, largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, plainDateTimeSlots0, isoToEpochNano, moveDateTime);
|
|
2537
|
+
}
|
|
2538
|
+
} else {
|
|
2539
|
+
durationFields = durationFieldDefaults;
|
|
2540
|
+
}
|
|
2541
|
+
return createDurationSlots(invert ? negateDurationFields(durationFields) : durationFields);
|
|
2542
|
+
}, exports.diffPlainDates = (getCalendarOps, invert, plainDateSlots0, plainDateSlots1, options) => {
|
|
2543
|
+
const calendarId = getCommonCalendarId(plainDateSlots0.calendar, plainDateSlots1.calendar);
|
|
2544
|
+
return diffDateLike(invert, (() => getCalendarOps(calendarId)), plainDateSlots0, plainDateSlots1, ...refineDiffOptions(invert, options, 6, 9, 6));
|
|
2545
|
+
}, exports.diffPlainTimes = (invert, plainTimeSlots0, plainTimeSlots1, options) => {
|
|
2546
|
+
const [largestUnit, smallestUnit, roundingInc, roundingMode] = refineDiffOptions(invert, options, 5, 5), timeDiffNano = roundByInc(diffTimes(plainTimeSlots0, plainTimeSlots1), computeNanoInc(smallestUnit, roundingInc), roundingMode), durationFields = {
|
|
2547
|
+
...durationFieldDefaults,
|
|
2548
|
+
...nanoToDurationTimeFields(timeDiffNano, largestUnit)
|
|
2549
|
+
};
|
|
2550
|
+
return createDurationSlots(invert ? negateDurationFields(durationFields) : durationFields);
|
|
2551
|
+
}, exports.diffPlainYearMonth = (getCalendarOps, invert, plainYearMonthSlots0, plainYearMonthSlots1, options) => {
|
|
2552
|
+
const calendarId = getCommonCalendarId(plainYearMonthSlots0.calendar, plainYearMonthSlots1.calendar), optionsTuple = refineDiffOptions(invert, options, 9, 9, 8), calendarOps = getCalendarOps(calendarId), firstOfMonth0 = moveToDayOfMonthUnsafe(calendarOps, plainYearMonthSlots0), firstOfMonth1 = moveToDayOfMonthUnsafe(calendarOps, plainYearMonthSlots1);
|
|
2553
|
+
return firstOfMonth0.isoYear === firstOfMonth1.isoYear && firstOfMonth0.isoMonth === firstOfMonth1.isoMonth && firstOfMonth0.isoDay === firstOfMonth1.isoDay ? createDurationSlots(durationFieldDefaults) : diffDateLike(invert, (() => calendarOps), checkIsoDateInBounds(firstOfMonth0), checkIsoDateInBounds(firstOfMonth1), ...optionsTuple, 8);
|
|
2554
|
+
}, exports.diffZonedDateTimes = (getCalendarOps, getTimeZoneOps, invert, slots0, slots1, options) => {
|
|
2555
|
+
const calendarId = getCommonCalendarId(slots0.calendar, slots1.calendar), [largestUnit, smallestUnit, roundingInc, roundingMode] = refineDiffOptions(invert, options, 5), epochNano0 = slots0.epochNanoseconds, epochNano1 = slots1.epochNanoseconds, sign = compareBigNanos(epochNano1, epochNano0);
|
|
2556
|
+
let durationFields;
|
|
2557
|
+
if (sign) {
|
|
2558
|
+
if (largestUnit < 6) {
|
|
2559
|
+
durationFields = diffEpochNanos(epochNano0, epochNano1, largestUnit, smallestUnit, roundingInc, roundingMode);
|
|
2560
|
+
} else {
|
|
2561
|
+
const timeZoneOps = getTimeZoneOps(((a, b) => {
|
|
2562
|
+
if (!isTimeZoneIdsEqual(a, b)) {
|
|
2563
|
+
throw new RangeError("Mismatching TimeZones");
|
|
2564
|
+
}
|
|
2565
|
+
return a;
|
|
2566
|
+
})(slots0.timeZone, slots1.timeZone)), calendarOps = getCalendarOps(calendarId);
|
|
2567
|
+
durationFields = diffZonedEpochsBig(calendarOps, timeZoneOps, slots0, slots1, sign, largestUnit, options),
|
|
2568
|
+
durationFields = roundRelativeDuration(durationFields, epochNano1, largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, slots0, extractEpochNano, bindArgs(moveZonedEpochs, timeZoneOps));
|
|
2569
|
+
}
|
|
2570
|
+
} else {
|
|
2571
|
+
durationFields = durationFieldDefaults;
|
|
2572
|
+
}
|
|
2573
|
+
return createDurationSlots(invert ? negateDurationFields(durationFields) : durationFields);
|
|
2574
|
+
}, exports.durationFieldNamesAsc = durationFieldNamesAsc, exports.durationWithFields = (slots, fields) => {
|
|
2575
|
+
return createDurationSlots((initialFields = slots, modFields = fields, checkDurationUnits({
|
|
2576
|
+
...initialFields,
|
|
2577
|
+
...refineFields(modFields, durationFieldNamesAlpha)
|
|
2578
|
+
})));
|
|
2579
|
+
var initialFields, modFields;
|
|
2580
|
+
}, exports.epochMilliToInstant = epochMilli => createInstantSlots(checkEpochNanoInBounds(numberToBigNano(toStrictInteger(epochMilli), nanoInMilli))),
|
|
2581
|
+
exports.epochNanoToInstant = epochNano => createInstantSlots(checkEpochNanoInBounds(bigIntToBigNano(toBigInt(epochNano)))),
|
|
2582
|
+
exports.forbiddenValueOf = "Cannot use valueOf", exports.formatDurationIso = (slots, options) => {
|
|
2583
|
+
const [roundingMode, nanoInc, subsecDigits] = refineTimeDisplayOptions(options, 3);
|
|
2584
|
+
return nanoInc > 1 && checkDurationUnits(slots = {
|
|
2585
|
+
...slots,
|
|
2586
|
+
...roundDayTimeDurationByInc(slots, nanoInc, roundingMode)
|
|
2587
|
+
}), ((durationSlots, subsecDigits) => {
|
|
2588
|
+
const {sign: sign} = durationSlots, abs = -1 === sign ? negateDurationFields(durationSlots) : durationSlots, {hours: hours, minutes: minutes} = abs, [wholeSec, subsecNano] = divModBigNano(durationFieldsToBigNano(abs, 3), nanoInSec, divModTrunc);
|
|
2589
|
+
checkDurationTimeUnit(wholeSec);
|
|
2590
|
+
const subsecNanoString = formatSubsecNano(subsecNano, subsecDigits), forceSec = subsecDigits >= 0 || !sign || subsecNanoString;
|
|
2591
|
+
return (sign < 0 ? "-" : "") + "P" + formatDurationFragments({
|
|
2592
|
+
Y: formatDurationNumber(abs.years),
|
|
2593
|
+
M: formatDurationNumber(abs.months),
|
|
2594
|
+
W: formatDurationNumber(abs.weeks),
|
|
2595
|
+
D: formatDurationNumber(abs.days)
|
|
2596
|
+
}) + (hours || minutes || wholeSec || forceSec ? "T" + formatDurationFragments({
|
|
2597
|
+
H: formatDurationNumber(hours),
|
|
2598
|
+
M: formatDurationNumber(minutes),
|
|
2599
|
+
S: formatDurationNumber(wholeSec, forceSec) + subsecNanoString
|
|
2600
|
+
}) : "");
|
|
2601
|
+
})(slots, subsecDigits);
|
|
2602
|
+
}, exports.formatInstantIso = (refineTimeZoneString, getTimeZoneOps, instantSlots, options) => {
|
|
2603
|
+
const [timeZoneArg, roundingMode, nanoInc, subsecDigits] = (options => {
|
|
2604
|
+
const timeDisplayTuple = refineTimeDisplayTuple(options = normalizeOptions(options));
|
|
2605
|
+
return [ options.timeZone, ...timeDisplayTuple ];
|
|
2606
|
+
})(options), providedTimeZone = void 0 !== timeZoneArg;
|
|
2607
|
+
return ((providedTimeZone, timeZoneOps, epochNano, roundingMode, nanoInc, subsecDigits) => {
|
|
2608
|
+
epochNano = roundBigNanoByInc(epochNano, nanoInc, roundingMode, 1);
|
|
2609
|
+
const offsetNano = timeZoneOps.getOffsetNanosecondsFor(epochNano);
|
|
2610
|
+
return formatIsoDateTimeFields(epochNanoToIso(epochNano, offsetNano), subsecDigits) + (providedTimeZone ? formatOffsetNano(roundToMinute(offsetNano)) : "Z");
|
|
2611
|
+
})(providedTimeZone, getTimeZoneOps(providedTimeZone ? refineTimeZoneString(timeZoneArg) : utcTimeZoneId), instantSlots.epochNanoseconds, roundingMode, nanoInc, subsecDigits);
|
|
2612
|
+
}, exports.formatOffsetNano = formatOffsetNano, exports.formatPlainDateIso = (plainDateSlots, options) => {
|
|
2613
|
+
return calendarId = plainDateSlots.calendar, isoFields = plainDateSlots, calendarDisplay = refineDateDisplayOptions(options),
|
|
2614
|
+
formatIsoDateFields(isoFields) + formatCalendar(calendarId, calendarDisplay);
|
|
2615
|
+
var calendarId, isoFields, calendarDisplay;
|
|
2616
|
+
}, exports.formatPlainDateTimeIso = (plainDateTimeSlots0, options) => {
|
|
2617
|
+
const [a, b, c, d] = (options => (options = normalizeOptions(options), [ refineCalendarDisplay(options), ...refineTimeDisplayTuple(options) ]))(options);
|
|
2618
|
+
return calendarId = plainDateTimeSlots0.calendar, calendarDisplay = a, subsecDigits = d,
|
|
2619
|
+
formatIsoDateTimeFields(roundDateTimeToNano(plainDateTimeSlots0, c, b), subsecDigits) + formatCalendar(calendarId, calendarDisplay);
|
|
2620
|
+
var calendarId, calendarDisplay, subsecDigits;
|
|
2621
|
+
}, exports.formatPlainMonthDayIso = (plainMonthDaySlots, options) => formatDateLikeIso(plainMonthDaySlots.calendar, formatIsoMonthDayFields, plainMonthDaySlots, refineDateDisplayOptions(options)),
|
|
2622
|
+
exports.formatPlainTimeIso = (slots, options) => {
|
|
2623
|
+
const [a, b, c] = refineTimeDisplayOptions(options);
|
|
2624
|
+
return subsecDigits = c, formatIsoTimeFields(roundTimeToNano(slots, b, a)[0], subsecDigits);
|
|
2625
|
+
var subsecDigits;
|
|
2626
|
+
}, exports.formatPlainYearMonthIso = (plainYearMonthSlots, options) => formatDateLikeIso(plainYearMonthSlots.calendar, formatIsoYearMonthFields, plainYearMonthSlots, refineDateDisplayOptions(options)),
|
|
2627
|
+
exports.formatZonedDateTimeIso = (getTimeZoneOps, zonedDateTimeSlots0, options) => {
|
|
2628
|
+
const [a, b, c, d, e, f] = (options => {
|
|
2629
|
+
options = normalizeOptions(options);
|
|
2630
|
+
const calendarDisplay = refineCalendarDisplay(options), subsecDigits = refineSubsecDigits(options), offsetDisplay = refineOffsetDisplay(options), roundingMode = refineRoundingMode(options, 4), smallestUnit = refineSmallestUnit(options, 4);
|
|
2631
|
+
return [ calendarDisplay, refineTimeZoneDisplay(options), offsetDisplay, roundingMode, ...refineSmallestUnitAndSubsecDigits(smallestUnit, subsecDigits) ];
|
|
2632
|
+
})(options);
|
|
2633
|
+
return ((getTimeZoneOps, calendarId, timeZoneId, epochNano, calendarDisplay, timeZoneDisplay, offsetDisplay, roundingMode, nanoInc, subsecDigits) => {
|
|
2634
|
+
epochNano = roundBigNanoByInc(epochNano, nanoInc, roundingMode, 1);
|
|
2635
|
+
const offsetNano = getTimeZoneOps(timeZoneId).getOffsetNanosecondsFor(epochNano);
|
|
2636
|
+
return formatIsoDateTimeFields(epochNanoToIso(epochNano, offsetNano), subsecDigits) + formatOffsetNano(roundToMinute(offsetNano), offsetDisplay) + ((timeZoneId, timeZoneDisplay) => 1 !== timeZoneDisplay ? "[" + (2 === timeZoneDisplay ? "!" : "") + timeZoneId + "]" : "")(timeZoneId, timeZoneDisplay) + formatCalendar(calendarId, calendarDisplay);
|
|
2637
|
+
})(getTimeZoneOps, zonedDateTimeSlots0.calendar, zonedDateTimeSlots0.timeZone, zonedDateTimeSlots0.epochNanoseconds, a, b, c, d, e, f);
|
|
2638
|
+
}, exports.getCurrentEpochNano = getCurrentEpochNano, exports.getCurrentIsoDateTime = timeZoneOps => {
|
|
2639
|
+
const epochNano = getCurrentEpochNano();
|
|
2640
|
+
return epochNanoToIso(epochNano, timeZoneOps.getOffsetNanosecondsFor(epochNano));
|
|
2641
|
+
}, exports.getCurrentTimeZoneId = () => currentTimeZoneId || (currentTimeZoneId = (new RawDateTimeFormat).resolvedOptions().timeZone),
|
|
2642
|
+
exports.getDurationBlank = slots => !slots.sign, exports.getEpochMilli = getEpochMilli,
|
|
2643
|
+
exports.getEpochNano = slots => ((bigNano, divisorNano = 1) => {
|
|
2644
|
+
const [days, timeNano] = bigNano, whole = Math.floor(timeNano / divisorNano), wholeInDay = nanoInUtcDay / divisorNano;
|
|
2645
|
+
return BigInt(days) * BigInt(wholeInDay) + BigInt(whole);
|
|
2646
|
+
})(slots.epochNanoseconds), exports.instantConfig = instantConfig, exports.instantToZonedDateTime = (instantSlots, timeZoneId, calendarId = isoCalendarId) => createZonedDateTimeSlots(instantSlots.epochNanoseconds, timeZoneId, calendarId),
|
|
2647
|
+
exports.instantsEqual = (instantSlots0, instantSlots1) => !compareInstants(instantSlots0, instantSlots1),
|
|
2648
|
+
exports.invalidBag = "Invalid bag", exports.invalidCalendar = invalidCalendar, exports.invalidCallingContext = "Invalid calling context",
|
|
2649
|
+
exports.invalidFormatType = branding => `Cannot format ${branding}`, exports.invalidTimeZone = invalidTimeZone,
|
|
2650
|
+
exports.isObjectLike = isObjectLike, exports.isoCalendarId = isoCalendarId, exports.isoTimeFieldDefaults = isoTimeFieldDefaults,
|
|
2651
|
+
exports.isoTimeFieldNamesAsc = isoTimeFieldNamesAsc, exports.mapPropNames = mapPropNames,
|
|
2652
|
+
exports.mapProps = mapProps, exports.memoize = memoize, exports.mismatchingFormatTypes = "Mismatching types for formatting",
|
|
2653
|
+
exports.monthDayConfig = monthDayConfig, exports.moveInstant = (doSubtract, instantSlots, durationSlots) => createInstantSlots(checkEpochNanoInBounds(addBigNanos(instantSlots.epochNanoseconds, (fields => {
|
|
2654
|
+
if (durationHasDateParts(fields)) {
|
|
2655
|
+
throw new RangeError("Cannot use large units");
|
|
2656
|
+
}
|
|
2657
|
+
return durationFieldsToBigNano(fields, 5);
|
|
2658
|
+
})(doSubtract ? negateDurationFields(durationSlots) : durationSlots)))), exports.movePlainDate = (getCalendarOps, doSubtract, plainDateSlots, durationSlots, options) => {
|
|
2659
|
+
const {calendar: calendar} = plainDateSlots;
|
|
2660
|
+
return createPlainDateSlots(moveDate(getCalendarOps(calendar), plainDateSlots, doSubtract ? negateDurationFields(durationSlots) : durationSlots, options), calendar);
|
|
2661
|
+
}, exports.movePlainDateTime = (getCalendarOps, doSubtract, plainDateTimeSlots, durationSlots, options = Object.create(null)) => {
|
|
2662
|
+
const {calendar: calendar} = plainDateTimeSlots;
|
|
2663
|
+
return createPlainDateTimeSlots(moveDateTime(getCalendarOps(calendar), plainDateTimeSlots, doSubtract ? negateDurationFields(durationSlots) : durationSlots, options), calendar);
|
|
2664
|
+
}, exports.movePlainTime = (doSubtract, slots, durationSlots) => createPlainTimeSlots(moveTime(slots, doSubtract ? negateDurationFields(durationSlots) : durationSlots)[0]),
|
|
2665
|
+
exports.movePlainYearMonth = (getCalendarOps, doSubtract, plainYearMonthSlots, durationSlots, options) => {
|
|
2666
|
+
const calendarId = plainYearMonthSlots.calendar, calendarOps = getCalendarOps(calendarId);
|
|
2667
|
+
let isoDateFields = checkIsoDateInBounds(moveToDayOfMonthUnsafe(calendarOps, plainYearMonthSlots));
|
|
2668
|
+
doSubtract && (durationSlots = negateDuration(durationSlots)), durationSlots.sign < 0 && (isoDateFields = calendarOps.dateAdd(isoDateFields, {
|
|
2669
|
+
...durationFieldDefaults,
|
|
2670
|
+
months: 1
|
|
2671
|
+
}), isoDateFields = moveByDays(isoDateFields, -1));
|
|
2672
|
+
const movedIsoDateFields = calendarOps.dateAdd(isoDateFields, durationSlots, options);
|
|
2673
|
+
return createPlainYearMonthSlots(moveToDayOfMonthUnsafe(calendarOps, movedIsoDateFields), calendarId);
|
|
2674
|
+
}, exports.moveZonedDateTime = (getCalendarOps, getTimeZoneOps, doSubtract, zonedDateTimeSlots, durationSlots, options = Object.create(null)) => {
|
|
2675
|
+
const timeZoneOps = getTimeZoneOps(zonedDateTimeSlots.timeZone), calendarOps = getCalendarOps(zonedDateTimeSlots.calendar);
|
|
2676
|
+
return {
|
|
2677
|
+
...zonedDateTimeSlots,
|
|
2678
|
+
...moveZonedEpochs(timeZoneOps, calendarOps, zonedDateTimeSlots, doSubtract ? negateDurationFields(durationSlots) : durationSlots, options)
|
|
2679
|
+
};
|
|
2680
|
+
}, exports.nanoInMilli = nanoInMilli, exports.negateDuration = negateDuration, exports.numberToBigNano = numberToBigNano,
|
|
2681
|
+
exports.parseCalendarId = s => {
|
|
2682
|
+
const res = parseDateTimeLike(s) || parseYearMonthOnly(s) || parseMonthDayOnly(s);
|
|
2683
|
+
return res ? res.calendar : s;
|
|
2684
|
+
}, exports.parseDuration = s => {
|
|
2685
|
+
const parsed = (s => {
|
|
2686
|
+
const parts = durationRegExp.exec(s);
|
|
2687
|
+
return parts ? (parts => {
|
|
2688
|
+
function parseUnit(wholeStr, fracStr, timeUnit) {
|
|
2689
|
+
let leftoverUnits = 0, wholeUnits = 0;
|
|
2690
|
+
if (timeUnit && ([leftoverUnits, leftoverNano] = divModFloor(leftoverNano, unitNanoMap[timeUnit])),
|
|
2691
|
+
void 0 !== wholeStr) {
|
|
2692
|
+
if (hasAnyFrac) {
|
|
2693
|
+
throw new RangeError(invalidSubstring(wholeStr));
|
|
2694
|
+
}
|
|
2695
|
+
wholeUnits = (s => {
|
|
2696
|
+
const n = parseInt(s);
|
|
2697
|
+
if (!Number.isFinite(n)) {
|
|
2698
|
+
throw new RangeError(invalidSubstring(s));
|
|
2699
|
+
}
|
|
2700
|
+
return n;
|
|
2701
|
+
})(wholeStr), hasAny = 1, fracStr && (leftoverNano = parseSubsecNano(fracStr) * (unitNanoMap[timeUnit] / nanoInSec),
|
|
2702
|
+
hasAnyFrac = 1);
|
|
2703
|
+
}
|
|
2704
|
+
return leftoverUnits + wholeUnits;
|
|
2705
|
+
}
|
|
2706
|
+
let hasAny = 0, hasAnyFrac = 0, leftoverNano = 0, durationFields = {
|
|
2707
|
+
...zipProps(durationFieldNamesAsc, [ parseUnit(parts[2]), parseUnit(parts[3]), parseUnit(parts[4]), parseUnit(parts[5]), parseUnit(parts[6], parts[7], 5), parseUnit(parts[8], parts[9], 4), parseUnit(parts[10], parts[11], 3) ]),
|
|
2708
|
+
...nanoToGivenFields(leftoverNano, 2, durationFieldNamesAsc)
|
|
2709
|
+
};
|
|
2710
|
+
if (!hasAny) {
|
|
2711
|
+
throw new RangeError(noValidFields(durationFieldNamesAsc));
|
|
2712
|
+
}
|
|
2713
|
+
return parseSign(parts[1]) < 0 && (durationFields = negateDurationFields(durationFields)),
|
|
2714
|
+
durationFields;
|
|
2715
|
+
})(parts) : void 0;
|
|
2716
|
+
})(requireString(s));
|
|
2717
|
+
if (!parsed) {
|
|
2718
|
+
throw new RangeError(failedParse(s));
|
|
2719
|
+
}
|
|
2720
|
+
return createDurationSlots(checkDurationUnits(parsed));
|
|
2721
|
+
}, exports.parseInstant = s => {
|
|
2722
|
+
const organized = parseDateTimeLike(s = toStringViaPrimitive(s));
|
|
2723
|
+
if (!organized) {
|
|
2724
|
+
throw new RangeError(failedParse(s));
|
|
2725
|
+
}
|
|
2726
|
+
let offsetNano;
|
|
2727
|
+
if (organized.hasZ) {
|
|
2728
|
+
offsetNano = 0;
|
|
2729
|
+
} else {
|
|
2730
|
+
if (!organized.offset) {
|
|
2731
|
+
throw new RangeError(failedParse(s));
|
|
2732
|
+
}
|
|
2733
|
+
offsetNano = parseOffsetNano(organized.offset);
|
|
2734
|
+
}
|
|
2735
|
+
return organized.timeZone && parseOffsetNanoMaybe(organized.timeZone, 1), createInstantSlots(isoToEpochNanoWithOffset(checkIsoDateTimeFields(organized), offsetNano));
|
|
2736
|
+
}, exports.parsePlainDate = parsePlainDate, exports.parsePlainDateTime = s => {
|
|
2737
|
+
const organized = parseDateTimeLike(requireString(s));
|
|
2738
|
+
if (!organized || organized.hasZ) {
|
|
2739
|
+
throw new RangeError(failedParse(s));
|
|
2740
|
+
}
|
|
2741
|
+
return createPlainDateTimeSlots(finalizeDateTime(organized));
|
|
2742
|
+
}, exports.parsePlainMonthDay = (getCalendarOps, s) => {
|
|
2743
|
+
const organized = parseMonthDayOnly(requireString(s));
|
|
2744
|
+
if (organized) {
|
|
2745
|
+
return requireIsoCalendar(organized), createPlainMonthDaySlots(checkIsoDateFields(organized));
|
|
2746
|
+
}
|
|
2747
|
+
const dateSlots = parsePlainDate(s, 0, 1), {calendar: calendar} = dateSlots, calendarOps = getCalendarOps(calendar), [origYear, origMonth, day] = calendarOps.dateParts(dateSlots), [monthCodeNumber, isLeapMonth] = calendarOps.monthCodeParts(origYear, origMonth), [year, month] = calendarOps.yearMonthForMonthDay(monthCodeNumber, isLeapMonth, day);
|
|
2748
|
+
return createPlainMonthDaySlots(checkIsoDateInBounds(calendarOps.isoFields(year, month, day)), calendar);
|
|
2749
|
+
}, exports.parsePlainTime = s => {
|
|
2750
|
+
let altParsed, organized = (s => {
|
|
2751
|
+
const parts = timeRegExp.exec(s);
|
|
2752
|
+
return parts ? (organizeAnnotationParts(parts[10]), organizeTimeParts(parts)) : void 0;
|
|
2753
|
+
})(requireString(s));
|
|
2754
|
+
if (!organized) {
|
|
2755
|
+
if (organized = parseDateTimeLike(s), !organized) {
|
|
2756
|
+
throw new RangeError(failedParse(s));
|
|
2757
|
+
}
|
|
2758
|
+
if (!organized.hasTime) {
|
|
2759
|
+
throw new RangeError(failedParse(s));
|
|
2760
|
+
}
|
|
2761
|
+
if (organized.hasZ) {
|
|
2762
|
+
throw new RangeError(invalidSubstring("Z"));
|
|
2763
|
+
}
|
|
2764
|
+
requireIsoCalendar(organized);
|
|
2765
|
+
}
|
|
2766
|
+
if ((altParsed = parseYearMonthOnly(s)) && isIsoDateFieldsValid(altParsed)) {
|
|
2767
|
+
throw new RangeError(failedParse(s));
|
|
2768
|
+
}
|
|
2769
|
+
if ((altParsed = parseMonthDayOnly(s)) && isIsoDateFieldsValid(altParsed)) {
|
|
2770
|
+
throw new RangeError(failedParse(s));
|
|
2771
|
+
}
|
|
2772
|
+
return createPlainTimeSlots(constrainIsoTimeFields(organized, 1));
|
|
2773
|
+
}, exports.parsePlainYearMonth = (getCalendarOps, s) => {
|
|
2774
|
+
const organized = parseYearMonthOnly(requireString(s));
|
|
2775
|
+
if (organized) {
|
|
2776
|
+
return requireIsoCalendar(organized), createPlainYearMonthSlots(checkIsoYearMonthInBounds(checkIsoDateFields(organized)));
|
|
2777
|
+
}
|
|
2778
|
+
const isoSlots = parsePlainDate(s, 1);
|
|
2779
|
+
return createPlainYearMonthSlots(moveToDayOfMonthUnsafe(getCalendarOps(isoSlots.calendar), isoSlots));
|
|
2780
|
+
}, exports.parseRelativeToSlots = s => {
|
|
2781
|
+
const organized = parseDateTimeLike(requireString(s));
|
|
2782
|
+
if (!organized) {
|
|
2783
|
+
throw new RangeError(failedParse(s));
|
|
2784
|
+
}
|
|
2785
|
+
if (organized.timeZone) {
|
|
2786
|
+
return finalizeZonedDateTime(organized, organized.offset ? parseOffsetNano(organized.offset) : void 0);
|
|
2787
|
+
}
|
|
2788
|
+
if (organized.hasZ) {
|
|
2789
|
+
throw new RangeError(failedParse(s));
|
|
2790
|
+
}
|
|
2791
|
+
return finalizeDate(organized);
|
|
2792
|
+
}, exports.parseTimeZoneId = s => {
|
|
2793
|
+
const parsed = parseDateTimeLike(s);
|
|
2794
|
+
return parsed && (parsed.timeZone || parsed.hasZ && utcTimeZoneId || parsed.offset) || s;
|
|
2795
|
+
}, exports.parseZonedDateTime = (s, options) => {
|
|
2796
|
+
const organized = parseDateTimeLike(requireString(s));
|
|
2797
|
+
if (!organized || !organized.timeZone) {
|
|
2798
|
+
throw new RangeError(failedParse(s));
|
|
2799
|
+
}
|
|
2800
|
+
const {offset: offset} = organized, offsetNano = offset ? parseOffsetNano(offset) : void 0, [, offsetDisambig, epochDisambig] = refineZonedFieldOptions(options);
|
|
2801
|
+
return finalizeZonedDateTime(organized, offsetNano, offsetDisambig, epochDisambig);
|
|
2802
|
+
}, exports.plainDateTimeToZonedDateTime = (getTimeZoneOps, plainDateTimeSlots, timeZoneId, options) => createZonedDateTimeSlots(checkEpochNanoInBounds(((getTimeZoneOps, timeZoneId, isoFields, options) => {
|
|
2803
|
+
const epochDisambig = (options => refineEpochDisambig(normalizeOptions(options)))(options);
|
|
2804
|
+
return getSingleInstantFor(getTimeZoneOps(timeZoneId), isoFields, epochDisambig);
|
|
2805
|
+
})(getTimeZoneOps, timeZoneId, plainDateTimeSlots, options)), timeZoneId, plainDateTimeSlots.calendar),
|
|
2806
|
+
exports.plainDateTimeWithFields = (getCalendarOps, plainDateTimeSlots, modFields, options) => {
|
|
2807
|
+
const calendarOps = getCalendarOps(plainDateTimeSlots.calendar), validFieldNames = [ ...calendarOps.fields(dateFieldNamesAlpha), ...timeFieldNamesAsc ].sort(), origFields = {
|
|
2808
|
+
...computeDateEssentials(slots = plainDateTimeSlots),
|
|
2809
|
+
hour: slots.isoHour,
|
|
2810
|
+
minute: slots.isoMinute,
|
|
2811
|
+
second: slots.isoSecond,
|
|
2812
|
+
millisecond: slots.isoMillisecond,
|
|
2813
|
+
microsecond: slots.isoMicrosecond,
|
|
2814
|
+
nanosecond: slots.isoNanosecond
|
|
2815
|
+
};
|
|
2816
|
+
var slots;
|
|
2817
|
+
const partialFields = refineFields(modFields, validFieldNames), overflow = refineOverflowOptions(options), mergedCalendarFields = calendarOps.mergeFields(origFields, partialFields), mergedAllFields = {
|
|
2818
|
+
...origFields,
|
|
2819
|
+
...partialFields
|
|
2820
|
+
};
|
|
2821
|
+
return createPlainDateTimeSlots(checkIsoDateTimeInBounds({
|
|
2822
|
+
...calendarOps.dateFromFields(mergedCalendarFields, fabricateOverflowOptions(overflow)),
|
|
2823
|
+
...constrainIsoTimeFields(timeFieldsToIso(mergedAllFields), overflow)
|
|
2824
|
+
}));
|
|
2825
|
+
}, exports.plainDateTimeWithPlainTime = (plainDateTimeSlots, plainTimeSlots = isoTimeFieldDefaults) => createPlainDateTimeSlots(checkIsoDateTimeInBounds({
|
|
2826
|
+
...plainDateTimeSlots,
|
|
2827
|
+
...plainTimeSlots
|
|
2828
|
+
})), exports.plainDateTimesEqual = (plainDateTimeSlots0, plainDateTimeSlots1) => !compareIsoDateTimeFields(plainDateTimeSlots0, plainDateTimeSlots1) && plainDateTimeSlots0.calendar === plainDateTimeSlots1.calendar,
|
|
2829
|
+
exports.plainDateToPlainDateTime = (plainDateSlots, plainTimeFields = isoTimeFieldDefaults) => createPlainDateTimeSlots(checkIsoDateTimeInBounds({
|
|
2830
|
+
...plainDateSlots,
|
|
2831
|
+
...plainTimeFields
|
|
2832
|
+
})), exports.plainDateToPlainMonthDay = (getCalendarOps, plainDateSlots, plainDateFields) => ((calendarOps, input) => {
|
|
2833
|
+
const fields = refineCalendarFields(calendarOps, input, monthCodeDayFieldNames);
|
|
2834
|
+
return calendarOps.monthDayFromFields(fields);
|
|
2835
|
+
})(getCalendarOps(plainDateSlots.calendar), plainDateFields), exports.plainDateToPlainYearMonth = (getCalendarOps, plainDateSlots, plainDateFields) => ((calendarOps, input) => {
|
|
2836
|
+
const fields = refineCalendarFields(calendarOps, input, yearMonthCodeFieldNames);
|
|
2837
|
+
return calendarOps.yearMonthFromFields(fields, void 0);
|
|
2838
|
+
})(getCalendarOps(plainDateSlots.calendar), plainDateFields), exports.plainDateToZonedDateTime = (refineTimeZoneString, refinePlainTimeArg, getTimeZoneOps, plainDateSlots, options) => {
|
|
2839
|
+
const timeZoneId = refineTimeZoneString(options.timeZone), plainTimeArg = options.plainTime, isoTimeFields = void 0 !== plainTimeArg ? refinePlainTimeArg(plainTimeArg) : void 0, timeZoneOps = getTimeZoneOps(timeZoneId);
|
|
2840
|
+
let epochNano;
|
|
2841
|
+
return epochNano = isoTimeFields ? getSingleInstantFor(timeZoneOps, {
|
|
2842
|
+
...plainDateSlots,
|
|
2843
|
+
...isoTimeFields
|
|
2844
|
+
}) : getStartOfDayInstantFor(timeZoneOps, {
|
|
2845
|
+
...plainDateSlots,
|
|
2846
|
+
...isoTimeFieldDefaults
|
|
2847
|
+
}), createZonedDateTimeSlots(epochNano, timeZoneId, plainDateSlots.calendar);
|
|
2848
|
+
}, exports.plainDateWithFields = (getCalendarOps, plainDateSlots, modFields, options) => {
|
|
2849
|
+
const calendarOps = getCalendarOps(plainDateSlots.calendar), validFieldNames = calendarOps.fields(dateFieldNamesAlpha).sort(), origFields = computeDateEssentials(plainDateSlots), partialFields = refineFields(modFields, validFieldNames), mergedFields = calendarOps.mergeFields(origFields, partialFields);
|
|
2850
|
+
return calendarOps.dateFromFields(mergedFields, options);
|
|
2851
|
+
}, exports.plainDatesEqual = (plainDateSlots0, plainDateSlots1) => !compareIsoDateFields(plainDateSlots0, plainDateSlots1) && plainDateSlots0.calendar === plainDateSlots1.calendar,
|
|
2852
|
+
exports.plainMonthDayToPlainDate = (getCalendarOps, plainMonthDaySlots, plainMonthDayFields, bag) => ((calendarOps, input, bag) => convertToIso(calendarOps, input, monthCodeDayFieldNames, requireObjectLike(bag), yearFieldNames))(getCalendarOps(plainMonthDaySlots.calendar), plainMonthDayFields, bag),
|
|
2853
|
+
exports.plainMonthDayWithFields = (getCalendarOps, plainMonthDaySlots, modFields, options) => {
|
|
2854
|
+
const calendarOps = getCalendarOps(plainMonthDaySlots.calendar), validFieldNames = calendarOps.fields(dateFieldNamesAlpha).sort(), origFields = (slots => {
|
|
2855
|
+
const calendarOps = createNativePartOps(slots.calendar), [year, month, day] = calendarOps.dateParts(slots), [monthCodeNumber, isLeapMonth] = calendarOps.monthCodeParts(year, month);
|
|
2856
|
+
return {
|
|
2857
|
+
monthCode: formatMonthCode(monthCodeNumber, isLeapMonth),
|
|
2858
|
+
day: day
|
|
2859
|
+
};
|
|
2860
|
+
})(plainMonthDaySlots), partialFields = refineFields(modFields, validFieldNames), mergedFields = calendarOps.mergeFields(origFields, partialFields);
|
|
2861
|
+
return calendarOps.monthDayFromFields(mergedFields, options);
|
|
2862
|
+
}, exports.plainMonthDaysEqual = (plainMonthDaySlots0, plainMonthDaySlots1) => !compareIsoDateFields(plainMonthDaySlots0, plainMonthDaySlots1) && plainMonthDaySlots0.calendar === plainMonthDaySlots1.calendar,
|
|
2863
|
+
exports.plainTimeWithFields = (initialFields, mod, options) => createPlainTimeSlots(((initialFields, modFields, options) => refineTimeBag({
|
|
2864
|
+
...pluckProps(timeFieldNamesAlpha, initialFields),
|
|
2865
|
+
...refineFields(modFields, timeFieldNamesAlpha)
|
|
2866
|
+
}, refineOverflowOptions(options)))(initialFields, mod, options)), exports.plainTimesEqual = (plainTimeSlots0, plainTimeSlots1) => !compareIsoTimeFields(plainTimeSlots0, plainTimeSlots1),
|
|
2867
|
+
exports.plainYearMonthToPlainDate = (getCalendarOps, plainYearMonthSlots, plainYearMonthFields, bag) => ((calendarOps, input, bag) => convertToIso(calendarOps, input, yearMonthCodeFieldNames, requireObjectLike(bag), dayFieldNames))(getCalendarOps(plainYearMonthSlots.calendar), plainYearMonthFields, bag),
|
|
2868
|
+
exports.plainYearMonthWithFields = (getCalendarOps, plainYearMonthSlots, modFields, options) => {
|
|
2869
|
+
const calendarOps = getCalendarOps(plainYearMonthSlots.calendar), validFieldNames = calendarOps.fields(yearMonthFieldNames).sort(), origFields = (slots => {
|
|
2870
|
+
const calendarOps = createNativePartOps(slots.calendar), [year, month] = calendarOps.dateParts(slots), [monthCodeNumber, isLeapMonth] = calendarOps.monthCodeParts(year, month);
|
|
2871
|
+
return {
|
|
2872
|
+
year: year,
|
|
2873
|
+
monthCode: formatMonthCode(monthCodeNumber, isLeapMonth)
|
|
2874
|
+
};
|
|
2875
|
+
})(plainYearMonthSlots), partialFields = refineFields(modFields, validFieldNames), mergedFields = calendarOps.mergeFields(origFields, partialFields);
|
|
2876
|
+
return calendarOps.yearMonthFromFields(mergedFields, options);
|
|
2877
|
+
}, exports.plainYearMonthsEqual = (plainYearMonthSlots0, plainYearMonthSlots1) => !compareIsoDateFields(plainYearMonthSlots0, plainYearMonthSlots1) && plainYearMonthSlots0.calendar === plainYearMonthSlots1.calendar,
|
|
2878
|
+
exports.pluckProps = pluckProps, exports.queryNativeTimeZone = queryNativeTimeZone,
|
|
2879
|
+
exports.refineCalendarId = id => resolveCalendarId(requireString(id)), exports.refineDirectionOptions = options => {
|
|
2880
|
+
const normalizedOptions = normalizeOptionsOrString(options, "direction"), res = refineChoiceOption("direction", directionMap, normalizedOptions, 0);
|
|
2881
|
+
if (!res) {
|
|
2882
|
+
throw new RangeError(invalidEntity("direction", res));
|
|
2883
|
+
}
|
|
2884
|
+
return res;
|
|
2885
|
+
}, exports.refineDurationBag = bag => {
|
|
2886
|
+
const durationFields = refineFields(bag, durationFieldNamesAlpha);
|
|
2887
|
+
return createDurationSlots(checkDurationUnits({
|
|
2888
|
+
...durationFieldDefaults,
|
|
2889
|
+
...durationFields
|
|
2890
|
+
}));
|
|
2891
|
+
}, exports.refineMaybeZonedDateTimeBag = (refineTimeZoneString, getTimeZoneOps, calendarOps, bag) => {
|
|
2892
|
+
const fields = refineCalendarFields(calendarOps, bag, dateFieldNamesAlpha, [], timeAndZoneFieldNames);
|
|
2893
|
+
if (void 0 !== fields.timeZone) {
|
|
2894
|
+
const isoDateFields = calendarOps.dateFromFields(fields), isoTimeFields = refineTimeBag(fields), timeZoneId = refineTimeZoneString(fields.timeZone);
|
|
2895
|
+
return {
|
|
2896
|
+
epochNanoseconds: getMatchingInstantFor(getTimeZoneOps(timeZoneId), {
|
|
2897
|
+
...isoDateFields,
|
|
2898
|
+
...isoTimeFields
|
|
2899
|
+
}, void 0 !== fields.offset ? parseOffsetNano(fields.offset) : void 0),
|
|
2900
|
+
timeZone: timeZoneId
|
|
2901
|
+
};
|
|
2902
|
+
}
|
|
2903
|
+
return {
|
|
2904
|
+
...calendarOps.dateFromFields(fields),
|
|
2905
|
+
...isoTimeFieldDefaults
|
|
2906
|
+
};
|
|
2907
|
+
}, exports.refineOverflowOptions = refineOverflowOptions, exports.refinePlainDateBag = (calendarOps, bag, options, requireFields = []) => {
|
|
2908
|
+
const fields = refineCalendarFields(calendarOps, bag, dateFieldNamesAlpha, requireFields);
|
|
2909
|
+
return calendarOps.dateFromFields(fields, options);
|
|
2910
|
+
}, exports.refinePlainDateTimeBag = (calendarOps, bag, options) => {
|
|
2911
|
+
const fields = refineCalendarFields(calendarOps, bag, dateFieldNamesAlpha, [], timeFieldNamesAsc), overflow = refineOverflowOptions(options);
|
|
2912
|
+
return createPlainDateTimeSlots(checkIsoDateTimeInBounds({
|
|
2913
|
+
...calendarOps.dateFromFields(fields, fabricateOverflowOptions(overflow)),
|
|
2914
|
+
...refineTimeBag(fields, overflow)
|
|
2915
|
+
}));
|
|
2916
|
+
}, exports.refinePlainMonthDayBag = (calendarOps, calendarAbsent, bag, options) => {
|
|
2917
|
+
const fields = refineCalendarFields(calendarOps, bag, dateFieldNamesAlpha, dayFieldNames);
|
|
2918
|
+
return calendarAbsent && void 0 !== fields.month && void 0 === fields.monthCode && void 0 === fields.year && (fields.year = isoEpochFirstLeapYear),
|
|
2919
|
+
calendarOps.monthDayFromFields(fields, options);
|
|
2920
|
+
}, exports.refinePlainTimeBag = (bag, options) => createPlainTimeSlots(refineTimeBag(refineFields(bag, timeFieldNamesAlpha, [], 1), refineOverflowOptions(options))),
|
|
2921
|
+
exports.refinePlainYearMonthBag = (calendarOps, bag, options, requireFields) => {
|
|
2922
|
+
const fields = refineCalendarFields(calendarOps, bag, yearMonthFieldNames, requireFields);
|
|
2923
|
+
return calendarOps.yearMonthFromFields(fields, options);
|
|
2924
|
+
}, exports.refineTimeZoneId = id => resolveTimeZoneId(requireString(id)), exports.refineZonedDateTimeBag = (refineTimeZoneString, getTimeZoneOps, calendarOps, calendarId, bag, options) => {
|
|
2925
|
+
const fields = refineCalendarFields(calendarOps, bag, dateFieldNamesAlpha, timeZoneFieldNames, timeAndZoneFieldNames), timeZoneId = refineTimeZoneString(fields.timeZone), [overflow, offsetDisambig, epochDisambig] = refineZonedFieldOptions(options), isoDateFields = calendarOps.dateFromFields(fields, fabricateOverflowOptions(overflow)), isoTimeFields = refineTimeBag(fields, overflow);
|
|
2926
|
+
return createZonedDateTimeSlots(getMatchingInstantFor(getTimeZoneOps(timeZoneId), {
|
|
2927
|
+
...isoDateFields,
|
|
2928
|
+
...isoTimeFields
|
|
2929
|
+
}, void 0 !== fields.offset ? parseOffsetNano(fields.offset) : void 0, offsetDisambig, epochDisambig), timeZoneId, calendarId);
|
|
2930
|
+
}, exports.refineZonedFieldOptions = refineZonedFieldOptions, exports.requireBoolean = requireBoolean,
|
|
2931
|
+
exports.requireInteger = requireInteger, exports.requireIntegerOrUndefined = input => {
|
|
2932
|
+
if (void 0 !== input) {
|
|
2933
|
+
return requireInteger(input);
|
|
2934
|
+
}
|
|
2935
|
+
}, exports.requireNumberIsInteger = requireNumberIsInteger, exports.requirePositiveInteger = requirePositiveInteger,
|
|
2936
|
+
exports.requirePositiveIntegerOrUndefined = input => {
|
|
2937
|
+
if (void 0 !== input) {
|
|
2938
|
+
return requirePositiveInteger(input);
|
|
2939
|
+
}
|
|
2940
|
+
}, exports.requireString = requireString, exports.requireStringOrUndefined = input => {
|
|
2941
|
+
if (void 0 !== input) {
|
|
2942
|
+
return requireString(input);
|
|
2943
|
+
}
|
|
2944
|
+
}, exports.resolveCalendarId = resolveCalendarId, exports.resolveTimeZoneId = resolveTimeZoneId,
|
|
2945
|
+
exports.roundDuration = (refineRelativeTo, getCalendarOps, getTimeZoneOps, slots, options) => {
|
|
2946
|
+
const durationLargestUnit = getMaxDurationUnit(slots), [largestUnit, smallestUnit, roundingInc, roundingMode, relativeToSlots] = ((options, defaultLargestUnit, refineRelativeTo) => {
|
|
2947
|
+
options = normalizeOptionsOrString(options, smallestUnitStr);
|
|
2948
|
+
let largestUnit = refineLargestUnit(options);
|
|
2949
|
+
const relativeToInternals = refineRelativeTo(options.relativeTo);
|
|
2950
|
+
let roundingInc = parseRoundingIncInteger(options);
|
|
2951
|
+
const roundingMode = refineRoundingMode(options, 7);
|
|
2952
|
+
let smallestUnit = refineSmallestUnit(options);
|
|
2953
|
+
if (void 0 === largestUnit && void 0 === smallestUnit) {
|
|
2954
|
+
throw new RangeError("Required smallestUnit or largestUnit");
|
|
2955
|
+
}
|
|
2956
|
+
if (null == smallestUnit && (smallestUnit = 0), null == largestUnit && (largestUnit = Math.max(smallestUnit, defaultLargestUnit)),
|
|
2957
|
+
checkLargestSmallestUnit(largestUnit, smallestUnit), roundingInc = refineRoundingInc(roundingInc, smallestUnit, 1),
|
|
2958
|
+
roundingInc > 1 && smallestUnit > 5 && largestUnit !== smallestUnit) {
|
|
2959
|
+
throw new RangeError("For calendar units with roundingIncrement > 1, use largestUnit = smallestUnit");
|
|
2960
|
+
}
|
|
2961
|
+
return [ largestUnit, smallestUnit, roundingInc, roundingMode, relativeToInternals ];
|
|
2962
|
+
})(options, durationLargestUnit, refineRelativeTo), maxUnit = Math.max(durationLargestUnit, largestUnit);
|
|
2963
|
+
if (!relativeToSlots && maxUnit <= 6) {
|
|
2964
|
+
return createDurationSlots(checkDurationUnits(((durationFields, largestUnit, smallestUnit, roundingInc, roundingMode) => {
|
|
2965
|
+
const roundedBigNano = roundBigNano(durationFieldsToBigNano(durationFields), smallestUnit, roundingInc, roundingMode);
|
|
2966
|
+
return {
|
|
2967
|
+
...durationFieldDefaults,
|
|
2968
|
+
...nanoToDurationDayTimeFields(roundedBigNano, largestUnit)
|
|
2969
|
+
};
|
|
2970
|
+
})(slots, largestUnit, smallestUnit, roundingInc, roundingMode)));
|
|
2971
|
+
}
|
|
2972
|
+
if (!isZonedEpochSlots(relativeToSlots) && !slots.sign) {
|
|
2973
|
+
return slots;
|
|
2974
|
+
}
|
|
2975
|
+
if (!relativeToSlots) {
|
|
2976
|
+
throw new RangeError("Missing relativeTo");
|
|
2977
|
+
}
|
|
2978
|
+
const [marker, calendarOps, timeZoneOps] = createMarkerSystem(getCalendarOps, getTimeZoneOps, relativeToSlots), markerToEpochNano = createMarkerToEpochNano(timeZoneOps), moveMarker = createMoveMarker(timeZoneOps), diffMarkers = createDiffMarkers(timeZoneOps), endMarker = moveMarker(calendarOps, marker, slots);
|
|
2979
|
+
isZonedEpochSlots(relativeToSlots) || (checkIsoDateTimeInBounds(marker), checkIsoDateTimeInBounds(endMarker));
|
|
2980
|
+
let balancedDuration = diffMarkers(calendarOps, marker, endMarker, largestUnit);
|
|
2981
|
+
const origSign = slots.sign, balancedSign = computeDurationSign(balancedDuration);
|
|
2982
|
+
if (origSign && balancedSign && origSign !== balancedSign) {
|
|
2983
|
+
throw new RangeError(invalidProtocolResults);
|
|
2984
|
+
}
|
|
2985
|
+
return balancedDuration = roundRelativeDuration(balancedDuration, markerToEpochNano(endMarker), largestUnit, smallestUnit, roundingInc, roundingMode, calendarOps, marker, markerToEpochNano, moveMarker),
|
|
2986
|
+
createDurationSlots(balancedDuration);
|
|
2987
|
+
}, exports.roundInstant = (instantSlots, options) => {
|
|
2988
|
+
const [smallestUnit, roundingInc, roundingMode] = refineRoundingOptions(options, 5, 1);
|
|
2989
|
+
return createInstantSlots(roundBigNano(instantSlots.epochNanoseconds, smallestUnit, roundingInc, roundingMode, 1));
|
|
2990
|
+
}, exports.roundPlainDateTime = (slots, options) => createPlainDateTimeSlots(roundDateTime(slots, ...refineRoundingOptions(options)), slots.calendar),
|
|
2991
|
+
exports.roundPlainTime = (slots, options) => {
|
|
2992
|
+
const [a, b, c] = refineRoundingOptions(options, 5);
|
|
2993
|
+
var roundingMode;
|
|
2994
|
+
return createPlainTimeSlots((roundingMode = c, roundTimeToNano(slots, computeNanoInc(a, b), roundingMode)[0]));
|
|
2995
|
+
}, exports.roundZonedDateTime = (getTimeZoneOps, slots, options) => {
|
|
2996
|
+
let {epochNanoseconds: epochNanoseconds, timeZone: timeZone, calendar: calendar} = slots;
|
|
2997
|
+
const [smallestUnit, roundingInc, roundingMode] = refineRoundingOptions(options);
|
|
2998
|
+
if (0 === smallestUnit && 1 === roundingInc) {
|
|
2999
|
+
return slots;
|
|
3000
|
+
}
|
|
3001
|
+
const timeZoneOps = getTimeZoneOps(timeZone);
|
|
3002
|
+
if (6 === smallestUnit) {
|
|
3003
|
+
epochNanoseconds = ((computeInterval, timeZoneOps, slots, roundingMode) => {
|
|
3004
|
+
const isoSlots = zonedEpochSlotsToIso(slots, timeZoneOps), [isoFields0, isoFields1] = computeInterval(isoSlots), epochNano = slots.epochNanoseconds, epochNano0 = getStartOfDayInstantFor(timeZoneOps, isoFields0), epochNano1 = getStartOfDayInstantFor(timeZoneOps, isoFields1);
|
|
3005
|
+
if (bigNanoOutside(epochNano, epochNano0, epochNano1)) {
|
|
3006
|
+
throw new RangeError(invalidProtocolResults);
|
|
3007
|
+
}
|
|
3008
|
+
return roundWithMode(computeEpochNanoFrac(epochNano, epochNano0, epochNano1), roundingMode) ? epochNano1 : epochNano0;
|
|
3009
|
+
})(computeDayInterval, timeZoneOps, slots, roundingMode);
|
|
3010
|
+
} else {
|
|
3011
|
+
const offsetNano = timeZoneOps.getOffsetNanosecondsFor(epochNanoseconds);
|
|
3012
|
+
epochNanoseconds = getMatchingInstantFor(timeZoneOps, roundDateTime(epochNanoToIso(epochNanoseconds, offsetNano), smallestUnit, roundingInc, roundingMode), offsetNano, 2, 0, 1);
|
|
3013
|
+
}
|
|
3014
|
+
return createZonedDateTimeSlots(epochNanoseconds, timeZone, calendar);
|
|
3015
|
+
}, exports.slotsWithCalendarId = (slots, calendarId) => ({
|
|
3016
|
+
...slots,
|
|
3017
|
+
calendar: calendarId
|
|
3018
|
+
}), exports.slotsWithTimeZoneId = (slots, timeZoneId) => ({
|
|
3019
|
+
...slots,
|
|
3020
|
+
timeZone: timeZoneId
|
|
3021
|
+
}), exports.timeConfig = timeConfig, exports.timeFieldNamesAsc = timeFieldNamesAsc,
|
|
3022
|
+
exports.totalDuration = (refineRelativeTo, getCalendarOps, getTimeZoneOps, slots, options) => {
|
|
3023
|
+
const maxDurationUnit = getMaxDurationUnit(slots), [totalUnit, relativeToSlots] = ((options, refineRelativeTo) => {
|
|
3024
|
+
const relativeToInternals = refineRelativeTo((options = normalizeOptionsOrString(options, "unit")).relativeTo);
|
|
3025
|
+
let totalUnit = refineTotalUnit(options);
|
|
3026
|
+
return totalUnit = requirePropDefined("unit", totalUnit), [ totalUnit, relativeToInternals ];
|
|
3027
|
+
})(options, refineRelativeTo), maxUnit = Math.max(totalUnit, maxDurationUnit);
|
|
3028
|
+
if (!relativeToSlots && isUniformUnit(maxUnit, relativeToSlots)) {
|
|
3029
|
+
return totalDayTimeDuration(slots, totalUnit);
|
|
3030
|
+
}
|
|
3031
|
+
if (!relativeToSlots) {
|
|
3032
|
+
throw new RangeError("Missing relativeTo");
|
|
3033
|
+
}
|
|
3034
|
+
if (!slots.sign) {
|
|
3035
|
+
return 0;
|
|
3036
|
+
}
|
|
3037
|
+
const [marker, calendarOps, timeZoneOps] = createMarkerSystem(getCalendarOps, getTimeZoneOps, relativeToSlots), markerToEpochNano = createMarkerToEpochNano(timeZoneOps), moveMarker = createMoveMarker(timeZoneOps), diffMarkers = createDiffMarkers(timeZoneOps), endMarker = moveMarker(calendarOps, marker, slots);
|
|
3038
|
+
isZonedEpochSlots(relativeToSlots) || (checkIsoDateTimeInBounds(marker), checkIsoDateTimeInBounds(endMarker));
|
|
3039
|
+
const balancedDuration = diffMarkers(calendarOps, marker, endMarker, totalUnit);
|
|
3040
|
+
return isUniformUnit(totalUnit, relativeToSlots) ? totalDayTimeDuration(balancedDuration, totalUnit) : ((durationFields, endEpochNano, totalUnit, calendarOps, marker, markerToEpochNano, moveMarker) => {
|
|
3041
|
+
const sign = computeDurationSign(durationFields), [epochNano0, epochNano1] = clampRelativeDuration(calendarOps, clearDurationFields(totalUnit, durationFields), totalUnit, sign, marker, markerToEpochNano, moveMarker), frac = computeEpochNanoFrac(endEpochNano, epochNano0, epochNano1);
|
|
3042
|
+
return durationFields[durationFieldNamesAsc[totalUnit]] + frac * sign;
|
|
3043
|
+
})(balancedDuration, markerToEpochNano(endMarker), totalUnit, calendarOps, marker, markerToEpochNano, moveMarker);
|
|
3044
|
+
}, exports.yearMonthConfig = yearMonthConfig, exports.zonedConfig = zonedConfig,
|
|
3045
|
+
exports.zonedDateTimeToInstant = zonedDateTimeSlots0 => createInstantSlots(zonedDateTimeSlots0.epochNanoseconds),
|
|
3046
|
+
exports.zonedDateTimeToPlainDate = (getTimeZoneOps, zonedDateTimeSlots0) => createPlainDateSlots(zonedEpochSlotsToIso(zonedDateTimeSlots0, getTimeZoneOps)),
|
|
3047
|
+
exports.zonedDateTimeToPlainDateTime = (getTimeZoneOps, zonedDateTimeSlots0) => createPlainDateTimeSlots(zonedEpochSlotsToIso(zonedDateTimeSlots0, getTimeZoneOps)),
|
|
3048
|
+
exports.zonedDateTimeToPlainTime = (getTimeZoneOps, zonedDateTimeSlots0) => createPlainTimeSlots(zonedEpochSlotsToIso(zonedDateTimeSlots0, getTimeZoneOps)),
|
|
3049
|
+
exports.zonedDateTimeWithFields = (getCalendarOps, getTimeZoneOps, zonedDateTimeSlots, modFields, options) => {
|
|
3050
|
+
const {calendar: calendar, timeZone: timeZone} = zonedDateTimeSlots, calendarOps = getCalendarOps(calendar), timeZoneOps = getTimeZoneOps(timeZone), validFieldNames = [ ...calendarOps.fields(dateFieldNamesAlpha), ...timeAndOffsetFieldNames ].sort(), origFields = (slots => {
|
|
3051
|
+
const isoFields = zonedEpochSlotsToIso(slots, queryNativeTimeZone), offsetString = formatOffsetNano(isoFields.offsetNanoseconds), calendarOps = createNativePartOps(slots.calendar), [year, month, day] = calendarOps.dateParts(isoFields), [monthCodeNumber, isLeapMonth] = calendarOps.monthCodeParts(year, month), monthCode = formatMonthCode(monthCodeNumber, isLeapMonth);
|
|
3052
|
+
return {
|
|
3053
|
+
...isoTimeFieldsToCal(isoFields),
|
|
3054
|
+
year: year,
|
|
3055
|
+
monthCode: monthCode,
|
|
3056
|
+
day: day,
|
|
3057
|
+
offset: offsetString
|
|
3058
|
+
};
|
|
3059
|
+
})(zonedDateTimeSlots), partialFields = refineFields(modFields, validFieldNames), mergedCalendarFields = calendarOps.mergeFields(origFields, partialFields), mergedAllFields = {
|
|
3060
|
+
...origFields,
|
|
3061
|
+
...partialFields
|
|
3062
|
+
}, [overflow, offsetDisambig, epochDisambig] = refineZonedFieldOptions(options, 2);
|
|
3063
|
+
return createZonedDateTimeSlots(getMatchingInstantFor(timeZoneOps, {
|
|
3064
|
+
...calendarOps.dateFromFields(mergedCalendarFields, fabricateOverflowOptions(overflow)),
|
|
3065
|
+
...constrainIsoTimeFields(timeFieldsToIso(mergedAllFields), overflow)
|
|
3066
|
+
}, parseOffsetNano(mergedAllFields.offset), offsetDisambig, epochDisambig), timeZone, calendar);
|
|
3067
|
+
}, exports.zonedDateTimeWithPlainTime = (getTimeZoneOps, zonedDateTimeSlots, plainTimeSlots) => {
|
|
3068
|
+
const timeZoneId = zonedDateTimeSlots.timeZone, timeZoneOps = getTimeZoneOps(timeZoneId), isoFields = {
|
|
3069
|
+
...zonedEpochSlotsToIso(zonedDateTimeSlots, timeZoneOps),
|
|
3070
|
+
...plainTimeSlots || isoTimeFieldDefaults
|
|
3071
|
+
};
|
|
3072
|
+
let epochNano;
|
|
3073
|
+
return epochNano = plainTimeSlots ? getMatchingInstantFor(timeZoneOps, isoFields, isoFields.offsetNanoseconds, 2) : getStartOfDayInstantFor(timeZoneOps, isoFields),
|
|
3074
|
+
createZonedDateTimeSlots(epochNano, timeZoneId, zonedDateTimeSlots.calendar);
|
|
3075
|
+
}, exports.zonedDateTimesEqual = (zonedDateTimeSlots0, zonedDateTimeSlots1) => !compareZonedDateTimes(zonedDateTimeSlots0, zonedDateTimeSlots1) && !!isTimeZoneIdsEqual(zonedDateTimeSlots0.timeZone, zonedDateTimeSlots1.timeZone) && zonedDateTimeSlots0.calendar === zonedDateTimeSlots1.calendar,
|
|
3076
|
+
exports.zonedEpochSlotsToIso = zonedEpochSlotsToIso;
|