generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
luxon.js
8212 lines (7078 loc) · 257 KB
/
luxon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*eslint-disable */
const luxon = (function (exports) {
function _defineProperties(target, props) {
for (let i = 0; i < props.length; i++) {
const descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ('value' in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _extends() {
_extends = Object.assign || function (target) {
for (let i = 1; i < arguments.length; i++) {
const source = arguments[i];
for (const key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === 'undefined' || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === 'function') return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], () => {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct;
} else {
_construct = function _construct(Parent, args, Class) {
const a = [null];
a.push.apply(a, args);
const Constructor = Function.bind.apply(Parent, a);
const instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf('[native code]') !== -1;
}
function _wrapNativeSuper(Class) {
const _cache = typeof Map === 'function' ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== 'function') {
throw new TypeError('Super expression must either be null or a function');
}
if (typeof _cache !== 'undefined') {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true,
},
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
const target = {};
const sourceKeys = Object.keys(source);
let key; let
i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === 'string') return _arrayLikeToArray(o, minLen);
let n = Object.prototype.toString.call(o).slice(8, -1);
if (n === 'Object' && o.constructor) n = o.constructor.name;
if (n === 'Map' || n === 'Set') return Array.from(o);
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
let it = typeof Symbol !== 'undefined' && o[Symbol.iterator] || o['@@iterator'];
if (it) return (it = it.call(o)).next.bind(it);
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === 'number') {
if (it) o = it;
let i = 0;
return function () {
if (i >= o.length) {
return {
done: true,
};
}
return {
done: false,
value: o[i++],
};
};
}
throw new TypeError('Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.');
}
// these aren't really private, but nor are they really useful to document
/**
* @private
*/
const LuxonError = /* #__PURE__ */(function (_Error) {
_inheritsLoose(LuxonError, _Error);
function LuxonError() {
return _Error.apply(this, arguments) || this;
}
return LuxonError;
}(/* #__PURE__ */_wrapNativeSuper(Error)));
/**
* @private
*/
const InvalidDateTimeError = /* #__PURE__ */(function (_LuxonError) {
_inheritsLoose(InvalidDateTimeError, _LuxonError);
function InvalidDateTimeError(reason) {
return _LuxonError.call(this, `Invalid DateTime: ${reason.toMessage()}`) || this;
}
return InvalidDateTimeError;
}(LuxonError));
/**
* @private
*/
const InvalidIntervalError = /* #__PURE__ */(function (_LuxonError2) {
_inheritsLoose(InvalidIntervalError, _LuxonError2);
function InvalidIntervalError(reason) {
return _LuxonError2.call(this, `Invalid Interval: ${reason.toMessage()}`) || this;
}
return InvalidIntervalError;
}(LuxonError));
/**
* @private
*/
const InvalidDurationError = /* #__PURE__ */(function (_LuxonError3) {
_inheritsLoose(InvalidDurationError, _LuxonError3);
function InvalidDurationError(reason) {
return _LuxonError3.call(this, `Invalid Duration: ${reason.toMessage()}`) || this;
}
return InvalidDurationError;
}(LuxonError));
/**
* @private
*/
const ConflictingSpecificationError = /* #__PURE__ */(function (_LuxonError4) {
_inheritsLoose(ConflictingSpecificationError, _LuxonError4);
function ConflictingSpecificationError() {
return _LuxonError4.apply(this, arguments) || this;
}
return ConflictingSpecificationError;
}(LuxonError));
/**
* @private
*/
const InvalidUnitError = /* #__PURE__ */(function (_LuxonError5) {
_inheritsLoose(InvalidUnitError, _LuxonError5);
function InvalidUnitError(unit) {
return _LuxonError5.call(this, `Invalid unit ${unit}`) || this;
}
return InvalidUnitError;
}(LuxonError));
/**
* @private
*/
const InvalidArgumentError = /* #__PURE__ */(function (_LuxonError6) {
_inheritsLoose(InvalidArgumentError, _LuxonError6);
function InvalidArgumentError() {
return _LuxonError6.apply(this, arguments) || this;
}
return InvalidArgumentError;
}(LuxonError));
/**
* @private
*/
const ZoneIsAbstractError = /* #__PURE__ */(function (_LuxonError7) {
_inheritsLoose(ZoneIsAbstractError, _LuxonError7);
function ZoneIsAbstractError() {
return _LuxonError7.call(this, 'Zone is an abstract class') || this;
}
return ZoneIsAbstractError;
}(LuxonError));
/**
* @private
*/
const n = 'numeric';
const s = 'short';
const l = 'long';
const DATE_SHORT = {
year: n,
month: n,
day: n,
};
const DATE_MED = {
year: n,
month: s,
day: n,
};
const DATE_MED_WITH_WEEKDAY = {
year: n,
month: s,
day: n,
weekday: s,
};
const DATE_FULL = {
year: n,
month: l,
day: n,
};
const DATE_HUGE = {
year: n,
month: l,
day: n,
weekday: l,
};
const TIME_SIMPLE = {
hour: n,
minute: n,
};
const TIME_WITH_SECONDS = {
hour: n,
minute: n,
second: n,
};
const TIME_WITH_SHORT_OFFSET = {
hour: n,
minute: n,
second: n,
timeZoneName: s,
};
const TIME_WITH_LONG_OFFSET = {
hour: n,
minute: n,
second: n,
timeZoneName: l,
};
const TIME_24_SIMPLE = {
hour: n,
minute: n,
hourCycle: 'h23',
};
const TIME_24_WITH_SECONDS = {
hour: n,
minute: n,
second: n,
hourCycle: 'h23',
};
const TIME_24_WITH_SHORT_OFFSET = {
hour: n,
minute: n,
second: n,
hourCycle: 'h23',
timeZoneName: s,
};
const TIME_24_WITH_LONG_OFFSET = {
hour: n,
minute: n,
second: n,
hourCycle: 'h23',
timeZoneName: l,
};
const DATETIME_SHORT = {
year: n,
month: n,
day: n,
hour: n,
minute: n,
};
const DATETIME_SHORT_WITH_SECONDS = {
year: n,
month: n,
day: n,
hour: n,
minute: n,
second: n,
};
const DATETIME_MED = {
year: n,
month: s,
day: n,
hour: n,
minute: n,
};
const DATETIME_MED_WITH_SECONDS = {
year: n,
month: s,
day: n,
hour: n,
minute: n,
second: n,
};
const DATETIME_MED_WITH_WEEKDAY = {
year: n,
month: s,
day: n,
weekday: s,
hour: n,
minute: n,
};
const DATETIME_FULL = {
year: n,
month: l,
day: n,
hour: n,
minute: n,
timeZoneName: s,
};
const DATETIME_FULL_WITH_SECONDS = {
year: n,
month: l,
day: n,
hour: n,
minute: n,
second: n,
timeZoneName: s,
};
const DATETIME_HUGE = {
year: n,
month: l,
day: n,
weekday: l,
hour: n,
minute: n,
timeZoneName: l,
};
const DATETIME_HUGE_WITH_SECONDS = {
year: n,
month: l,
day: n,
weekday: l,
hour: n,
minute: n,
second: n,
timeZoneName: l,
};
/**
* @private
*/
// TYPES
function isUndefined(o) {
return typeof o === 'undefined';
}
function isNumber(o) {
return typeof o === 'number';
}
function isInteger(o) {
return typeof o === 'number' && o % 1 === 0;
}
function isString(o) {
return typeof o === 'string';
}
function isDate(o) {
return Object.prototype.toString.call(o) === '[object Date]';
} // CAPABILITIES
function hasRelative() {
try {
return typeof Intl !== 'undefined' && !!Intl.RelativeTimeFormat;
} catch (e) {
return false;
}
} // OBJECTS AND ARRAYS
function maybeArray(thing) {
return Array.isArray(thing) ? thing : [thing];
}
function bestBy(arr, by, compare) {
if (arr.length === 0) {
return undefined;
}
return arr.reduce((best, next) => {
const pair = [by(next), next];
if (!best) {
return pair;
} if (compare(best[0], pair[0]) === best[0]) {
return best;
}
return pair;
}, null)[1];
}
function pick(obj, keys) {
return keys.reduce((a, k) => {
a[k] = obj[k];
return a;
}, {});
}
function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
} // NUMBERS AND STRINGS
function integerBetween(thing, bottom, top) {
return isInteger(thing) && thing >= bottom && thing <= top;
} // x % n but takes the sign of n instead of x
function floorMod(x, n) {
return x - n * Math.floor(x / n);
}
function padStart(input, n) {
if (n === void 0) {
n = 2;
}
const minus = input < 0 ? '-' : '';
const target = minus ? input * -1 : input;
let result;
if (target.toString().length < n) {
result = ('0'.repeat(n) + target).slice(-n);
} else {
result = target.toString();
}
return `${minus}${result}`;
}
function parseInteger(string) {
if (isUndefined(string) || string === null || string === '') {
return undefined;
}
return parseInt(string, 10);
}
function parseFloating(string) {
if (isUndefined(string) || string === null || string === '') {
return undefined;
}
return parseFloat(string);
}
function parseMillis(fraction) {
// Return undefined (instead of 0) in these cases, where fraction is not set
if (isUndefined(fraction) || fraction === null || fraction === '') {
return undefined;
}
const f = parseFloat(`0.${fraction}`) * 1000;
return Math.floor(f);
}
function roundTo(number, digits, towardZero) {
if (towardZero === void 0) {
towardZero = false;
}
const factor = Math.pow(10, digits);
const rounder = towardZero ? Math.trunc : Math.round;
return rounder(number * factor) / factor;
} // DATE BASICS
function isLeapYear(year) {
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
function daysInYear(year) {
return isLeapYear(year) ? 366 : 365;
}
function daysInMonth(year, month) {
const modMonth = floorMod(month - 1, 12) + 1;
const modYear = year + (month - modMonth) / 12;
if (modMonth === 2) {
return isLeapYear(modYear) ? 29 : 28;
}
return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1];
} // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
function objToLocalTS(obj) {
let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond); // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
if (obj.year < 100 && obj.year >= 0) {
d = new Date(d);
d.setUTCFullYear(d.getUTCFullYear() - 1900);
}
return +d;
}
function weeksInWeekYear(weekYear) {
const p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7;
const last = weekYear - 1;
const p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7;
return p1 === 4 || p2 === 3 ? 53 : 52;
}
function untruncateYear(year) {
if (year > 99) {
return year;
} return year > 60 ? 1900 + year : 2000 + year;
} // PARSING
function parseZoneInfo(ts, offsetFormat, locale, timeZone) {
if (timeZone === void 0) {
timeZone = null;
}
const date = new Date(ts);
const intlOpts = {
hourCycle: 'h23',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
};
if (timeZone) {
intlOpts.timeZone = timeZone;
}
const modified = { timeZoneName: offsetFormat, ...intlOpts };
const parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find((m) => m.type.toLowerCase() === 'timezonename');
return parsed ? parsed.value : null;
} // signedOffset('-5', '30') -> -330
function signedOffset(offHourStr, offMinuteStr) {
let offHour = parseInt(offHourStr, 10); // don't || this because we want to preserve -0
if (Number.isNaN(offHour)) {
offHour = 0;
}
const offMin = parseInt(offMinuteStr, 10) || 0;
const offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin;
return offHour * 60 + offMinSigned;
} // COERCION
function asNumber(value) {
const numericValue = Number(value);
if (typeof value === 'boolean' || value === '' || Number.isNaN(numericValue)) throw new InvalidArgumentError(`Invalid unit value ${value}`);
return numericValue;
}
function normalizeObject(obj, normalizer) {
const normalized = {};
for (const u in obj) {
if (hasOwnProperty(obj, u)) {
const v = obj[u];
if (v === undefined || v === null) continue;
normalized[normalizer(u)] = asNumber(v);
}
}
return normalized;
}
function formatOffset(offset, format) {
const hours = Math.trunc(Math.abs(offset / 60));
const minutes = Math.trunc(Math.abs(offset % 60));
const sign = offset >= 0 ? '+' : '-';
switch (format) {
case 'short':
return `${sign}${padStart(hours, 2)}:${padStart(minutes, 2)}`;
case 'narrow':
return `${sign}${hours}${minutes > 0 ? `:${minutes}` : ''}`;
case 'techie':
return `${sign}${padStart(hours, 2)}${padStart(minutes, 2)}`;
default:
throw new RangeError(`Value format ${format} is out of range for property format`);
}
}
function timeObject(obj) {
return pick(obj, ['hour', 'minute', 'second', 'millisecond']);
}
const ianaRegex = /[A-Za-z_+-]{1,256}(:?\/[A-Za-z0-9_+-]{1,256}(\/[A-Za-z0-9_+-]{1,256})?)?/;
/**
* @private
*/
const monthsLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
const monthsShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const monthsNarrow = ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'];
function months(length) {
switch (length) {
case 'narrow':
return [].concat(monthsNarrow);
case 'short':
return [].concat(monthsShort);
case 'long':
return [].concat(monthsLong);
case 'numeric':
return ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
case '2-digit':
return ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
default:
return null;
}
}
const weekdaysLong = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const weekdaysShort = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
const weekdaysNarrow = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
function weekdays(length) {
switch (length) {
case 'narrow':
return [].concat(weekdaysNarrow);
case 'short':
return [].concat(weekdaysShort);
case 'long':
return [].concat(weekdaysLong);
case 'numeric':
return ['1', '2', '3', '4', '5', '6', '7'];
default:
return null;
}
}
const meridiems = ['AM', 'PM'];
const erasLong = ['Before Christ', 'Anno Domini'];
const erasShort = ['BC', 'AD'];
const erasNarrow = ['B', 'A'];
function eras(length) {
switch (length) {
case 'narrow':
return [].concat(erasNarrow);
case 'short':
return [].concat(erasShort);
case 'long':
return [].concat(erasLong);
default:
return null;
}
}
function meridiemForDateTime(dt) {
return meridiems[dt.hour < 12 ? 0 : 1];
}
function weekdayForDateTime(dt, length) {
return weekdays(length)[dt.weekday - 1];
}
function monthForDateTime(dt, length) {
return months(length)[dt.month - 1];
}
function eraForDateTime(dt, length) {
return eras(length)[dt.year < 0 ? 0 : 1];
}
function formatRelativeTime(unit, count, numeric, narrow) {
if (numeric === void 0) {
numeric = 'always';
}
if (narrow === void 0) {
narrow = false;
}
const units = {
years: ['year', 'yr.'],
quarters: ['quarter', 'qtr.'],
months: ['month', 'mo.'],
weeks: ['week', 'wk.'],
days: ['day', 'day', 'days'],
hours: ['hour', 'hr.'],
minutes: ['minute', 'min.'],
seconds: ['second', 'sec.'],
};
const lastable = ['hours', 'minutes', 'seconds'].indexOf(unit) === -1;
if (numeric === 'auto' && lastable) {
const isDay = unit === 'days';
switch (count) {
case 1:
return isDay ? 'tomorrow' : `next ${units[unit][0]}`;
case -1:
return isDay ? 'yesterday' : `last ${units[unit][0]}`;
case 0:
return isDay ? 'today' : `this ${units[unit][0]}`;
}
}
const isInPast = Object.is(count, -0) || count < 0;
const fmtValue = Math.abs(count);
const singular = fmtValue === 1;
const lilUnits = units[unit];
const fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit;
return isInPast ? `${fmtValue} ${fmtUnit} ago` : `in ${fmtValue} ${fmtUnit}`;
}
function stringifyTokens(splits, tokenToString) {
let s = '';
for (var _iterator = _createForOfIteratorHelperLoose(splits), _step; !(_step = _iterator()).done;) {
const token = _step.value;
if (token.literal) {
s += token.val;
} else {
s += tokenToString(token.val);
}
}
return s;
}
const _macroTokenToFormatOpts = {
D: DATE_SHORT,
DD: DATE_MED,
DDD: DATE_FULL,
DDDD: DATE_HUGE,
t: TIME_SIMPLE,
tt: TIME_WITH_SECONDS,
ttt: TIME_WITH_SHORT_OFFSET,
tttt: TIME_WITH_LONG_OFFSET,
T: TIME_24_SIMPLE,
TT: TIME_24_WITH_SECONDS,
TTT: TIME_24_WITH_SHORT_OFFSET,
TTTT: TIME_24_WITH_LONG_OFFSET,
f: DATETIME_SHORT,
ff: DATETIME_MED,
fff: DATETIME_FULL,
ffff: DATETIME_HUGE,
F: DATETIME_SHORT_WITH_SECONDS,
FF: DATETIME_MED_WITH_SECONDS,
FFF: DATETIME_FULL_WITH_SECONDS,
FFFF: DATETIME_HUGE_WITH_SECONDS,
};
/**
* @private
*/
const Formatter = /* #__PURE__ */(function () {
Formatter.create = function create(locale, opts) {
if (opts === void 0) {
opts = {};
}
return new Formatter(locale, opts);
};
Formatter.parseFormat = function parseFormat(fmt) {
let current = null;
let currentFull = '';
let bracketed = false;
const splits = [];
for (let i = 0; i < fmt.length; i++) {
const c = fmt.charAt(i);
if (c === "'") {
if (currentFull.length > 0) {
splits.push({
literal: bracketed,
val: currentFull,
});
}
current = null;
currentFull = '';
bracketed = !bracketed;
} else if (bracketed) {
currentFull += c;
} else if (c === current) {
currentFull += c;
} else {
if (currentFull.length > 0) {
splits.push({
literal: false,
val: currentFull,
});
}
currentFull = c;
current = c;
}
}
if (currentFull.length > 0) {
splits.push({
literal: bracketed,
val: currentFull,
});
}
return splits;
};
Formatter.macroTokenToFormatOpts = function macroTokenToFormatOpts(token) {
return _macroTokenToFormatOpts[token];
};
function Formatter(locale, formatOpts) {
this.opts = formatOpts;
this.loc = locale;
this.systemLoc = null;
}
const _proto = Formatter.prototype;
_proto.formatWithSystemDefault = function formatWithSystemDefault(dt, opts) {
if (this.systemLoc === null) {
this.systemLoc = this.loc.redefaultToSystem();
}
const df = this.systemLoc.dtFormatter(dt, { ...this.opts, ...opts });
return df.format();
};
_proto.formatDateTime = function formatDateTime(dt, opts) {
if (opts === void 0) {
opts = {};
}
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.format();
};
_proto.formatDateTimeParts = function formatDateTimeParts(dt, opts) {
if (opts === void 0) {
opts = {};
}
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.formatToParts();
};
_proto.resolvedOptions = function resolvedOptions(dt, opts) {
if (opts === void 0) {
opts = {};
}
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.resolvedOptions();
};
_proto.num = function num(n, p) {
if (p === void 0) {
p = 0;
}
// we get some perf out of doing this here, annoyingly
if (this.opts.forceSimple) {
return padStart(n, p);
}
const opts = { ...this.opts };
if (p > 0) {
opts.padTo = p;
}
return this.loc.numberFormatter(opts).format(n);
};
_proto.formatDateTimeFromString = function formatDateTimeFromString(dt, fmt) {
const _this = this;
const knownEnglish = this.loc.listingMode() === 'en';
const useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== 'gregory';
const string = function string(opts, extract) {
return _this.loc.extract(dt, opts, extract);
};
const formatOffset = function formatOffset(opts) {
if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) {
return 'Z';
}
return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : '';
};
const meridiem = function meridiem() {
return knownEnglish ? meridiemForDateTime(dt) : string({
hour: 'numeric',
hourCycle: 'h12',
}, 'dayperiod');
};
const month = function month(length, standalone) {
return knownEnglish ? monthForDateTime(dt, length) : string(standalone ? {
month: length,
} : {
month: length,
day: 'numeric',
}, 'month');
};
const weekday = function weekday(length, standalone) {
return knownEnglish ? weekdayForDateTime(dt, length) : string(standalone ? {
weekday: length,
} : {
weekday: length,
month: 'long',
day: 'numeric',
}, 'weekday');
};
const maybeMacro = function maybeMacro(token) {