@fr0st/datetime 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2921 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
+ typeof define === 'function' && define.amd ? define(factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DateTime = factory());
5
+ })(this, (function () { 'use strict';
6
+
7
+ /**
8
+ * DateTime Factory
9
+ */
10
+
11
+ const data = {};
12
+
13
+ /**
14
+ * Get values from cache (or generate if they don't exist).
15
+ * @param {string} key The key for the values.
16
+ * @param {function} callback The callback to generate the values.
17
+ * @return {array} The cached values.
18
+ */
19
+ function getData(key, callback) {
20
+ if (!(key in data)) {
21
+ data[key] = callback();
22
+ }
23
+
24
+ return data[key];
25
+ }
26
+ /**
27
+ * Create a new date formatter for a timeZone.
28
+ * @param {string} timeZone The timeZone.
29
+ * @param {object} options The options for the formatter.
30
+ * @return {Intl.DateTimeFormat} A new DateTimeFormat object.
31
+ */
32
+ function getDateFormatter(timeZone) {
33
+ return getData(
34
+ `dateFormatter.${timeZone}`,
35
+ (_) => makeFormatter('en', {
36
+ timeZone,
37
+ hourCycle: 'h23',
38
+ year: 'numeric',
39
+ month: 'numeric',
40
+ day: 'numeric',
41
+ hour: 'numeric',
42
+ minute: 'numeric',
43
+ }),
44
+ );
45
+ }
46
+ /**
47
+ * Create a new relative formatter for a locale.
48
+ * @param {string} locale The locale.
49
+ * @param {object} options The options for the formatter.
50
+ * @return {Intl.RelativeTimeFormat} A new RelativeTimeFormat object.
51
+ */
52
+ function getRelativeFormatter(locale) {
53
+ if (!('RelativeTimeFormat' in Intl)) {
54
+ return null;
55
+ }
56
+
57
+ return getData(
58
+ `relativeFormatter.${locale}`,
59
+ (_) => new Intl.RelativeTimeFormat(locale, {
60
+ numeric: 'auto',
61
+ style: 'long',
62
+ }),
63
+ );
64
+ }
65
+ /**
66
+ * Create a new formatter for a locale.
67
+ * @param {string} locale The locale.
68
+ * @param {object} options The options for the formatter.
69
+ * @return {Intl.DateTimeFormat} A new DateTimeFormat object.
70
+ */
71
+ function makeFormatter(locale, options) {
72
+ return new Intl.DateTimeFormat(locale, {
73
+ timeZone: 'UTC',
74
+ ...options,
75
+ });
76
+ }
77
+
78
+ /**
79
+ * DateTime Variables
80
+ */
81
+
82
+ const resolvedOptions = (new Intl.DateTimeFormat).resolvedOptions();
83
+
84
+ const config = {
85
+ clampDates: true,
86
+ defaultLocale: resolvedOptions.locale,
87
+ defaultTimeZone: resolvedOptions.timeZone,
88
+ };
89
+
90
+ const dateStringTimeZoneRegExp = /\s(?:UTC|GMT|Z|[\+\-]\d)|\d{4}\-\d{2}\-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d{3}[\+\-]\d{2}\:\d{2}/i;
91
+
92
+ const formats = {
93
+ date: 'eee MMM dd yyyy',
94
+ rfc3339_extended: `yyyy-MM-dd'T'HH:mm:ss.SSSxxx`,
95
+ string: 'eee MMM dd yyyy HH:mm:ss xx (VV)',
96
+ time: 'HH:mm:ss xx (VV)',
97
+ };
98
+
99
+ const formatTokenRegExp = /([a-z])\1*|'[^']*'/i;
100
+
101
+ const monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
102
+
103
+ const offsetRegExp = /(?:GMT)?([\+\-])(\d{2})(\:?)(\d{2})?/;
104
+
105
+ const parseOrderKeys = [
106
+ ['year', 'weekYear'],
107
+ ['era'],
108
+ ['quarter', 'month', 'week', 'dayOfYear'],
109
+ ['weekOfMonth'],
110
+ ['date', 'weekDay'],
111
+ ['weekDayInMonth'],
112
+ ['hours24', 'hours12', 'dayPeriod'],
113
+ ['minutes', 'seconds', 'milliseconds'],
114
+ ];
115
+
116
+ const thresholds = {
117
+ month: 12,
118
+ week: null,
119
+ day: 7,
120
+ hour: 24,
121
+ minute: 60,
122
+ second: 60,
123
+ };
124
+
125
+ /**
126
+ * DateTime Helpers
127
+ */
128
+
129
+ /**
130
+ * Compensate the difference between two dates.
131
+ * @param {DateTime} date The DateTime.
132
+ * @param {DateTime} other The DateTime to compare to.
133
+ * @param {number} amount The amount to compensate.
134
+ * @param {Boolean} [compensate=true] Whether to compensate the amount.
135
+ * @param {number} [compensation=1] The compensation offset.
136
+ * @return {number} The compensated amount.
137
+ */
138
+ function compensateDiff(date, other, amount, compensate = true, compensation = 1) {
139
+ if (amount > 0) {
140
+ amount = Math.floor(amount);
141
+
142
+ if (compensate && date < other) {
143
+ amount += compensation;
144
+ }
145
+ } else if (amount < 0) {
146
+ amount = Math.ceil(amount);
147
+
148
+ if (compensate && date > other) {
149
+ amount -= compensation;
150
+ }
151
+ }
152
+
153
+ return amount;
154
+ }
155
+ /**
156
+ * Get the biggest difference between two dates.
157
+ * @param {DateTime} date The DateTime.
158
+ * @param {DateTime} [other] The DateTime to compare to.
159
+ * @return {array} The biggest difference (amount and time unit).
160
+ */
161
+ function getBiggestDiff(date, other) {
162
+ let lastResult;
163
+ for (const timeUnit of ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']) {
164
+ const relativeDiff = date.diff(other, { timeUnit });
165
+ if (lastResult && thresholds[timeUnit] && Math.abs(relativeDiff) >= thresholds[timeUnit]) {
166
+ return lastResult;
167
+ }
168
+
169
+ const actualDiff = date.diff(other, { timeUnit, relative: false });
170
+ if (actualDiff) {
171
+ return [relativeDiff, timeUnit];
172
+ }
173
+
174
+ if (relativeDiff) {
175
+ lastResult = [relativeDiff, timeUnit];
176
+ } else {
177
+ lastResult = null;
178
+ }
179
+ }
180
+
181
+ return lastResult ?
182
+ lastResult :
183
+ [0, 'second'];
184
+ }
185
+ /**
186
+ * Get the offset for a DateTime.
187
+ * @param {DateTime} date The DateTime.
188
+ * @return {number} The offset.
189
+ */
190
+ function getOffset(date) {
191
+ const timeZone = date.getTimeZone();
192
+
193
+ if (timeZone === 'UTC') {
194
+ return 0;
195
+ }
196
+
197
+ const utcString = getDateFormatter('UTC').format(date);
198
+ const localString = getDateFormatter(timeZone).format(date);
199
+
200
+ return (new Date(utcString) - new Date(localString)) / 60000;
201
+ }
202
+ /**
203
+ * Get the number of milliseconds since the UNIX epoch (offset to timeZone).
204
+ * @param {DateTime} date The DateTime.
205
+ * @return {number} The number of milliseconds since the UNIX epoch (offset to timeZone).
206
+ */
207
+ function getOffsetTime(date) {
208
+ return date.getTime() - (date.getTimeZoneOffset() * 60000);
209
+ }
210
+ /**
211
+ * Modify a DateTime by a duration.
212
+ * @param {DateTime} date The DateTime.
213
+ * @param {number} amount The amount to modify the date by.
214
+ * @param {string} [timeUnit] The unit of time.
215
+ * @return {DateTime} The DateTime object.
216
+ */
217
+ function modify(date, amount, timeUnit) {
218
+ timeUnit = timeUnit.toLowerCase();
219
+
220
+ switch (timeUnit) {
221
+ case 'second':
222
+ case 'seconds':
223
+ return date.setSeconds(
224
+ date.getSeconds() + amount,
225
+ );
226
+ case 'minute':
227
+ case 'minutes':
228
+ return date.setMinutes(
229
+ date.getMinutes() + amount,
230
+ );
231
+ case 'hour':
232
+ case 'hours':
233
+ return date.setHours(
234
+ date.getHours() + amount,
235
+ );
236
+ case 'week':
237
+ case 'weeks':
238
+ return date.setDate(
239
+ date.getDate() + (amount * 7),
240
+ );
241
+ case 'day':
242
+ case 'days':
243
+ return date.setDate(
244
+ date.getDate() + amount,
245
+ );
246
+ case 'month':
247
+ case 'months':
248
+ return date.setMonth(
249
+ date.getMonth() + amount,
250
+ );
251
+ case 'year':
252
+ case 'years':
253
+ return date.setYear(
254
+ date.getYear() + amount,
255
+ );
256
+ default:
257
+ throw new Error('Invalid time unit supplied');
258
+ }
259
+ }
260
+ /**
261
+ * Compare a literal format string with a date string.
262
+ * @param {string} formatString The literal format string.
263
+ * @param {string} dateString The date string.
264
+ */
265
+ function parseCompare(formatString, dateString) {
266
+ let i = 0;
267
+ for (const char of formatString) {
268
+ if (char !== dateString[i]) {
269
+ throw new Error(`Unmatched character in DateTime string: ${char}`);
270
+ }
271
+
272
+ i++;
273
+ }
274
+ }
275
+ /**
276
+ * Generate methods for parsing a date.
277
+ * @return {object} An object containing date parsing methods.
278
+ */
279
+ function parseFactory() {
280
+ let isPM = false;
281
+ let lastAM = true;
282
+
283
+ return {
284
+ date: {
285
+ get: (datetime) => datetime.getDate(),
286
+ set: (datetime, value) => datetime.setDate(value),
287
+ },
288
+ dayPeriod: {
289
+ get: (datetime) => datetime.getHours() < 12 ? 0 : 1,
290
+ set: (datetime, value) => {
291
+ isPM = value;
292
+ let hours = value ? 12 : 0;
293
+ if (lastAM) {
294
+ hours += datetime.getHours();
295
+ }
296
+ return datetime.setHours(hours);
297
+ },
298
+ },
299
+ dayOfYear: {
300
+ get: (datetime) => datetime.getDayOfYear(),
301
+ set: (datetime, value) => datetime.setDayOfYear(value),
302
+ },
303
+ era: {
304
+ get: (datetime) => datetime.getYear() < 1 ? 0 : 1,
305
+ set: (datetime, value) => {
306
+ const offset = value ? 1 : -1;
307
+ return datetime.setYear(
308
+ datetime.getYear() * offset,
309
+ );
310
+ },
311
+ },
312
+ hours12: {
313
+ get: (datetime) => datetime.getHours() % 12,
314
+ set: (datetime, value) => {
315
+ if (isPM) {
316
+ value += 12;
317
+ }
318
+ lastAM = true;
319
+ return datetime.setHours(value);
320
+ },
321
+ },
322
+ hours24: {
323
+ get: (datetime) => datetime.getHours(),
324
+ set: (datetime, value) => {
325
+ lastAM = false;
326
+ return datetime.setHours(value);
327
+ },
328
+ },
329
+ milliseconds: {
330
+ get: (datetime) => datetime.getMilliseconds(),
331
+ set: (datetime, value) => datetime.setMilliseconds(value),
332
+ },
333
+ minutes: {
334
+ get: (datetime) => datetime.getMinutes(),
335
+ set: (datetime, value) => datetime.setMinutes(value),
336
+ },
337
+ month: {
338
+ get: (datetime) => datetime.getMonth(),
339
+ set: (datetime, value) => datetime.setMonth(value),
340
+ },
341
+ quarter: {
342
+ get: (datetime) => datetime.getQuarter(),
343
+ set: (datetime, value) => datetime.setQuarter(value),
344
+ },
345
+ seconds: {
346
+ get: (datetime) => datetime.getSeconds(),
347
+ set: (datetime, value) => datetime.setSeconds(value),
348
+ },
349
+ week: {
350
+ get: (datetime) => datetime.getWeek(),
351
+ set: (datetime, value) => datetime.setWeek(value),
352
+ },
353
+ weekDay: {
354
+ get: (datetime) => datetime.getWeekDay(),
355
+ set: (datetime, value) => datetime.setWeekDay(value),
356
+ },
357
+ weekDayInMonth: {
358
+ get: (datetime) => datetime.getWeekDayInMonth(),
359
+ set: (datetime, value) => datetime.setWeekDayInMonth(value),
360
+ },
361
+ weekOfMonth: {
362
+ get: (datetime) => datetime.getWeekOfMonth(),
363
+ set: (datetime, value) => datetime.setWeekOfMonth(value),
364
+ },
365
+ weekYear: {
366
+ get: (datetime) => datetime.getWeekYear(),
367
+ set: (datetime, value) => datetime.setWeekYear(value),
368
+ },
369
+ year: {
370
+ get: (datetime) => {
371
+ const year = datetime.getYear();
372
+ return Math.abs(year);
373
+ },
374
+ set: (datetime, value) => datetime.setYear(value),
375
+ },
376
+ };
377
+ }
378
+ /**
379
+ * Set the number of milliseconds since the UNIX epoch (offset to timeZone).
380
+ * @param {DateTime} date The DateTime.
381
+ * @param {number} time The number of milliseconds since the UNIX epoch (offset to timeZone).
382
+ * @return {DateTime} The DateTime object.
383
+ */
384
+ function setOffsetTime(date, time) {
385
+ return date.setTime(time + (date.getTimeZoneOffset() * 60000));
386
+ }
387
+
388
+ /**
389
+ * DateFormatter Values
390
+ */
391
+
392
+ /**
393
+ * Get cached day period values.
394
+ * @param {string} locale The locale.
395
+ * @param {string} [type=long] The formatting type.
396
+ * @return {array} The cached values.
397
+ */
398
+ function getDayPeriods(locale, type = 'long') {
399
+ return getData(
400
+ `periods.${locale}.${type}`,
401
+ (_) => {
402
+ const dayPeriodFormatter = makeFormatter(locale, { hour: 'numeric', hourCycle: 'h11' });
403
+ return new Array(2)
404
+ .fill()
405
+ .map((_, index) =>
406
+ dayPeriodFormatter.formatToParts(Date.UTC(2018, 0, 1, index * 12))
407
+ .find((part) => part.type === 'dayPeriod')
408
+ .value,
409
+ );
410
+ },
411
+ );
412
+ }
413
+ /**
414
+ * Get cached day values.
415
+ * @param {string} locale The locale.
416
+ * @param {string} [type=long] The formatting type.
417
+ * @param {Boolean} [standalone=true] Whether the values are standalone.
418
+ * @return {array} The cached values.
419
+ */
420
+ function getDays(locale, type = 'long', standalone = true) {
421
+ return getData(
422
+ `days.${locale}.${type}.${standalone}`,
423
+ (_) => {
424
+ if (standalone) {
425
+ const dayFormatter = makeFormatter(locale, { weekday: type });
426
+ return new Array(7)
427
+ .fill()
428
+ .map((_, index) =>
429
+ dayFormatter.format(Date.UTC(2018, 0, index)),
430
+ );
431
+ }
432
+
433
+ const dayFormatter = makeFormatter(locale, { year: 'numeric', month: 'numeric', day: 'numeric', weekday: type });
434
+ return new Array(7)
435
+ .fill()
436
+ .map((_, index) =>
437
+ dayFormatter.formatToParts(Date.UTC(2018, 0, index))
438
+ .find((part) => part.type === 'weekday')
439
+ .value,
440
+ );
441
+ },
442
+ );
443
+ }
444
+ /**
445
+ * Get cached era values.
446
+ * @param {string} locale The locale.
447
+ * @param {string} [type=long] The formatting type.
448
+ * @return {array} The cached values.
449
+ */
450
+ function getEras(locale, type = 'long') {
451
+ return getData(
452
+ `eras.${locale}.${type}`,
453
+ (_) => {
454
+ const eraFormatter = makeFormatter(locale, { era: type });
455
+ return new Array(2)
456
+ .fill()
457
+ .map((_, index) =>
458
+ eraFormatter.formatToParts(Date.UTC(index - 1, 0, 1))
459
+ .find((part) => part.type === 'era')
460
+ .value,
461
+ );
462
+ },
463
+ );
464
+ }
465
+ /**
466
+ * Get cached month values.
467
+ * @param {string} locale The locale.
468
+ * @param {string} [type=long] The formatting type.
469
+ * @param {Boolean} [standalone=true] Whether the values are standalone.
470
+ * @return {array} The cached values.
471
+ */
472
+ function getMonths(locale, type = 'long', standalone = true) {
473
+ return getData(
474
+ `months.${locale}.${type}.${standalone}`,
475
+ (_) => {
476
+ if (standalone) {
477
+ const monthFormatter = makeFormatter(locale, { month: type });
478
+ return new Array(12)
479
+ .fill()
480
+ .map((_, index) =>
481
+ monthFormatter.format(Date.UTC(2018, index, 1)),
482
+ );
483
+ }
484
+
485
+ const monthFormatter = makeFormatter(locale, { year: 'numeric', month: type, day: 'numeric' });
486
+ return new Array(12)
487
+ .fill()
488
+ .map((_, index) =>
489
+ monthFormatter.formatToParts(Date.UTC(2018, index, 1))
490
+ .find((part) => part.type === 'month')
491
+ .value,
492
+ );
493
+ },
494
+ );
495
+ }
496
+ /**
497
+ * Get cached number values.
498
+ * @param {string} locale The locale.
499
+ * @return {array} The cached values.
500
+ */
501
+ function getNumbers(locale) {
502
+ return getData(
503
+ `numbers.${locale}`,
504
+ (_) => {
505
+ const numberFormatter = makeFormatter(locale, { minute: 'numeric' });
506
+ return new Array(10)
507
+ .fill()
508
+ .map((_, index) =>
509
+ numberFormatter.format(Date.UTC(2018, 0, 1, 0, index)),
510
+ );
511
+ },
512
+ );
513
+ }
514
+ /**
515
+ * Get the RegExp for the number values.
516
+ * @param {string} locale The locale.
517
+ * @return {string} The number values RegExp.
518
+ */
519
+ function numberRegExp(locale) {
520
+ const numbers = getNumbers(locale).join('|');
521
+ return `(?:${numbers})+`;
522
+ }
523
+
524
+ /**
525
+ * Format a day as a locale string.
526
+ * @param {string} locale The locale.
527
+ * @param {number} day The day to format (0-6).
528
+ * @param {string} [type=long] The formatting type.
529
+ * @param {Boolean} [standalone=true] Whether the value is standalone.
530
+ * @return {string} The formatted string.
531
+ */
532
+ function formatDay(locale, day, type = 'long', standalone = true) {
533
+ return getDays(locale, type, standalone)[day];
534
+ }
535
+ /**
536
+ * Format a day period as a locale string.
537
+ * @param {string} locale The locale.
538
+ * @param {number} period The period to format (0-1).
539
+ * @param {string} [type=long] The formatting type.
540
+ * @return {string} The formatted string.
541
+ */
542
+ function formatDayPeriod(locale, period, type = 'long') {
543
+ return getDayPeriods(locale, type)[period];
544
+ }
545
+ /**
546
+ * Format an era as a locale string.
547
+ * @param {string} locale The locale.
548
+ * @param {number} era The period to format (0-1).
549
+ * @param {string} [type=long] The formatting type.
550
+ * @return {string} The formatted string.
551
+ */
552
+ function formatEra(locale, era, type = 'long') {
553
+ return getEras(locale, type)[era];
554
+ }
555
+ /**
556
+ * Format a month as a locale string.
557
+ * @param {string} locale The locale.
558
+ * @param {number} month The month to format (1-12).
559
+ * @param {string} [type=long] The formatting type.
560
+ * @param {Boolean} [standalone=true] Whether the value is standalone.
561
+ * @return {string} The formatted string.
562
+ */
563
+ function formatMonth(locale, month, type = 'long', standalone = true) {
564
+ return getMonths(locale, type, standalone)[month - 1];
565
+ }
566
+ /**
567
+ * Format a number as a locale number string.
568
+ * @param {string} locale The locale.
569
+ * @param {number} number The number to format.
570
+ * @param {number} [padding=0] The amount of padding to use.
571
+ * @return {string} The formatted string.
572
+ */
573
+ function formatNumber(locale, number, padding = 0) {
574
+ const numbers = getNumbers(locale);
575
+ return `${number}`
576
+ .padStart(padding, 0)
577
+ .replace(/\d/g, (match) => numbers[match]);
578
+ }
579
+ /**
580
+ * Format a number to an offset string.
581
+ * @param {number} offset The offset to format.
582
+ * @param {Boolean} [useColon=true] Whether to use a colon seperator.
583
+ * @param {Boolean} [optionalMinutes=false] Whether minutes are optional.
584
+ * @return {string} The formatted offset string.
585
+ */
586
+ function formatOffset(offset, useColon = true, optionalMinutes = false) {
587
+ const hours = Math.abs(
588
+ (offset / 60) | 0,
589
+ );
590
+ const minutes = Math.abs(offset % 60);
591
+
592
+ const sign = offset > 0 ?
593
+ '-' :
594
+ '+';
595
+ const hourString = `${hours}`.padStart(2, 0);
596
+ const minuteString = minutes || !optionalMinutes ?
597
+ `${minutes}`.padStart(2, 0) :
598
+ '';
599
+ const colon = useColon && minuteString ?
600
+ ':' :
601
+ '';
602
+
603
+ return `${sign}${hourString}${colon}${minuteString}`;
604
+ }
605
+ /**
606
+ * Format a time zone as a locale string.
607
+ * @param {string} locale The locale.
608
+ * @param {number} timestamp The timestamp to use.
609
+ * @param {string} timeZone The time zone to format.
610
+ * @param {string} [type=long] The formatting type.
611
+ * @return {string} The formatted string.
612
+ */
613
+ function formatTimeZoneName(locale, timestamp, timeZone, type = 'long') {
614
+ return makeFormatter(locale, { second: 'numeric', timeZone, timeZoneName: type })
615
+ .formatToParts(timestamp)
616
+ .find((part) => part.type === 'timeZoneName')
617
+ .value;
618
+ }
619
+
620
+ /**
621
+ * DateTime class
622
+ * @class
623
+ */
624
+ class DateTime {
625
+ /**
626
+ * New DateTime constructor.
627
+ * @param {string|number|null} [date] The date or timestamp to parse.
628
+ * @param {object} [options] Options for the new DateTime.
629
+ * @param {string} [options.timeZone] The timeZone to use.
630
+ * @param {string} [options.locale] The locale to use.
631
+ */
632
+ constructor(date = null, options = {}) {
633
+ let timestamp;
634
+ let adjustOffset = false;
635
+
636
+ if (date === null) {
637
+ timestamp = Date.now();
638
+ } else if (!isNaN(parseInt(date)) && isFinite(date)) {
639
+ timestamp = date;
640
+ } else if (date === `${date}`) {
641
+ timestamp = Date.parse(date);
642
+
643
+ if (isNaN(timestamp)) {
644
+ throw new Error('Invalid date string supplied');
645
+ }
646
+
647
+ if (!date.match(dateStringTimeZoneRegExp)) {
648
+ timestamp -= new Date()
649
+ .getTimezoneOffset() *
650
+ 60000;
651
+ }
652
+
653
+ adjustOffset = true;
654
+ } else {
655
+ throw new Error('Invalid date supplied');
656
+ }
657
+
658
+ this._date = new Date(timestamp);
659
+ this._dynamicTz = false;
660
+ this.isValid = true;
661
+
662
+ let timeZone = options.timeZone;
663
+
664
+ if (!timeZone) {
665
+ timeZone = config.defaultTimeZone;
666
+ }
667
+
668
+ if (['Z', 'GMT'].includes(timeZone)) {
669
+ timeZone = 'UTC';
670
+ }
671
+
672
+ const match = timeZone.match(offsetRegExp);
673
+ if (match) {
674
+ this._offset = match[2] * 60 + parseInt(match[4] || 0);
675
+ if (this._offset && match[1] === '+') {
676
+ this._offset *= -1;
677
+ }
678
+
679
+ if (this._offset) {
680
+ this._timeZone = formatOffset(this._offset);
681
+ } else {
682
+ this._dynamicTz = true;
683
+ this._timeZone = 'UTC';
684
+ }
685
+ } else {
686
+ this._dynamicTz = true;
687
+ this._timeZone = timeZone;
688
+ }
689
+
690
+ if (this._dynamicTz) {
691
+ this._offset = getOffset(this);
692
+ }
693
+
694
+ if (adjustOffset && this._offset) {
695
+ const oldOffset = this._offset;
696
+
697
+ this._date.setTime(this.getTime() + this._offset * 60000);
698
+
699
+ if (this._dynamicTz) {
700
+ this._offset = getOffset(this);
701
+
702
+ // compensate for DST transitions
703
+ if (oldOffset !== this._offset) {
704
+ this._date.setTime(this.getTime() - ((oldOffset - offset) * 60000));
705
+ }
706
+ }
707
+ }
708
+
709
+ if (!('locale' in options)) {
710
+ options.locale = config.defaultLocale;
711
+ }
712
+
713
+ this._locale = options.locale;
714
+ }
715
+
716
+ /**
717
+ * Get the name of the current locale.
718
+ * @return {string} The name of the current locale.
719
+ */
720
+ getLocale() {
721
+ return this._locale;
722
+ }
723
+
724
+ /**
725
+ * Get the number of milliseconds since the UNIX epoch.
726
+ * @return {number} The number of milliseconds since the UNIX epoch.
727
+ */
728
+ getTime() {
729
+ return this._date.getTime();
730
+ }
731
+
732
+ /**
733
+ * Get the name of the current timeZone.
734
+ * @return {string} The name of the current timeZone.
735
+ */
736
+ getTimeZone() {
737
+ return this._timeZone;
738
+ }
739
+
740
+ /**
741
+ * Get the UTC offset (in minutes) of the current timeZone.
742
+ * @return {number} The UTC offset (in minutes) of the current timeZone.
743
+ */
744
+ getTimeZoneOffset() {
745
+ return this._offset;
746
+ }
747
+
748
+ /**
749
+ * Set the current locale.
750
+ * @param {string} locale The name of the timeZone.
751
+ * @return {DateTime} The DateTime object.
752
+ */
753
+ setLocale(locale) {
754
+ return new DateTime(this.getTime(), {
755
+ locale,
756
+ timeZone: this._timeZone,
757
+ });
758
+ }
759
+
760
+ /**
761
+ * Set the number of milliseconds since the UNIX epoch.
762
+ * @param {number} time The number of milliseconds since the UNIX epoch.
763
+ * @return {DateTime} The DateTime object.
764
+ */
765
+ setTime(time) {
766
+ return new DateTime(time, {
767
+ locale: this._locale,
768
+ timeZone: this._timeZone,
769
+ });
770
+ }
771
+
772
+ /**
773
+ * Set the current timeZone.
774
+ * @param {string} timeZone The name of the timeZone.
775
+ * @return {DateTime} The DateTime object.
776
+ */
777
+ setTimeZone(timeZone) {
778
+ return new DateTime(this.getTime(), {
779
+ locale: this._locale,
780
+ timeZone,
781
+ });
782
+ }
783
+
784
+ /**
785
+ * Set the current UTC offset.
786
+ * @param {number} offset The UTC offset (in minutes).
787
+ * @return {DateTime} The DateTime object.
788
+ */
789
+ setTimeZoneOffset(offset) {
790
+ return new DateTime(this.getTime(), {
791
+ locale: this._locale,
792
+ timeZone: formatOffset(offset),
793
+ });
794
+ }
795
+
796
+ /**
797
+ * Get the number of milliseconds since the UNIX epoch.
798
+ * @return {number} The number of milliseconds since the UNIX epoch.
799
+ */
800
+ valueOf() {
801
+ return this.getTime();
802
+ }
803
+
804
+ /**
805
+ * Return a primitive value of the DateTime.
806
+ * @param {string} hint The type hint.
807
+ * @return {string|number}
808
+ */
809
+ [Symbol.toPrimitive](hint) {
810
+ return hint === 'number' ?
811
+ this.valueOf() :
812
+ this.toString();
813
+ }
814
+ }
815
+
816
+ const weekStart = { '1': ['af', 'am', 'ar-il', 'ar-sa', 'ar-ye', 'as', 'bn', 'bo', 'brx', 'ccp', 'ceb', 'chr', 'dav', 'dz', 'ebu', 'en', 'fil', 'gu', 'guz', 'haw', 'he', 'hi', 'id', 'ii', 'ja', 'jv', 'kam', 'ki', 'kln', 'km', 'kn', 'ko', 'kok', 'ks', 'lkt', 'lo', 'luo', 'luy', 'mas', 'mer', 'mgh', 'ml', 'mr', 'mt', 'my', 'nd', 'ne', 'om', 'or', 'pa', 'ps-pk', 'pt', 'qu', 'saq', 'sd', 'seh', 'sn', 'ta', 'te', 'th', 'ti', 'ug', 'ur', 'xh', 'yue', 'zh', 'zu'], '7': ['ar', 'ckb', 'en-ae', 'en-sd', 'fa', 'kab', 'lrc', 'mzn', 'ps'] };
817
+ const minDaysInFirstWeek = { '4': ['ast', 'bg', 'br', 'ca', 'ce', 'cs', 'cy', 'da', 'de', 'dsb', 'el', 'en-at', 'en-be', 'en-ch', 'en-de', 'en-dk', 'en-fi', 'en-fj', 'en-gb', 'en-gg', 'en-gi', 'en-ie', 'en-im', 'en-je', 'en-nl', 'en-se', 'es', 'et', 'eu', 'fi', 'fo', 'fr', 'fur', 'fy', 'ga', 'gd', 'gl', 'gsw', 'gv', 'hsb', 'hu', 'is', 'it', 'ksh', 'kw', 'lb', 'lt', 'nb', 'nds', 'nl', 'nn', 'os-ru', 'pl', 'pt-ch', 'pt-lu', 'pt-pt', 'rm', 'ru', 'sah', 'se', 'sk', 'smn', 'sv', 'tt', 'wae'] };
818
+
819
+ /**
820
+ * Get the formatting type from the component token length.
821
+ * @param {number} length The component token length.
822
+ * @return {string} The formatting type.
823
+ */
824
+ function getType(length) {
825
+ switch (length) {
826
+ case 5:
827
+ return 'narrow';
828
+ case 4:
829
+ return 'long';
830
+ default:
831
+ return 'short';
832
+ }
833
+ }
834
+ /**
835
+ * Get the minimum days.
836
+ * @param {string} locale The locale.
837
+ * @return {number} The minimum days.
838
+ */
839
+ function minimumDays(locale) {
840
+ return getData(
841
+ `minimumDays.${locale}`,
842
+ (_) => {
843
+ let minDays = 1;
844
+ const localeTest = locale.toLowerCase().split('-');
845
+ while (minDays === 1 && localeTest.length) {
846
+ for (const days in minDaysInFirstWeek) {
847
+ if (!{}.hasOwnProperty.call(minDaysInFirstWeek, days)) {
848
+ continue;
849
+ }
850
+
851
+ const locales = minDaysInFirstWeek[days];
852
+
853
+ if (locales.includes(localeTest.join('-'))) {
854
+ minDays = parseInt(days);
855
+ break;
856
+ }
857
+ }
858
+
859
+ localeTest.pop();
860
+ }
861
+
862
+ return minDays;
863
+ },
864
+ );
865
+ }
866
+ /**
867
+ * Get the week start offset for a locale.
868
+ * @param {string} [locale] The locale to load.
869
+ * @return {number} The week start offset.
870
+ */
871
+ function weekStartOffset(locale) {
872
+ return getData(
873
+ `weekStartOffset.${locale}`,
874
+ (_) => {
875
+ let weekStarted;
876
+ const localeTest = locale.toLowerCase().split('-');
877
+ while (!weekStarted && localeTest.length) {
878
+ for (const start in weekStart) {
879
+ if (!{}.hasOwnProperty.call(weekStart, start)) {
880
+ continue;
881
+ }
882
+
883
+ const locales = weekStart[start];
884
+
885
+ if (locales.includes(localeTest.join('-'))) {
886
+ weekStarted = parseInt(start);
887
+ break;
888
+ }
889
+ }
890
+
891
+ localeTest.pop();
892
+ }
893
+
894
+ return weekStarted ?
895
+ weekStarted - 2 :
896
+ 0;
897
+ },
898
+ );
899
+ }
900
+ /**
901
+ * Convert a day of the week to a local format.
902
+ * @param {string} locale The locale.
903
+ * @param {number} day The day of the week.
904
+ * @return {number} The local day of the week.
905
+ */
906
+ function weekDay(locale, day) {
907
+ return (7 + parseInt(day) - weekStartOffset(locale)) % 7 || 7;
908
+ }
909
+
910
+ /**
911
+ * Parse a day from a locale string.
912
+ * @param {string} locale The locale.
913
+ * @param {string} value The value to parse.
914
+ * @param {string} [type=long] The formatting type.
915
+ * @param {Boolean} [standalone=true] Whether the value is standalone.
916
+ * @return {number} The day number (0-6).
917
+ */
918
+ function parseDay(locale, value, type = 'long', standalone = true) {
919
+ const day = getDays(locale, type, standalone).indexOf(value) || 7;
920
+ return weekDay(locale, day);
921
+ }
922
+ /**
923
+ * Parse a day period from a locale string.
924
+ * @param {string} locale The locale.
925
+ * @param {string} value The value to parse.
926
+ * @param {string} [type=long] The formatting type.
927
+ * @return {number} The day period (0-1).
928
+ */
929
+ function parseDayPeriod(locale, value, type = 'long') {
930
+ return getDayPeriods(locale, type).indexOf(value);
931
+ }
932
+ /**
933
+ * Parse an era from a locale string.
934
+ * @param {string} locale The locale.
935
+ * @param {string} value The value to parse.
936
+ * @param {string} [type=long] The formatting type.
937
+ * @return {number} The era (0-1).
938
+ */
939
+ function parseEra(locale, value, type = 'long') {
940
+ return getEras(locale, type).indexOf(value);
941
+ }
942
+ /**
943
+ * Parse a month from a locale string.
944
+ * @param {string} locale The locale.
945
+ * @param {string} value The value to parse.
946
+ * @param {string} [type=long] The formatting type.
947
+ * @param {Boolean} [standalone=true] Whether the value is standalone.
948
+ * @return {number} The month number (1-12).
949
+ */
950
+ function parseMonth(locale, value, type = 'long', standalone = true) {
951
+ return getMonths(locale, type, standalone).indexOf(value) + 1;
952
+ }
953
+ /**
954
+ * Parse a number from a locale number string.
955
+ * @param {string} locale The locale.
956
+ * @param {string} value The value to parse.
957
+ * @return {number} The parsed number.
958
+ */
959
+ function parseNumber(locale, value) {
960
+ const numbers = getNumbers(locale);
961
+ return parseInt(
962
+ `${value}`.replace(/./g, (match) => numbers.indexOf(match)),
963
+ );
964
+ }
965
+
966
+ /**
967
+ * DateFormatter Format Data
968
+ */
969
+
970
+ var tokens = {
971
+
972
+ /* ERA */
973
+
974
+ G: {
975
+ key: 'era',
976
+ maxLength: 5,
977
+ regex: (locale, length) => {
978
+ const type = getType(length);
979
+ return getEras(locale, type).join('|');
980
+ },
981
+ input: (locale, value, length) => {
982
+ const type = getType(length);
983
+ return parseEra(locale, value, type);
984
+ },
985
+ output: (datetime, length) => {
986
+ const type = getType(length);
987
+ return datetime.era(type);
988
+ },
989
+ },
990
+
991
+ /* YEAR */
992
+
993
+ // year
994
+ y: {
995
+ key: 'year',
996
+ regex: (locale) => numberRegExp(locale),
997
+ input: (locale, value, length) => {
998
+ value = parseNumber(locale, value);
999
+
1000
+ if (length !== 2 || `${value}`.length !== 2) {
1001
+ return value;
1002
+ }
1003
+
1004
+ return value > 40 ?
1005
+ 1900 + value :
1006
+ 2000 + value;
1007
+ },
1008
+ output: (datetime, length) => {
1009
+ let year = datetime.getYear();
1010
+ if (length === 2) {
1011
+ year = `${year}`.slice(-2);
1012
+ }
1013
+ return formatNumber(
1014
+ datetime.getLocale(),
1015
+ Math.abs(year),
1016
+ length,
1017
+ );
1018
+ },
1019
+ },
1020
+
1021
+ // week year
1022
+ Y: {
1023
+ key: 'weekYear',
1024
+ regex: (locale) => numberRegExp(locale),
1025
+ input: (locale, value, length) => {
1026
+ value = parseNumber(locale, value);
1027
+
1028
+ if (length !== 2 || `${value}`.length !== 2) {
1029
+ return value;
1030
+ }
1031
+
1032
+ return value > 40 ?
1033
+ 1900 + value :
1034
+ 2000 + value;
1035
+ },
1036
+ output: (datetime, length) => {
1037
+ let year = datetime.getWeekYear();
1038
+ if (length === 2) {
1039
+ year = `${year}`.slice(-2);
1040
+ }
1041
+ return formatNumber(
1042
+ datetime.getLocale(),
1043
+ Math.abs(year),
1044
+ length,
1045
+ );
1046
+ },
1047
+ },
1048
+
1049
+ /* QUARTER */
1050
+
1051
+ // quarter
1052
+ Q: {
1053
+ key: 'quarter',
1054
+ regex: (locale) => numberRegExp(locale),
1055
+ input: (locale, value) => parseNumber(locale, value),
1056
+ output: (datetime, length) =>
1057
+ formatNumber(
1058
+ datetime.getLocale(),
1059
+ datetime.getQuarter(),
1060
+ length,
1061
+ ),
1062
+ },
1063
+
1064
+ // quarter (standalone)
1065
+ q: {
1066
+ key: 'quarter',
1067
+ regex: (locale) => numberRegExp(locale),
1068
+ input: (locale, value) => parseNumber(locale, value),
1069
+ output: (datetime, length) =>
1070
+ formatNumber(
1071
+ datetime.getLocale(),
1072
+ datetime.getQuarter(),
1073
+ length,
1074
+ ),
1075
+ },
1076
+
1077
+ /* MONTH */
1078
+
1079
+ // month
1080
+ M: {
1081
+ key: 'month',
1082
+ regex: (locale, length) => {
1083
+ switch (length) {
1084
+ case 5:
1085
+ case 4:
1086
+ case 3:
1087
+ const type = getType(length);
1088
+ return getMonths(locale, type, false).join('|');
1089
+ default:
1090
+ return numberRegExp(locale);
1091
+ }
1092
+ },
1093
+ input: (locale, value, length) => {
1094
+ switch (length) {
1095
+ case 5:
1096
+ return null;
1097
+ case 4:
1098
+ case 3:
1099
+ const type = getType(length);
1100
+ return parseMonth(locale, value, type, false);
1101
+ default:
1102
+ return parseNumber(locale, value);
1103
+ }
1104
+ },
1105
+ output: (datetime, length) => {
1106
+ const locale = datetime.getLocale();
1107
+ const month = datetime.getMonth();
1108
+ switch (length) {
1109
+ case 5:
1110
+ case 4:
1111
+ case 3:
1112
+ const type = getType(length);
1113
+ return formatMonth(locale, month, type, false);
1114
+ default:
1115
+ return formatNumber(locale, month, length);
1116
+ }
1117
+ },
1118
+ },
1119
+
1120
+ // month (standalone)
1121
+ L: {
1122
+ key: 'month',
1123
+ regex: (locale, length) => {
1124
+ switch (length) {
1125
+ case 5:
1126
+ case 4:
1127
+ case 3:
1128
+ const type = getType(length);
1129
+ return getMonths(locale, type).join('|');
1130
+ default:
1131
+ return numberRegExp(locale);
1132
+ }
1133
+ },
1134
+ input: (locale, value, length) => {
1135
+ switch (length) {
1136
+ case 5:
1137
+ return null;
1138
+ case 4:
1139
+ case 3:
1140
+ const type = getType(length);
1141
+ return parseMonth(locale, value, type);
1142
+ default:
1143
+ return parseNumber(locale, value);
1144
+ }
1145
+ },
1146
+ output: (datetime, length) => {
1147
+ const locale = datetime.getLocale();
1148
+ const month = datetime.getMonth();
1149
+ switch (length) {
1150
+ case 5:
1151
+ case 4:
1152
+ case 3:
1153
+ const type = getType(length);
1154
+ return formatMonth(locale, month, type);
1155
+ default:
1156
+ return formatNumber(locale, month, length);
1157
+ }
1158
+ },
1159
+ },
1160
+
1161
+ /* WEEK */
1162
+
1163
+ // local week
1164
+ w: {
1165
+ key: 'week',
1166
+ regex: (locale) => numberRegExp(locale),
1167
+ input: (locale, value) => parseNumber(locale, value),
1168
+ output: (datetime, length) =>
1169
+ formatNumber(
1170
+ datetime.getLocale(),
1171
+ datetime.getWeek(),
1172
+ length,
1173
+ ),
1174
+ },
1175
+
1176
+ // local week of month
1177
+ W: {
1178
+ key: 'weekOfMonth',
1179
+ regex: (locale) => numberRegExp(locale),
1180
+ input: (locale, value) => parseNumber(locale, value),
1181
+ output: (datetime) =>
1182
+ formatNumber(
1183
+ datetime.getLocale(),
1184
+ datetime.getWeekOfMonth(),
1185
+ ),
1186
+ },
1187
+
1188
+ /* DAY */
1189
+
1190
+ // day of month
1191
+ d: {
1192
+ key: 'date',
1193
+ regex: (locale) => numberRegExp(locale),
1194
+ input: (locale, value) => parseNumber(locale, value),
1195
+ output: (datetime, length) =>
1196
+ formatNumber(
1197
+ datetime.getLocale(),
1198
+ datetime.getDate(),
1199
+ length,
1200
+ ),
1201
+ },
1202
+
1203
+ // day of year
1204
+ D: {
1205
+ key: 'dayOfYear',
1206
+ regex: (locale) => numberRegExp(locale),
1207
+ input: (locale, value) => parseNumber(locale, value),
1208
+ output: (datetime, length) =>
1209
+ formatNumber(
1210
+ datetime.getLocale(),
1211
+ datetime.getDayOfYear(),
1212
+ length,
1213
+ ),
1214
+ },
1215
+
1216
+ // day of week in month
1217
+ F: {
1218
+ key: 'weekDayInMonth',
1219
+ regex: (locale) => numberRegExp(locale),
1220
+ input: (locale, value) => parseNumber(locale, value),
1221
+ output: (datetime) =>
1222
+ formatNumber(
1223
+ datetime.getLocale(),
1224
+ datetime.getWeekDayInMonth(),
1225
+ ),
1226
+ },
1227
+
1228
+ // week day name
1229
+ E: {
1230
+ key: 'weekDay',
1231
+ regex: (locale, length) => {
1232
+ const type = getType(length);
1233
+ return getDays(locale, type, false).join('|');
1234
+ },
1235
+ input: (locale, value, length) => {
1236
+ if (length === 5) {
1237
+ return null;
1238
+ }
1239
+
1240
+ const type = getType(length);
1241
+ return parseDay(locale, value, type, false);
1242
+ },
1243
+ output: (datetime, length) => {
1244
+ const type = getType(length);
1245
+ const locale = datetime.getLocale();
1246
+ const day = datetime.getDay();
1247
+ return formatDay(locale, day, type, false);
1248
+ },
1249
+ },
1250
+
1251
+ // week day
1252
+ e: {
1253
+ key: 'weekDay',
1254
+ maxLength: 5,
1255
+ regex: (locale, length) => {
1256
+ switch (length) {
1257
+ case 5:
1258
+ case 4:
1259
+ case 3:
1260
+ const type = getType(length);
1261
+ return getDays(locale, type, false).join('|');
1262
+ default:
1263
+ return numberRegExp(locale);
1264
+ }
1265
+ },
1266
+ input: (locale, value, length) => {
1267
+ switch (length) {
1268
+ case 5:
1269
+ return null;
1270
+ case 4:
1271
+ case 3:
1272
+ const type = getType(length);
1273
+ return parseDay(locale, value, type, false);
1274
+ default:
1275
+ return parseNumber(locale, value);
1276
+ }
1277
+ },
1278
+ output: (datetime, length) => {
1279
+ const locale = datetime.getLocale();
1280
+ switch (length) {
1281
+ case 5:
1282
+ case 4:
1283
+ case 3:
1284
+ const type = getType(length);
1285
+ const day = datetime.getDay();
1286
+ return formatDay(locale, day, type, false);
1287
+ default:
1288
+ const weekDay = datetime.getWeekDay();
1289
+ return formatNumber(locale, weekDay, length);
1290
+ }
1291
+ },
1292
+ },
1293
+
1294
+ // week day (standalone)
1295
+ c: {
1296
+ key: 'weekDay',
1297
+ maxLength: 5,
1298
+ regex: (locale, length) => {
1299
+ switch (length) {
1300
+ case 5:
1301
+ case 4:
1302
+ case 3:
1303
+ const type = getType(length);
1304
+ return getDays(locale, type).join('|');
1305
+ default:
1306
+ return numberRegExp(locale);
1307
+ }
1308
+ },
1309
+ input: (locale, value, length) => {
1310
+ switch (length) {
1311
+ case 5:
1312
+ return null;
1313
+ case 4:
1314
+ case 3:
1315
+ const type = getType(length);
1316
+ return parseDay(locale, value, type);
1317
+ default:
1318
+ return parseNumber(locale, value);
1319
+ }
1320
+ },
1321
+ output: (datetime, length) => {
1322
+ const locale = datetime.getLocale();
1323
+ switch (length) {
1324
+ case 5:
1325
+ case 4:
1326
+ case 3:
1327
+ const type = getType(length);
1328
+ const day = datetime.getDay();
1329
+ return formatDay(locale, day, type);
1330
+ default:
1331
+ const weekDay = datetime.getWeekDay();
1332
+ return formatNumber(locale, weekDay);
1333
+ }
1334
+ },
1335
+ },
1336
+
1337
+ /* PERIOD */
1338
+
1339
+ a: {
1340
+ key: 'dayPeriod',
1341
+ regex: (locale, length) => {
1342
+ const type = getType(length);
1343
+ return getDayPeriods(locale, type).join('|');
1344
+ },
1345
+ input: (locale, value, length) => {
1346
+ const type = getType(length);
1347
+ return parseDayPeriod(locale, value, type);
1348
+ },
1349
+ output: (datetime, length) => {
1350
+ const type = getType(length);
1351
+ return datetime.dayPeriod(type);
1352
+ },
1353
+ },
1354
+
1355
+ /* HOUR */
1356
+
1357
+ h: {
1358
+ key: 'hours12',
1359
+ regex: (locale) => numberRegExp(locale),
1360
+ input: (locale, value) => {
1361
+ value = parseNumber(locale, value);
1362
+ if (value === 12) {
1363
+ value = 0;
1364
+ }
1365
+ return value;
1366
+ },
1367
+ output: (datetime, length) =>
1368
+ formatNumber(
1369
+ datetime.getLocale(),
1370
+ datetime.getHours() % 12 || 12,
1371
+ length,
1372
+ ),
1373
+ },
1374
+
1375
+ H: {
1376
+ key: 'hours24',
1377
+ regex: (locale) => numberRegExp(locale),
1378
+ input: (locale, value) => parseNumber(locale, value),
1379
+ output: (datetime, length) =>
1380
+ formatNumber(
1381
+ datetime.getLocale(),
1382
+ datetime.getHours(),
1383
+ length,
1384
+ ),
1385
+ },
1386
+
1387
+ K: {
1388
+ key: 'hours12',
1389
+ regex: (locale) => numberRegExp(locale),
1390
+ input: (locale, value) => parseNumber(locale, value),
1391
+ output: (datetime, length) =>
1392
+ formatNumber(
1393
+ datetime.getLocale(),
1394
+ datetime.getHours() % 12,
1395
+ length,
1396
+ ),
1397
+ },
1398
+
1399
+ k: {
1400
+ key: 'hours24',
1401
+ regex: (locale) => numberRegExp(locale),
1402
+ input: (locale, value) => {
1403
+ value = parseNumber(locale, value);
1404
+ if (value === 24) {
1405
+ value = 0;
1406
+ }
1407
+ return value;
1408
+ },
1409
+ output: (datetime, length) =>
1410
+ formatNumber(
1411
+ datetime.getLocale(),
1412
+ datetime.getHours() || 24,
1413
+ length,
1414
+ ),
1415
+ },
1416
+
1417
+ /* MINUTE */
1418
+
1419
+ m: {
1420
+ key: 'minutes',
1421
+ regex: (locale) => numberRegExp(locale),
1422
+ input: (locale, value) => parseNumber(locale, value),
1423
+ output: (datetime, length) =>
1424
+ formatNumber(
1425
+ datetime.getLocale(),
1426
+ datetime.getMinutes(),
1427
+ length,
1428
+ ),
1429
+ },
1430
+
1431
+ /* SECOND */
1432
+
1433
+ s: {
1434
+ key: 'seconds',
1435
+ regex: (locale) => numberRegExp(locale),
1436
+ input: (locale, value) => parseNumber(locale, value),
1437
+ output: (datetime, length) =>
1438
+ formatNumber(
1439
+ datetime.getLocale(),
1440
+ datetime.getSeconds(),
1441
+ length,
1442
+ ),
1443
+ },
1444
+
1445
+ /* FRACTIONAL */
1446
+
1447
+ S: {
1448
+ key: 'milliseconds',
1449
+ regex: (locale) => numberRegExp(locale),
1450
+ input: (_) => 0,
1451
+ output: (datetime, length) =>
1452
+ formatNumber(
1453
+ datetime.getLocale(),
1454
+ `${Math.floor(
1455
+ datetime.getMilliseconds() *
1456
+ 1000,
1457
+ )}`.padEnd(length, '0').slice(0, length),
1458
+ ),
1459
+ },
1460
+
1461
+ /* TIMEZONE/OFFSET */
1462
+
1463
+ z: {
1464
+ output: (datetime, length) => {
1465
+ if (length === 5) {
1466
+ length = 1;
1467
+ }
1468
+ const type = getType(length);
1469
+ return datetime.timeZoneName(type);
1470
+ },
1471
+ },
1472
+
1473
+ Z: {
1474
+ key: 'timeZone',
1475
+ regex: (_, length) => {
1476
+ switch (length) {
1477
+ case 5:
1478
+ return `[\\+\\-]\\d{2}\\:\\d{2}|Z`;
1479
+ case 4:
1480
+ return `GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT`;
1481
+ default:
1482
+ return `[\\+\\-]\\d{4}`;
1483
+ }
1484
+ },
1485
+ input: (_, value) => value,
1486
+ output: (datetime, length) => {
1487
+ const offset = datetime.getTimeZoneOffset();
1488
+
1489
+ let useColon = true;
1490
+ let prefix = '';
1491
+ switch (length) {
1492
+ case 5:
1493
+ if (!offset) {
1494
+ return 'Z';
1495
+ }
1496
+ break;
1497
+ case 4:
1498
+ prefix = 'GMT';
1499
+
1500
+ if (!offset) {
1501
+ return prefix;
1502
+ }
1503
+
1504
+ break;
1505
+ default:
1506
+ useColon = false;
1507
+ break;
1508
+ }
1509
+
1510
+ return prefix + formatOffset(offset, useColon);
1511
+ },
1512
+ },
1513
+
1514
+ O: {
1515
+ key: 'timeZone',
1516
+ regex: (_, length) => {
1517
+ switch (length) {
1518
+ case 4:
1519
+ return `GMT[\\+\\-]\\d{2}\\:\\d{2}|GMT`;
1520
+ default:
1521
+ return `GMT[\\+\\-]\\d{2}|GMT`;
1522
+ }
1523
+ },
1524
+ input: (_, value) => value,
1525
+ output: (datetime, length) => {
1526
+ const offset = datetime.getTimeZoneOffset();
1527
+ const prefix = 'GMT';
1528
+
1529
+ if (!offset) {
1530
+ return prefix;
1531
+ }
1532
+
1533
+ let optionalMinutes = false;
1534
+ switch (length) {
1535
+ case 4:
1536
+ break;
1537
+ default:
1538
+ optionalMinutes = true;
1539
+ }
1540
+
1541
+ return prefix + formatOffset(offset, true, optionalMinutes);
1542
+ },
1543
+ },
1544
+
1545
+ V: {
1546
+ key: 'timeZone',
1547
+ regex: (_) => '([a-zA-Z_\/]+)',
1548
+ input: (_, value) => value,
1549
+ output: (datetime) => datetime.getTimeZone(),
1550
+ },
1551
+
1552
+ X: {
1553
+ key: 'timeZone',
1554
+ regex: (_, length) => {
1555
+ switch (length) {
1556
+ case 5:
1557
+ case 3:
1558
+ return `[\\+\\-]\\d{2}\\:\\d{2}|Z`;
1559
+ case 4:
1560
+ case 2:
1561
+ return `[\\+\\-]\\d{4}|Z`;
1562
+ default:
1563
+ return `[\\+\\-]\\d{2}(?:\\d{2})?|Z`;
1564
+ }
1565
+ },
1566
+ input: (_, value) => value,
1567
+ output: (datetime, length) => {
1568
+ const offset = datetime.getTimeZoneOffset();
1569
+
1570
+ if (!offset) {
1571
+ return 'Z';
1572
+ }
1573
+
1574
+ let useColon;
1575
+ switch (length) {
1576
+ case 5:
1577
+ case 3:
1578
+ useColon = true;
1579
+ break;
1580
+ default:
1581
+ useColon = false;
1582
+ break;
1583
+ }
1584
+
1585
+ return formatOffset(offset, useColon, length === 1);
1586
+ },
1587
+ },
1588
+
1589
+ x: {
1590
+ key: 'timeZone',
1591
+ regex: (_, length) => {
1592
+ switch (length) {
1593
+ case 5:
1594
+ case 3:
1595
+ return `[\\+\\-]\\d{2}\\:\\d{2}`;
1596
+ case 4:
1597
+ case 2:
1598
+ return `[\\+\\-]\\d{4}`;
1599
+ default:
1600
+ return `[\\+\\-]\\d{2}(?:\\d{2})?`;
1601
+ }
1602
+ },
1603
+ input: (_, value) => value,
1604
+ output: (datetime, length) => {
1605
+ let useColon;
1606
+ switch (length) {
1607
+ case 5:
1608
+ case 3:
1609
+ useColon = true;
1610
+ break;
1611
+ default:
1612
+ useColon = false;
1613
+ break;
1614
+ }
1615
+
1616
+ return formatOffset(datetime.getTimeZoneOffset(), useColon, length === 1);
1617
+ },
1618
+ },
1619
+
1620
+ };
1621
+
1622
+ /**
1623
+ * DateTime (Static) Creation
1624
+ */
1625
+
1626
+ /**
1627
+ * Create a new DateTime from an array.
1628
+ * @param {number[]} dateArray The date to parse.
1629
+ * @param {object} [options] Options for the new DateTime.
1630
+ * @param {string} [options.timeZone] The timeZone to use.
1631
+ * @param {string} [options.locale] The locale to use.
1632
+ * @return {DateTime} A new DateTime object.
1633
+ */
1634
+ function fromArray(dateArray, options = {}) {
1635
+ const dateValues = dateArray.slice(0, 3);
1636
+ const timeValues = dateArray.slice(3);
1637
+
1638
+ if (dateValues.length < 3) {
1639
+ dateValues.push(...new Array(3 - dateValues.length).fill(1));
1640
+ }
1641
+
1642
+ if (timeValues.length < 4) {
1643
+ timeValues.push(...new Array(4 - timeValues.length).fill(0));
1644
+ }
1645
+
1646
+ return new DateTime(null, options)
1647
+ .setTimestamp(0)
1648
+ .setYear(...dateValues)
1649
+ .setHours(...timeValues);
1650
+ }
1651
+ /**
1652
+ * Create a new DateTime from a Date.
1653
+ * @param {Date} date The date.
1654
+ * @param {object} [options] Options for the new DateTime.
1655
+ * @param {string} [options.timeZone] The timeZone to use.
1656
+ * @param {string} [options.locale] The locale to use.
1657
+ * @return {DateTime} A new DateTime object.
1658
+ */
1659
+ function fromDate(date, options = {}) {
1660
+ return new DateTime(date.getTime(), options);
1661
+ }
1662
+ /**
1663
+ * Create a new DateTime from a format string.
1664
+ * @param {string} formatString The format string.
1665
+ * @param {string} dateString The date string.
1666
+ * @param {object} [options] Options for the new DateTime.
1667
+ * @param {string} [options.timeZone] The timeZone to use.
1668
+ * @param {string} [options.locale] The locale to use.
1669
+ * @return {DateTime} A new DateTime object.
1670
+ */
1671
+ function fromFormat(formatString, dateString, options = {}) {
1672
+ if (!('locale' in options)) {
1673
+ options.locale = config.defaultLocale;
1674
+ }
1675
+
1676
+ const values = [];
1677
+
1678
+ let match;
1679
+ while (formatString && (match = formatString.match(formatTokenRegExp))) {
1680
+ const token = match[1];
1681
+ const position = match.index;
1682
+ const length = match[0].length;
1683
+
1684
+ if (position) {
1685
+ const formatTest = formatString.substring(0, position);
1686
+ parseCompare(formatTest, dateString);
1687
+ }
1688
+
1689
+ formatString = formatString.substring(position + length);
1690
+ dateString = dateString.substring(position);
1691
+
1692
+ if (!token) {
1693
+ const literal = match[0].slice(1, -1);
1694
+ parseCompare(literal || `'`, dateString);
1695
+ dateString = dateString.substring(literal.length);
1696
+ continue;
1697
+ }
1698
+
1699
+ if (!(token in tokens)) {
1700
+ throw new Error(`Invalid token in DateTime format: ${token}`);
1701
+ }
1702
+
1703
+ const regExp = tokens[token].regex(options.locale, length);
1704
+ const matchedValue = dateString.match(new RegExp(`^${regExp}`));
1705
+
1706
+ if (!matchedValue) {
1707
+ throw new Error(`Unmatched token in DateTime string: ${token}`);
1708
+ }
1709
+
1710
+ const literal = matchedValue[0];
1711
+ const value = tokens[token].input(options.locale, literal, length);
1712
+
1713
+ if (value !== null) {
1714
+ const key = tokens[token].key;
1715
+ values.push({ key, value, literal, token, length });
1716
+ }
1717
+
1718
+ dateString = dateString.substring(literal.length);
1719
+ }
1720
+
1721
+ if (formatString) {
1722
+ parseCompare(formatString, dateString);
1723
+ }
1724
+
1725
+ if (!('timeZone' in options)) {
1726
+ options.timeZone = config.defaultTimeZone;
1727
+ }
1728
+
1729
+ let timeZone = options.timeZone;
1730
+ for (const { key, value } of values) {
1731
+ if (key !== 'timeZone') {
1732
+ continue;
1733
+ }
1734
+
1735
+ timeZone = value;
1736
+ }
1737
+
1738
+ let datetime = this.fromTimestamp(0, {
1739
+ locale: options.locale,
1740
+ }).setYear(1).setTimeZone(timeZone);
1741
+
1742
+ const methods = parseFactory();
1743
+
1744
+ const testValues = [];
1745
+
1746
+ for (const subKeys of parseOrderKeys) {
1747
+ for (const subKey of subKeys) {
1748
+ if (subKey === 'era' && !values.find((data) => data.key === 'year')) {
1749
+ continue;
1750
+ }
1751
+
1752
+ for (const data of values) {
1753
+ const { key, value, literal, token, length } = data;
1754
+
1755
+ if (key !== subKey) {
1756
+ continue;
1757
+ }
1758
+
1759
+ // skip narrow month and day names if output already matches
1760
+ if (length === 5 && ['M', 'L', 'E', 'e', 'c'].includes(token)) {
1761
+ const fullToken = token.repeat(length);
1762
+ if (datetime.format(fullToken) === literal) {
1763
+ continue;
1764
+ }
1765
+ }
1766
+
1767
+ datetime = methods[key].set(datetime, value);
1768
+ testValues.push(data);
1769
+ }
1770
+ }
1771
+ }
1772
+
1773
+ let isValid = true;
1774
+ for (const { key, value } of testValues) {
1775
+ if (key in methods && methods[key].get(datetime) !== value) {
1776
+ isValid = false;
1777
+ break;
1778
+ }
1779
+ }
1780
+
1781
+ if (options.timeZone !== timeZone) {
1782
+ datetime = datetime.setTimeZone(options.timeZone);
1783
+ }
1784
+
1785
+ datetime.isValid = isValid;
1786
+
1787
+ return datetime;
1788
+ }
1789
+ /**
1790
+ * Create a new DateTime from an ISO format string.
1791
+ * @param {string} dateString The date string.
1792
+ * @param {object} [options] Options for the new DateTime.
1793
+ * @param {string} [options.timeZone] The timeZone to use.
1794
+ * @param {string} [options.locale] The locale to use.
1795
+ * @return {DateTime} A new DateTime object.
1796
+ */
1797
+ function fromISOString(dateString, options = {}) {
1798
+ let date = this.fromFormat(formats.rfc3339_extended, dateString, {
1799
+ locale: 'en',
1800
+ });
1801
+
1802
+ if ('timeZone' in options) {
1803
+ date = date.setTimeZone(options.timeZone);
1804
+ }
1805
+
1806
+ if ('locale' in options) {
1807
+ date = date.setLocale(options.locale);
1808
+ }
1809
+
1810
+ return date;
1811
+ }
1812
+ /**
1813
+ * Create a new DateTime from a timestamp.
1814
+ * @param {number} timestamp The timestamp.
1815
+ * @param {object} [options] Options for the new DateTime.
1816
+ * @param {string} [options.timeZone] The timeZone to use.
1817
+ * @param {string} [options.locale] The locale to use.
1818
+ * @return {DateTime} A new DateTime object.
1819
+ */
1820
+ function fromTimestamp(timestamp, options = {}) {
1821
+ return new DateTime(null, options)
1822
+ .setTimestamp(timestamp);
1823
+ }
1824
+ /**
1825
+ * Create a new DateTime for the current time.
1826
+ * @param {object} [options] Options for the new DateTime.
1827
+ * @param {string} [options.timeZone] The timeZone to use.
1828
+ * @param {string} [options.locale] The locale to use.
1829
+ * @return {DateTime} A new DateTime object.
1830
+ */
1831
+ function now(options = {}) {
1832
+ return new DateTime(null, options);
1833
+ }
1834
+
1835
+ /**
1836
+ * DateTime (Static) Utility
1837
+ */
1838
+
1839
+ /**
1840
+ * Get the day of the year for a year, month and date.
1841
+ * @param {number} year The year.
1842
+ * @param {number} month The month. (1, 12)
1843
+ * @param {number} date The date.
1844
+ * @return {number} The day of the year. (1, 366)
1845
+ */
1846
+ function dayOfYear(year, month, date) {
1847
+ return new Array(month - 1)
1848
+ .fill()
1849
+ .reduce(
1850
+ (d, _, i) =>
1851
+ d + daysInMonth$1(year, i + 1),
1852
+ date,
1853
+ );
1854
+ }
1855
+ /**
1856
+ * Get the number of days in a month, from a year and month.
1857
+ * @param {number} year The year.
1858
+ * @param {number} month The month. (1, 12)
1859
+ * @return {number} The number of days in the month.
1860
+ */
1861
+ function daysInMonth$1(year, month) {
1862
+ const date = new Date(Date.UTC(year, month - 1));
1863
+ month = date.getUTCMonth();
1864
+
1865
+ return monthDays[month] +
1866
+ (
1867
+ month == 1 && isLeapYear$1(
1868
+ date.getUTCFullYear(),
1869
+ ) ?
1870
+ 1 :
1871
+ 0
1872
+ );
1873
+ }
1874
+ /**
1875
+ * Get the number of days in a year.
1876
+ * @param {number} year The year.
1877
+ * @return {number} The number of days in the year.
1878
+ */
1879
+ function daysInYear$1(year) {
1880
+ return !isLeapYear$1(year) ?
1881
+ 365 :
1882
+ 366;
1883
+ }
1884
+ /**
1885
+ * Get the default locale.
1886
+ * @return {string} The locale.
1887
+ */
1888
+ function getDefaultLocale() {
1889
+ return config.defaultLocale;
1890
+ }
1891
+ /**
1892
+ * Get the default timeZone.
1893
+ * @return {string} The name of the timeZone.
1894
+ */
1895
+ function getDefaultTimeZone() {
1896
+ return config.defaultTimeZone;
1897
+ }
1898
+ /**
1899
+ * Return true if a year is a leap year.
1900
+ * @param {number} year The year.
1901
+ * @return {Boolean} TRUE if the year is a leap year, otherwise FALSE.
1902
+ */
1903
+ function isLeapYear$1(year) {
1904
+ return new Date(year, 1, 29)
1905
+ .getDate() === 29;
1906
+ }
1907
+ /**
1908
+ * Set whether dates will be clamped when changing months.
1909
+ * @param {Boolean} clampDates Whether to clamp dates.
1910
+ */
1911
+ function setDateClamping(clampDates) {
1912
+ config.clampDates = clampDates;
1913
+ }
1914
+ /**
1915
+ * Set the default locale.
1916
+ * @param {string} locale The locale.
1917
+ */
1918
+ function setDefaultLocale(locale) {
1919
+ config.defaultLocale = locale;
1920
+ }
1921
+ /**
1922
+ * Set the default timeZone.
1923
+ * @param {string} timeZone The name of the timeZone.
1924
+ */
1925
+ function setDefaultTimeZone(timeZone) {
1926
+ config.defaultTimeZone = timeZone;
1927
+ }
1928
+
1929
+ /**
1930
+ * DateTime Attributes (Get)
1931
+ */
1932
+
1933
+ /**
1934
+ * Get the date of the month in current timeZone.
1935
+ * @return {number} The date of the month.
1936
+ */
1937
+ function getDate() {
1938
+ return new Date(getOffsetTime(this)).getUTCDate();
1939
+ }
1940
+ /**
1941
+ * Get the day of the week in current timeZone.
1942
+ * @return {number} The day of the week. (0 - Sunday, 6 - Saturday)
1943
+ */
1944
+ function getDay() {
1945
+ return new Date(getOffsetTime(this)).getUTCDay();
1946
+ }
1947
+ /**
1948
+ * Get the day of the year in current timeZone.
1949
+ * @return {number} The day of the year. (1, 366)
1950
+ */
1951
+ function getDayOfYear() {
1952
+ return dayOfYear(
1953
+ this.getYear(),
1954
+ this.getMonth(),
1955
+ this.getDate(),
1956
+ );
1957
+ }
1958
+ /**
1959
+ * Get the hours of the day in current timeZone.
1960
+ * @return {number} The hours of the day. (0, 23)
1961
+ */
1962
+ function getHours() {
1963
+ return new Date(getOffsetTime(this)).getUTCHours();
1964
+ }
1965
+ /**
1966
+ * Get the milliseconds in current timeZone.
1967
+ * @return {number} The milliseconds.
1968
+ */
1969
+ function getMilliseconds() {
1970
+ return new Date(getOffsetTime(this)).getUTCMilliseconds();
1971
+ }
1972
+ /**
1973
+ * Get the minutes in current timeZone.
1974
+ * @return {number} The minutes. (0, 59)
1975
+ */
1976
+ function getMinutes() {
1977
+ return new Date(getOffsetTime(this)).getUTCMinutes();
1978
+ }
1979
+ /**
1980
+ * Get the month in current timeZone.
1981
+ * @return {number} The month. (1, 12)
1982
+ */
1983
+ function getMonth() {
1984
+ return new Date(getOffsetTime(this)).getUTCMonth() + 1;
1985
+ }
1986
+ /**
1987
+ * Get the quarter of the year in current timeZone.
1988
+ * @return {number} The quarter of the year. (1, 4)
1989
+ */
1990
+ function getQuarter() {
1991
+ return Math.ceil(this.getMonth() / 3);
1992
+ }
1993
+ /**
1994
+ * Get the seconds in current timeZone.
1995
+ * @return {number} The seconds. (0, 59)
1996
+ */
1997
+ function getSeconds() {
1998
+ return new Date(getOffsetTime(this)).getUTCSeconds();
1999
+ }
2000
+ /**
2001
+ * Get the number of seconds since the UNIX epoch.
2002
+ * @return {number} The number of seconds since the UNIX epoch.
2003
+ */
2004
+ function getTimestamp() {
2005
+ return Math.floor(this.getTime() / 1000);
2006
+ }
2007
+ /**
2008
+ * Get the local week in current timeZone.
2009
+ * @return {number} The local week. (1, 53)
2010
+ */
2011
+ function getWeek() {
2012
+ const thisWeek = this.startOf('day').setWeekDay(1);
2013
+ const firstWeek = thisWeek.setWeek(1, 1);
2014
+
2015
+ return 1 +
2016
+ (
2017
+ (
2018
+ (thisWeek - firstWeek) /
2019
+ 604800000
2020
+ ) | 0
2021
+ );
2022
+ }
2023
+ /**
2024
+ * Get the local day of the week in current timeZone.
2025
+ * @return {number} The local day of the week. (1 - 7)
2026
+ */
2027
+ function getWeekDay() {
2028
+ return weekDay(
2029
+ this.getLocale(),
2030
+ this.getDay(),
2031
+ );
2032
+ }
2033
+ /**
2034
+ * Get the week day in month in current timeZone.
2035
+ * @return {number} The week day in month.
2036
+ */
2037
+ function getWeekDayInMonth() {
2038
+ const thisWeek = this.getWeek();
2039
+ const first = this.setDate(1);
2040
+ const firstWeek = first.getWeek();
2041
+ const offset = first.getWeekDay() > this.getWeekDay() ?
2042
+ 0 : 1;
2043
+ return firstWeek > thisWeek ?
2044
+ thisWeek + offset :
2045
+ thisWeek - firstWeek + offset;
2046
+ }
2047
+ /**
2048
+ * Get the week of month in current timeZone.
2049
+ * @return {number} The week of month.
2050
+ */
2051
+ function getWeekOfMonth() {
2052
+ const thisWeek = this.getWeek();
2053
+ const firstWeek = this.setDate(1).getWeek();
2054
+ return firstWeek > thisWeek ?
2055
+ thisWeek + 1 :
2056
+ thisWeek - firstWeek + 1;
2057
+ }
2058
+ /**
2059
+ * Get the week year in current timeZone.
2060
+ * @return {number} The week year.
2061
+ */
2062
+ function getWeekYear() {
2063
+ const minDays = minimumDays(this.getLocale());
2064
+ return this.setWeekDay(7 - minDays + 1).getYear();
2065
+ }
2066
+ /**
2067
+ * Get the year in current timeZone.
2068
+ * @return {number} The year.
2069
+ */
2070
+ function getYear() {
2071
+ return new Date(getOffsetTime(this)).getUTCFullYear();
2072
+ }
2073
+
2074
+ /**
2075
+ * DateTime Attributes (Set)
2076
+ */
2077
+
2078
+ /**
2079
+ * Set the date of the month in current timeZone.
2080
+ * @param {number} date The date of the month.
2081
+ * @return {DateTime} The DateTime object.
2082
+ */
2083
+ function setDate(date) {
2084
+ return setOffsetTime(
2085
+ this,
2086
+ new Date(getOffsetTime(this)).setUTCDate(date),
2087
+ );
2088
+ }
2089
+ /**
2090
+ * Set the day of the week in current timeZone.
2091
+ * @param {number} day The day of the week. (0 - Sunday, 6 - Saturday)
2092
+ * @return {DateTime} The DateTime object.
2093
+ */
2094
+ function setDay(day) {
2095
+ return setOffsetTime(
2096
+ this,
2097
+ new Date(getOffsetTime(this)).setUTCDate(
2098
+ this.getDate() -
2099
+ this.getDay() +
2100
+ parseInt(day),
2101
+ ),
2102
+ );
2103
+ }
2104
+ /**
2105
+ * Set the day of the year in current timeZone.
2106
+ * @param {number} day The day of the year. (1, 366)
2107
+ * @return {DateTime} The DateTime object.
2108
+ */
2109
+ function setDayOfYear(day) {
2110
+ return setOffsetTime(
2111
+ this,
2112
+ new Date(getOffsetTime(this)).setUTCMonth(
2113
+ 0,
2114
+ day,
2115
+ ),
2116
+ );
2117
+ }
2118
+ /**
2119
+ * Set the hours in current timeZone (and optionally, minutes, seconds and milliseconds).
2120
+ * @param {number} hours The hours. (0, 23)
2121
+ * @param {number} [minutes] The minutes. (0, 59)
2122
+ * @param {number} [seconds] The seconds. (0, 59)
2123
+ * @param {number} [milliseconds] The milliseconds.
2124
+ * @return {DateTime} The DateTime object.
2125
+ */
2126
+ function setHours(...args) {
2127
+ return setOffsetTime(
2128
+ this,
2129
+ new Date(getOffsetTime(this)).setUTCHours(...args),
2130
+ );
2131
+ }
2132
+ /**
2133
+ * Set the milliseconds in current timeZone.
2134
+ * @param {number} milliseconds The milliseconds.
2135
+ * @return {DateTime} The DateTime object.
2136
+ */
2137
+ function setMilliseconds(milliseconds) {
2138
+ return setOffsetTime(
2139
+ this,
2140
+ new Date(getOffsetTime(this)).setUTCMilliseconds(milliseconds),
2141
+ );
2142
+ }
2143
+ /**
2144
+ * Set the minutes in current timeZone (and optionally, seconds and milliseconds).
2145
+ * @param {number} minutes The minutes. (0, 59)
2146
+ * @param {number} [seconds] The seconds. (0, 59)
2147
+ * @param {number} [milliseconds] The milliseconds.
2148
+ * @return {DateTime} The DateTime object.
2149
+ */
2150
+ function setMinutes(...args) {
2151
+ return setOffsetTime(
2152
+ this,
2153
+ new Date(getOffsetTime(this)).setUTCMinutes(...args),
2154
+ );
2155
+ }
2156
+ /**
2157
+ * Set the month in current timeZone (and optionally, date).
2158
+ * @param {number} month The month. (1, 12)
2159
+ * @param {number|null} [date] The date of the month.
2160
+ * @return {DateTime} The DateTime object.
2161
+ */
2162
+ function setMonth(month, date = null) {
2163
+ if (date === null) {
2164
+ date = this.getDate();
2165
+
2166
+ if (config.clampDates) {
2167
+ date = Math.min(
2168
+ date,
2169
+ daysInMonth$1(
2170
+ this.getYear(),
2171
+ month,
2172
+ ),
2173
+ );
2174
+ }
2175
+ }
2176
+
2177
+ return setOffsetTime(
2178
+ this,
2179
+ new Date(getOffsetTime(this)).setUTCMonth(
2180
+ month - 1,
2181
+ date,
2182
+ ),
2183
+ );
2184
+ }
2185
+ /**
2186
+ * Set the quarter of the year in current timeZone.
2187
+ * @param {number} quarter The quarter of the year. (1, 4)
2188
+ * @return {DateTime} The DateTime object.
2189
+ */
2190
+ function setQuarter(quarter) {
2191
+ return setOffsetTime(
2192
+ this,
2193
+ new Date(getOffsetTime(this)).setUTCMonth(
2194
+ quarter * 3 -
2195
+ 3,
2196
+ ),
2197
+ );
2198
+ }
2199
+ /**
2200
+ * Set the seconds in current timeZone (and optionally, milliseconds).
2201
+ * @param {number} seconds The seconds. (0, 59)
2202
+ * @param {number} [milliseconds] The milliseconds.
2203
+ * @return {DateTime} The DateTime object.
2204
+ */
2205
+ function setSeconds(...args) {
2206
+ return setOffsetTime(
2207
+ this,
2208
+ new Date(getOffsetTime(this)).setUTCSeconds(...args),
2209
+ );
2210
+ }
2211
+ /**
2212
+ * Set the number of seconds since the UNIX epoch.
2213
+ * @param {number} timestamp The number of seconds since the UNIX epoch.
2214
+ * @return {DateTime} The DateTime object.
2215
+ */
2216
+ function setTimestamp(timestamp) {
2217
+ return this.setTime(timestamp * 1000);
2218
+ }
2219
+ /**
2220
+ * Set the local day of the week in current timeZone (and optionally, day of the week).
2221
+ * @param {number} week The local week.
2222
+ * @param {number|null} [day] The local day of the week. (1 - 7)
2223
+ * @return {DateTime} The DateTime object.
2224
+ */
2225
+ function setWeek(week, day = null) {
2226
+ if (day === null) {
2227
+ day = this.getWeekDay();
2228
+ }
2229
+
2230
+ const minDays = minimumDays(this.getLocale());
2231
+ return this.setYear(this.getWeekYear(), 1, minDays + ((week - 1) * 7)).setWeekDay(day);
2232
+ }
2233
+ /**
2234
+ * Set the local day of the week in current timeZone.
2235
+ * @param {number} day The local day of the week. (1 - 7)
2236
+ * @return {DateTime} The DateTime object.
2237
+ */
2238
+ function setWeekDay(day) {
2239
+ return setOffsetTime(
2240
+ this,
2241
+ new Date(getOffsetTime(this)).setUTCDate(
2242
+ this.getDate() -
2243
+ this.getWeekDay() +
2244
+ parseInt(day),
2245
+ ),
2246
+ );
2247
+ }
2248
+ /**
2249
+ * Set the week day in month in current timeZone.
2250
+ * @param {number} week The week day in month.
2251
+ * @return {DateTime} The DateTime object.
2252
+ */
2253
+ function setWeekDayInMonth(week) {
2254
+ return this.setDate(
2255
+ this.getDate() +
2256
+ (
2257
+ week -
2258
+ this.getWeekDayInMonth()
2259
+ ) * 7,
2260
+ );
2261
+ }
2262
+ /**
2263
+ * Set the week of month in current timeZone.
2264
+ * @param {number} week The week of month.
2265
+ * @return {DateTime} The DateTime object.
2266
+ */
2267
+ function setWeekOfMonth(week) {
2268
+ return this.setDate(
2269
+ this.getDate() +
2270
+ (
2271
+ week -
2272
+ this.getWeekOfMonth()
2273
+ ) * 7,
2274
+ );
2275
+ }
2276
+ /**
2277
+ * Set the local day of the week in current timeZone (and optionally, week and day of the week).
2278
+ * @param {number} year The local year.
2279
+ * @param {number|null} [week] The local week.
2280
+ * @param {number|null} [day] The local day of the week. (1 - 7)
2281
+ * @return {DateTime} The DateTime object.
2282
+ */
2283
+ function setWeekYear(year, week = null, day = null) {
2284
+ const minDays = minimumDays(this.getLocale());
2285
+
2286
+ if (week === null) {
2287
+ week = Math.min(
2288
+ this.getWeek(),
2289
+ DateTime.fromArray([year, 1, minDays]).weeksInYear(),
2290
+ );
2291
+ }
2292
+
2293
+ if (day === null) {
2294
+ day = this.getWeekDay();
2295
+ }
2296
+
2297
+ return this.setYear(year, 1, minDays + ((week - 1) * 7)).setWeekDay(day);
2298
+ }
2299
+ /**
2300
+ * Set the year in current timeZone (and optionally, month and date).
2301
+ * @param {number} year The year.
2302
+ * @param {number|null} [month] The month. (1, 12)
2303
+ * @param {number|null} [date] The date of the month.
2304
+ * @return {DateTime} The DateTime object.
2305
+ */
2306
+ function setYear(year, month = null, date = null) {
2307
+ if (month === null) {
2308
+ month = this.getMonth();
2309
+ }
2310
+
2311
+ if (date === null) {
2312
+ date = this.getDate();
2313
+
2314
+ if (config.clampDates) {
2315
+ date = Math.min(
2316
+ date,
2317
+ daysInMonth$1(
2318
+ this.getYear(),
2319
+ month,
2320
+ ),
2321
+ );
2322
+ }
2323
+ }
2324
+
2325
+ return setOffsetTime(
2326
+ this,
2327
+ new Date(getOffsetTime(this)).setUTCFullYear(
2328
+ year,
2329
+ month - 1,
2330
+ date,
2331
+ ),
2332
+ );
2333
+ }
2334
+
2335
+ /**
2336
+ * DateTime Manipulation
2337
+ */
2338
+
2339
+ /**
2340
+ * Add a duration to the date.
2341
+ * @param {number} amount The amount to modify the date by.
2342
+ * @param {string} timeUnit The unit of time.
2343
+ * @return {DateTime} The DateTime object.
2344
+ */
2345
+ function add(amount, timeUnit) {
2346
+ return modify(this, amount, timeUnit);
2347
+ }
2348
+ /**
2349
+ * Modify the DateTime by setting it to the end of a unit of time.
2350
+ * @param {string} timeUnit The unit of time.
2351
+ * @return {DateTime} The DateTime object.
2352
+ */
2353
+ function endOf(timeUnit) {
2354
+ timeUnit = timeUnit.toLowerCase();
2355
+
2356
+ switch (timeUnit) {
2357
+ case 'second':
2358
+ return this.setMilliseconds(999);
2359
+ case 'minute':
2360
+ return this.setSeconds(59, 999);
2361
+ case 'hour':
2362
+ return this.setMinutes(59, 59, 999);
2363
+ case 'day':
2364
+ return this.setHours(23, 59, 59, 999);
2365
+ case 'week':
2366
+ return this.setWeekDay(7)
2367
+ .setHours(23, 59, 59, 999);
2368
+ case 'month':
2369
+ return this.setDate(this.daysInMonth())
2370
+ .setHours(23, 59, 59, 999);
2371
+ case 'quarter':
2372
+ const month = this.getQuarter() * 3;
2373
+ return this.setMonth(month, daysInMonth$1(this.getYear(), month))
2374
+ .setHours(23, 59, 59, 999);
2375
+ case 'year':
2376
+ return this.setMonth(12, 31)
2377
+ .setHours(23, 59, 59, 999);
2378
+ default:
2379
+ throw new Error('Invalid time unit supplied');
2380
+ }
2381
+ }
2382
+ /**
2383
+ * Modify the DateTime by setting it to the start of a unit of time.
2384
+ * @param {string} timeUnit The unit of time.
2385
+ * @return {DateTime} The DateTime object.
2386
+ */
2387
+ function startOf(timeUnit) {
2388
+ timeUnit = timeUnit.toLowerCase();
2389
+
2390
+ switch (timeUnit) {
2391
+ case 'second':
2392
+ return this.setMilliseconds(0);
2393
+ case 'minute':
2394
+ return this.setSeconds(0, 0);
2395
+ case 'hour':
2396
+ return this.setMinutes(0, 0, 0);
2397
+ case 'day':
2398
+ return this.setHours(0, 0, 0, 0);
2399
+ case 'week':
2400
+ return this.setWeekDay(1)
2401
+ .setHours(0, 0, 0, 0);
2402
+ case 'month':
2403
+ return this.setDate(1)
2404
+ .setHours(0, 0, 0, 0);
2405
+ case 'quarter':
2406
+ const month = this.getQuarter() * 3 - 2;
2407
+ return this.setMonth(month, 1)
2408
+ .setHours(0, 0, 0, 0);
2409
+ case 'year':
2410
+ return this.setMonth(1, 1)
2411
+ .setHours(0, 0, 0, 0);
2412
+ default:
2413
+ throw new Error('Invalid time unit supplied');
2414
+ }
2415
+ }
2416
+ /**
2417
+ * Subtract a duration from the date.
2418
+ * @param {number} amount The amount to modify the date by.
2419
+ * @param {string} timeUnit The unit of time.
2420
+ * @return {DateTime} The DateTime object.
2421
+ */
2422
+ function sub(amount, timeUnit) {
2423
+ return modify(this, -amount, timeUnit);
2424
+ }
2425
+
2426
+ /**
2427
+ * DateTime Output
2428
+ */
2429
+
2430
+ /**
2431
+ * Format the current date using a format string.
2432
+ * @param {string} formatString The format string.
2433
+ * @return {string} The formatted date string.
2434
+ */
2435
+ function format(formatString) {
2436
+ let match;
2437
+ let output = '';
2438
+
2439
+ while (formatString && (match = formatString.match(formatTokenRegExp))) {
2440
+ const token = match[1];
2441
+ const position = match.index;
2442
+ const length = match[0].length;
2443
+
2444
+ if (position) {
2445
+ output += formatString.substring(0, position);
2446
+ }
2447
+
2448
+ formatString = formatString.substring(position + length);
2449
+
2450
+ if (!token) {
2451
+ output += match[0].slice(1, -1);
2452
+ continue;
2453
+ }
2454
+
2455
+ if (!(token in tokens)) {
2456
+ throw new Error(`Invalid token in DateTime format: ${token}`);
2457
+ }
2458
+
2459
+ output += tokens[token].output(this, length);
2460
+ }
2461
+
2462
+ output += formatString;
2463
+
2464
+ return output;
2465
+ }
2466
+ /**
2467
+ * Format the current date using "eee MMM dd yyyy".
2468
+ * @return {string} The formatted date string.
2469
+ */
2470
+ function toDateString() {
2471
+ return this.format(formats.date);
2472
+ }
2473
+ /**
2474
+ * Format the current date using "yyyy-MM-dd'THH:mm:ss.SSSSSSxxx".
2475
+ * @return {string} The formatted date string.
2476
+ */
2477
+ function toISOString() {
2478
+ return this
2479
+ .setLocale('en')
2480
+ .setTimeZone('UTC')
2481
+ .format(formats.rfc3339_extended);
2482
+ }
2483
+ /**
2484
+ * Format the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
2485
+ * @return {string} The formatted date string.
2486
+ */
2487
+ function toString() {
2488
+ return this.format(formats.string);
2489
+ }
2490
+ /**
2491
+ * Format the current date using "HH:mm:ss xx (VV)".
2492
+ * @return {string} The formatted date string.
2493
+ */
2494
+ function toTimeString() {
2495
+ return this.format(formats.time);
2496
+ }
2497
+ /**
2498
+ * Format the current date in UTC timeZone using "eee MMM dd yyyy HH:mm:ss xx (VV)".
2499
+ * @return {string} The formatted date string.
2500
+ */
2501
+ function toUTCString() {
2502
+ return this
2503
+ .setLocale('en')
2504
+ .setTimeZone('UTC')
2505
+ .toString();
2506
+ }
2507
+
2508
+ /**
2509
+ * DateTime Utility
2510
+ */
2511
+
2512
+ /**
2513
+ * Get the name of the day of the week in current timeZone.
2514
+ * @param {string} [type=long] The type of day name to return.
2515
+ * @return {string} The name of the day of the week.
2516
+ */
2517
+ function dayName(type = 'long') {
2518
+ return formatDay(this.getLocale(), this.getDay(), type);
2519
+ }
2520
+ /**
2521
+ * Get the day period in current timeZone.
2522
+ * @param {string} [type=long] The type of day period to return.
2523
+ * @return {string} The day period.
2524
+ */
2525
+ function dayPeriod(type = 'long') {
2526
+ return formatDayPeriod(
2527
+ this.getLocale(),
2528
+ this.getHours() < 12 ?
2529
+ 0 :
2530
+ 1,
2531
+ type,
2532
+ );
2533
+ }
2534
+ /**
2535
+ * Get the number of days in the current month.
2536
+ * @return {number} The number of days in the current month.
2537
+ */
2538
+ function daysInMonth() {
2539
+ return daysInMonth$1(
2540
+ this.getYear(),
2541
+ this.getMonth(),
2542
+ );
2543
+ }
2544
+ /**
2545
+ * Get the number of days in the current year.
2546
+ * @return {number} The number of days in the current year.
2547
+ */
2548
+ function daysInYear() {
2549
+ return daysInYear$1(
2550
+ this.getYear(),
2551
+ );
2552
+ }
2553
+ /**
2554
+ * Get the difference between this and another Date.
2555
+ * @param {DateTime} [other] The date to compare to.
2556
+ * @param {object} [options] The options for comparing the dates.
2557
+ * @param {string} [options.timeUnit] The unit of time.
2558
+ * @param {Boolean} [options.relative=true] Whether to use the relative difference.
2559
+ * @return {number} The difference.
2560
+ */
2561
+ function diff(other, { timeUnit, relative = true } = {}) {
2562
+ if (!other) {
2563
+ other = new this.constructor;
2564
+ }
2565
+
2566
+ if (!timeUnit) {
2567
+ return this - other;
2568
+ }
2569
+
2570
+ if (timeUnit) {
2571
+ timeUnit = timeUnit.toLowerCase();
2572
+ }
2573
+
2574
+ other = other.setTimeZone(this.getTimeZone());
2575
+
2576
+ switch (timeUnit) {
2577
+ case 'year':
2578
+ case 'years':
2579
+ const yearDiff = this.getYear() - other.getYear();
2580
+ return compensateDiff(
2581
+ this,
2582
+ other.setYear(
2583
+ this.getYear(),
2584
+ ),
2585
+ yearDiff,
2586
+ !relative,
2587
+ -1,
2588
+ );
2589
+ case 'month':
2590
+ case 'months':
2591
+ const monthDiff = (this.getYear() - other.getYear()) *
2592
+ 12 +
2593
+ this.getMonth() -
2594
+ other.getMonth();
2595
+ return compensateDiff(
2596
+ this,
2597
+ other.setYear(
2598
+ this.getYear(),
2599
+ this.getMonth(),
2600
+ ),
2601
+ monthDiff,
2602
+ !relative,
2603
+ -1,
2604
+ );
2605
+ case 'week':
2606
+ case 'weeks':
2607
+ const weekDiff = (this - other) / 604800000;
2608
+ return compensateDiff(
2609
+ this,
2610
+ other.setWeekYear(
2611
+ this.getWeekYear(),
2612
+ this.getWeek(),
2613
+ ),
2614
+ weekDiff,
2615
+ relative,
2616
+ );
2617
+ case 'day':
2618
+ case 'days':
2619
+ const dayDiff = (this - other) / 86400000;
2620
+ return compensateDiff(
2621
+ this,
2622
+ other.setYear(
2623
+ this.getYear(),
2624
+ this.getMonth(),
2625
+ this.getDate(),
2626
+ ),
2627
+ dayDiff,
2628
+ relative,
2629
+ );
2630
+ case 'hour':
2631
+ case 'hours':
2632
+ const hourDiff = (this - other) / 3600000;
2633
+ return compensateDiff(
2634
+ this,
2635
+ other.setYear(
2636
+ this.getYear(),
2637
+ this.getMonth(),
2638
+ this.getDate(),
2639
+ ).setHours(
2640
+ this.getHours(),
2641
+ ),
2642
+ hourDiff,
2643
+ relative,
2644
+ );
2645
+ case 'minute':
2646
+ case 'minutes':
2647
+ const minuteDiff = (this - other) / 60000;
2648
+ return compensateDiff(
2649
+ this,
2650
+ other.setYear(
2651
+ this.getYear(),
2652
+ this.getMonth(),
2653
+ this.getDate(),
2654
+ ).setHours(
2655
+ this.getHours(),
2656
+ this.getMinutes(),
2657
+ ),
2658
+ minuteDiff,
2659
+ relative,
2660
+ );
2661
+ case 'second':
2662
+ case 'seconds':
2663
+ const secondDiff = (this - other) / 1000;
2664
+ return compensateDiff(
2665
+ this,
2666
+ other.setYear(
2667
+ this.getYear(),
2668
+ this.getMonth(),
2669
+ this.getDate(),
2670
+ ).setHours(
2671
+ this.getHours(),
2672
+ this.getMinutes(),
2673
+ this.getSeconds(),
2674
+ ),
2675
+ secondDiff,
2676
+ relative,
2677
+ );
2678
+ default:
2679
+ throw new Error('Invalid time unit supplied');
2680
+ }
2681
+ }
2682
+ /**
2683
+ * Get the era in current timeZone.
2684
+ * @param {string} [type=long] The type of era to return.
2685
+ * @return {string} The era.
2686
+ */
2687
+ function era(type = 'long') {
2688
+ return formatEra(
2689
+ this.getLocale(),
2690
+ this.getYear() < 0 ?
2691
+ 0 :
2692
+ 1,
2693
+ type,
2694
+ );
2695
+ }
2696
+ /**
2697
+ * Get the difference between this and another Date in human readable form.
2698
+ * @param {DateTime} [other] The date to compare to.
2699
+ * @param {object} [options] The options for comparing the dates.
2700
+ * @param {string} [options.timeUnit] The unit of time.
2701
+ * @return {string} The difference in human readable form.
2702
+ */
2703
+ function humanDiff(other, { timeUnit } = {}) {
2704
+ const relativeFormatter = getRelativeFormatter(this.getLocale());
2705
+
2706
+ if (!relativeFormatter) {
2707
+ throw new Error('RelativeTimeFormat not supported');
2708
+ }
2709
+
2710
+ if (!other) {
2711
+ other = new this.constructor;
2712
+ }
2713
+
2714
+ let amount;
2715
+ if (timeUnit) {
2716
+ amount = this.diff(other, { timeUnit });
2717
+ } else {
2718
+ [amount, timeUnit] = getBiggestDiff(this, other);
2719
+ }
2720
+
2721
+ return relativeFormatter.format(amount, timeUnit);
2722
+ }
2723
+ /**
2724
+ * Determine whether this DateTime is after another date (optionally to a granularity).
2725
+ * @param {DateTime} [other] The date to compare to.
2726
+ * @param {object} [options] The options for comparing the dates.
2727
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2728
+ * @return {Boolean} TRUE if this DateTime is after the other date, otherwise FALSE.
2729
+ */
2730
+ function isAfter(other, { granularity } = {}) {
2731
+ return this.diff(other, { timeUnit: granularity }) > 0;
2732
+ }
2733
+ /**
2734
+ * Determine whether this DateTime is before another date (optionally to a granularity).
2735
+ * @param {DateTime} [other] The date to compare to.
2736
+ * @param {object} [options] The options for comparing the dates.
2737
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2738
+ * @return {Boolean} TRUE if this DateTime is before the other date, otherwise FALSE.
2739
+ */
2740
+ function isBefore(other, { granularity } = {}) {
2741
+ return this.diff(other, { timeUnit: granularity }) < 0;
2742
+ }
2743
+ /**
2744
+ * Determine whether this DateTime is between two other dates (optionally to a granularity).
2745
+ * @param {DateTime} [start] The first date to compare to.
2746
+ * @param {DateTime} [end] The second date to compare to.
2747
+ * @param {object} [options] The options for comparing the dates.
2748
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2749
+ * @return {Boolean} TRUE if this DateTime is between the other dates, otherwise FALSE.
2750
+ */
2751
+ function isBetween(start, end, { granularity } = {}) {
2752
+ return this.diff(start, { timeUnit: granularity }) > 0 && this.diff(end, { timeUnit: granularity }) < 0;
2753
+ }
2754
+ /**
2755
+ * Return true if the DateTime is in daylight savings.
2756
+ * @return {Boolean} TRUE if the current time is in daylight savings, otherwise FALSE.
2757
+ */
2758
+ function isDST() {
2759
+ if (!this._dynamicTz) {
2760
+ return false;
2761
+ }
2762
+
2763
+ const year = this.getYear();
2764
+ const dateA = DateTime.fromArray([year, 1, 1], {
2765
+ timeZone: this.getTimeZone(),
2766
+ });
2767
+ const dateB = DateTime.fromArray([year, 6, 1], {
2768
+ timeZone: this.getTimeZone(),
2769
+ });
2770
+
2771
+ return this.getTimeZoneOffset() < Math.max(dateA.getTimeZoneOffset(), dateB.getTimeZoneOffset());
2772
+ }
2773
+ /**
2774
+ * Return true if the year is a leap year.
2775
+ * @return {Boolean} TRUE if the current year is a leap year, otherwise FALSE.
2776
+ */
2777
+ function isLeapYear() {
2778
+ return isLeapYear$1(
2779
+ this.getYear(),
2780
+ );
2781
+ }
2782
+ /**
2783
+ * Determine whether this DateTime is the same as another date (optionally to a granularity).
2784
+ * @param {DateTime} [other] The date to compare to.
2785
+ * @param {object} [options] The options for comparing the dates.
2786
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2787
+ * @return {Boolean} TRUE if this DateTime is the same as the other date, otherwise FALSE.
2788
+ */
2789
+ function isSame(other, { granularity } = {}) {
2790
+ return this.diff(other, { timeUnit: granularity }) === 0;
2791
+ }
2792
+ /**
2793
+ * Determine whether this DateTime is the same or after another date (optionally to a granularity).
2794
+ * @param {DateTime} [other] The date to compare to.
2795
+ * @param {object} [options] The options for comparing the dates.
2796
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2797
+ * @return {Boolean} TRUE if this DateTime is the same or after the other date, otherwise FALSE.
2798
+ */
2799
+ function isSameOrAfter(other, { granularity } = {}) {
2800
+ return this.diff(other, { timeUnit: granularity }) >= 0;
2801
+ }
2802
+ /**
2803
+ * Determine whether this DateTime is the same or before another date.
2804
+ * @param {DateTime} other The date to compare to.
2805
+ * @param {object} [options] The options for comparing the dates.
2806
+ * @param {string} [options.granularity] The level of granularity to use for comparison.
2807
+ * @return {Boolean} TRUE if this DateTime is the same or before the other date, otherwise FALSE.
2808
+ */
2809
+ function isSameOrBefore(other, { granularity } = {}) {
2810
+ return this.diff(other, { timeUnit: granularity }) <= 0;
2811
+ }
2812
+ /**
2813
+ * Get the name of the month in current timeZone.
2814
+ * @param {string} [type=long] The type of month name to return.
2815
+ * @return {string} The name of the month.
2816
+ */
2817
+ function monthName(type = 'long') {
2818
+ return formatMonth(this.getLocale(), this.getMonth(), type);
2819
+ }
2820
+ /**
2821
+ * Get the name of the current timeZone.
2822
+ * @param {string} [type=long] The formatting type.
2823
+ * @return {string} The name of the time zone.
2824
+ */
2825
+ function timeZoneName(type = 'long') {
2826
+ return this._dynamicTz ?
2827
+ formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
2828
+ 'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
2829
+ }
2830
+ /**
2831
+ * Get the number of weeks in the current year.
2832
+ * @return {number} The number of weeks in the current year.
2833
+ */
2834
+ function weeksInYear() {
2835
+ const minDays = minimumDays(this.getLocale());
2836
+ return this.setMonth(12, 24 + minDays).getWeek();
2837
+ }
2838
+
2839
+ DateTime.dayOfYear = dayOfYear;
2840
+ DateTime.daysInMonth = daysInMonth$1;
2841
+ DateTime.daysInYear = daysInYear$1;
2842
+ DateTime.fromArray = fromArray;
2843
+ DateTime.fromDate = fromDate;
2844
+ DateTime.fromFormat = fromFormat;
2845
+ DateTime.fromISOString = fromISOString;
2846
+ DateTime.fromTimestamp = fromTimestamp;
2847
+ DateTime.getDefaultLocale = getDefaultLocale;
2848
+ DateTime.getDefaultTimeZone = getDefaultTimeZone;
2849
+ DateTime.isLeapYear = isLeapYear$1;
2850
+ DateTime.now = now;
2851
+ DateTime.setDateClamping = setDateClamping;
2852
+ DateTime.setDefaultLocale = setDefaultLocale;
2853
+ DateTime.setDefaultTimeZone = setDefaultTimeZone;
2854
+
2855
+ const proto = DateTime.prototype;
2856
+
2857
+ proto.add = add;
2858
+ proto.dayName = dayName;
2859
+ proto.dayPeriod = dayPeriod;
2860
+ proto.daysInMonth = daysInMonth;
2861
+ proto.daysInYear = daysInYear;
2862
+ proto.diff = diff;
2863
+ proto.endOf = endOf;
2864
+ proto.era = era;
2865
+ proto.format = format;
2866
+ proto.getDate = getDate;
2867
+ proto.getDay = getDay;
2868
+ proto.getDayOfYear = getDayOfYear;
2869
+ proto.getHours = getHours;
2870
+ proto.getMilliseconds = getMilliseconds;
2871
+ proto.getMinutes = getMinutes;
2872
+ proto.getMonth = getMonth;
2873
+ proto.getQuarter = getQuarter;
2874
+ proto.getSeconds = getSeconds;
2875
+ proto.getTimestamp = getTimestamp;
2876
+ proto.getWeek = getWeek;
2877
+ proto.getWeekDay = getWeekDay;
2878
+ proto.getWeekDayInMonth = getWeekDayInMonth;
2879
+ proto.getWeekOfMonth = getWeekOfMonth;
2880
+ proto.getWeekYear = getWeekYear;
2881
+ proto.getYear = getYear;
2882
+ proto.humanDiff = humanDiff;
2883
+ proto.isAfter = isAfter;
2884
+ proto.isBefore = isBefore;
2885
+ proto.isBetween = isBetween;
2886
+ proto.isDST = isDST;
2887
+ proto.isLeapYear = isLeapYear;
2888
+ proto.isSame = isSame;
2889
+ proto.isSameOrAfter = isSameOrAfter;
2890
+ proto.isSameOrBefore = isSameOrBefore;
2891
+ proto.monthName = monthName;
2892
+ proto.setDate = setDate;
2893
+ proto.setDay = setDay;
2894
+ proto.setDayOfYear = setDayOfYear;
2895
+ proto.setHours = setHours;
2896
+ proto.setMilliseconds = setMilliseconds;
2897
+ proto.setMinutes = setMinutes;
2898
+ proto.setMonth = setMonth;
2899
+ proto.setQuarter = setQuarter;
2900
+ proto.setSeconds = setSeconds;
2901
+ proto.setTimestamp = setTimestamp;
2902
+ proto.setWeek = setWeek;
2903
+ proto.setWeekDay = setWeekDay;
2904
+ proto.setWeekDayInMonth = setWeekDayInMonth;
2905
+ proto.setWeekOfMonth = setWeekOfMonth;
2906
+ proto.setWeekYear = setWeekYear;
2907
+ proto.setYear = setYear;
2908
+ proto.startOf = startOf;
2909
+ proto.sub = sub;
2910
+ proto.timeZoneName = timeZoneName;
2911
+ proto.toDateString = toDateString;
2912
+ proto.toISOString = toISOString;
2913
+ proto.toString = toString;
2914
+ proto.toTimeString = toTimeString;
2915
+ proto.toUTCString = toUTCString;
2916
+ proto.weeksInYear = weeksInYear;
2917
+
2918
+ return DateTime;
2919
+
2920
+ }));
2921
+ //# sourceMappingURL=frost-datetime.js.map