@fr0st/datetime 8.0.0 → 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/frost-datetime.js +270 -264
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +1 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +1 -1
- package/src/date-time.js +214 -208
- package/src/factory.js +4 -4
- package/src/formatter/format.js +13 -13
- package/src/formatter/locale.js +3 -3
- package/src/formatter/parse.js +10 -10
- package/src/formatter/utility.js +5 -5
- package/src/formatter/values.js +10 -10
- package/src/helpers.js +11 -11
package/src/date-time.js
CHANGED
|
@@ -38,6 +38,12 @@ import {
|
|
|
38
38
|
* An immutable date and time object with locale-aware formatting and time-zone support.
|
|
39
39
|
*/
|
|
40
40
|
export default class DateTime {
|
|
41
|
+
#date;
|
|
42
|
+
#dynamicTz;
|
|
43
|
+
#locale;
|
|
44
|
+
#offset;
|
|
45
|
+
#timeZone;
|
|
46
|
+
|
|
41
47
|
/**
|
|
42
48
|
* Clears cached formatter and locale data.
|
|
43
49
|
*/
|
|
@@ -50,7 +56,7 @@ export default class DateTime {
|
|
|
50
56
|
* @param {number} year The year.
|
|
51
57
|
* @param {number} month The month. (1-12)
|
|
52
58
|
* @param {number} date The date.
|
|
53
|
-
* @
|
|
59
|
+
* @returns {number} The day of the year. (1-366)
|
|
54
60
|
*/
|
|
55
61
|
static dayOfYear(year, month, date) {
|
|
56
62
|
return new Array(month - 1)
|
|
@@ -66,7 +72,7 @@ export default class DateTime {
|
|
|
66
72
|
* Gets the number of days in a month for a given year.
|
|
67
73
|
* @param {number} year The year.
|
|
68
74
|
* @param {number} month The month. (1-12)
|
|
69
|
-
* @
|
|
75
|
+
* @returns {number} The number of days in the month.
|
|
70
76
|
*/
|
|
71
77
|
static daysInMonth(year, month) {
|
|
72
78
|
const date = new Date(0);
|
|
@@ -86,7 +92,7 @@ export default class DateTime {
|
|
|
86
92
|
/**
|
|
87
93
|
* Gets the number of days in a given year.
|
|
88
94
|
* @param {number} year The year.
|
|
89
|
-
* @
|
|
95
|
+
* @returns {number} The number of days in the year.
|
|
90
96
|
*/
|
|
91
97
|
static daysInYear(year) {
|
|
92
98
|
return !this.isLeapYear(year) ?
|
|
@@ -101,7 +107,7 @@ export default class DateTime {
|
|
|
101
107
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
102
108
|
* @param {string} [options.timeZone] The time zone to use.
|
|
103
109
|
* @param {string} [options.locale] The locale to use.
|
|
104
|
-
* @
|
|
110
|
+
* @returns {DateTime} A new DateTime instance.
|
|
105
111
|
*/
|
|
106
112
|
static fromArray(dateArray, options = {}) {
|
|
107
113
|
const dateValues = dateArray.slice(0, 3);
|
|
@@ -127,7 +133,7 @@ export default class DateTime {
|
|
|
127
133
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
128
134
|
* @param {string} [options.timeZone] The time zone to use.
|
|
129
135
|
* @param {string} [options.locale] The locale to use.
|
|
130
|
-
* @
|
|
136
|
+
* @returns {DateTime} A new DateTime instance.
|
|
131
137
|
*/
|
|
132
138
|
static fromDate(date, options = {}) {
|
|
133
139
|
return new this(date.getTime(), options);
|
|
@@ -140,9 +146,9 @@ export default class DateTime {
|
|
|
140
146
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
141
147
|
* @param {string} [options.timeZone] The time zone to use.
|
|
142
148
|
* @param {string} [options.locale] The locale to use.
|
|
143
|
-
* @
|
|
149
|
+
* @returns {DateTime} A new DateTime instance.
|
|
150
|
+
* @throws {Error} When the format contains unsupported parsing tokens such as
|
|
144
151
|
* `MMMMM` or `LLLLL`.
|
|
145
|
-
* @return {DateTime} A new DateTime instance.
|
|
146
152
|
*/
|
|
147
153
|
static fromFormat(formatString, dateString, options = {}) {
|
|
148
154
|
const locale = 'locale' in options ?
|
|
@@ -290,7 +296,7 @@ export default class DateTime {
|
|
|
290
296
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
291
297
|
* @param {string} [options.timeZone] The time zone to use.
|
|
292
298
|
* @param {string} [options.locale] The locale to use.
|
|
293
|
-
* @
|
|
299
|
+
* @returns {DateTime} A new DateTime instance.
|
|
294
300
|
*/
|
|
295
301
|
static fromISOString(dateString, options = {}) {
|
|
296
302
|
let date = this.fromFormat(formats.rfc3339_extended, dateString, {
|
|
@@ -314,7 +320,7 @@ export default class DateTime {
|
|
|
314
320
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
315
321
|
* @param {string} [options.timeZone] The time zone to use.
|
|
316
322
|
* @param {string} [options.locale] The locale to use.
|
|
317
|
-
* @
|
|
323
|
+
* @returns {DateTime} A new DateTime instance.
|
|
318
324
|
*/
|
|
319
325
|
static fromTimestamp(timestamp, options = {}) {
|
|
320
326
|
return new this(null, options)
|
|
@@ -323,7 +329,7 @@ export default class DateTime {
|
|
|
323
329
|
|
|
324
330
|
/**
|
|
325
331
|
* Gets the default locale.
|
|
326
|
-
* @
|
|
332
|
+
* @returns {string} The locale.
|
|
327
333
|
*/
|
|
328
334
|
static getDefaultLocale() {
|
|
329
335
|
return config.defaultLocale;
|
|
@@ -331,7 +337,7 @@ export default class DateTime {
|
|
|
331
337
|
|
|
332
338
|
/**
|
|
333
339
|
* Gets the default time zone.
|
|
334
|
-
* @
|
|
340
|
+
* @returns {string} The default time zone.
|
|
335
341
|
*/
|
|
336
342
|
static getDefaultTimeZone() {
|
|
337
343
|
return config.defaultTimeZone;
|
|
@@ -340,7 +346,7 @@ export default class DateTime {
|
|
|
340
346
|
/**
|
|
341
347
|
* Checks whether the year is a leap year.
|
|
342
348
|
* @param {number} year The year.
|
|
343
|
-
* @
|
|
349
|
+
* @returns {boolean} Whether the given year is a leap year.
|
|
344
350
|
*/
|
|
345
351
|
static isLeapYear(year) {
|
|
346
352
|
const date = new Date(0);
|
|
@@ -354,7 +360,7 @@ export default class DateTime {
|
|
|
354
360
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
355
361
|
* @param {string} [options.timeZone] The time zone to use.
|
|
356
362
|
* @param {string} [options.locale] The locale to use.
|
|
357
|
-
* @
|
|
363
|
+
* @returns {DateTime} A new DateTime instance.
|
|
358
364
|
*/
|
|
359
365
|
static now(options = {}) {
|
|
360
366
|
return new this(null, options);
|
|
@@ -421,8 +427,8 @@ export default class DateTime {
|
|
|
421
427
|
throw new Error('Invalid date supplied');
|
|
422
428
|
}
|
|
423
429
|
|
|
424
|
-
this
|
|
425
|
-
this
|
|
430
|
+
this.#date = new Date(timestamp);
|
|
431
|
+
this.#dynamicTz = false;
|
|
426
432
|
this.isValid = true;
|
|
427
433
|
|
|
428
434
|
let timeZone = options.timeZone;
|
|
@@ -437,43 +443,43 @@ export default class DateTime {
|
|
|
437
443
|
|
|
438
444
|
const match = timeZone.match(offsetRegExp);
|
|
439
445
|
if (match) {
|
|
440
|
-
this
|
|
446
|
+
this.#offset =
|
|
441
447
|
match[2] * 60 +
|
|
442
448
|
parseInt(match[4] || 0, 10) +
|
|
443
449
|
parseInt(match[5] || 0, 10) / 60;
|
|
444
|
-
if (this
|
|
445
|
-
this
|
|
450
|
+
if (this.#offset && match[1] === '+') {
|
|
451
|
+
this.#offset *= -1;
|
|
446
452
|
}
|
|
447
453
|
|
|
448
|
-
if (this
|
|
449
|
-
this
|
|
454
|
+
if (this.#offset) {
|
|
455
|
+
this.#timeZone = formatOffset(this.#offset);
|
|
450
456
|
} else {
|
|
451
|
-
this
|
|
452
|
-
this
|
|
457
|
+
this.#dynamicTz = true;
|
|
458
|
+
this.#timeZone = 'UTC';
|
|
453
459
|
}
|
|
454
460
|
} else {
|
|
455
|
-
this
|
|
456
|
-
this
|
|
461
|
+
this.#dynamicTz = true;
|
|
462
|
+
this.#timeZone = timeZone;
|
|
457
463
|
}
|
|
458
464
|
|
|
459
|
-
this
|
|
465
|
+
this.#locale = 'locale' in options ?
|
|
460
466
|
options.locale :
|
|
461
467
|
config.defaultLocale;
|
|
462
468
|
|
|
463
|
-
if (this
|
|
464
|
-
this
|
|
469
|
+
if (this.#dynamicTz) {
|
|
470
|
+
this.#offset = getOffset(this);
|
|
465
471
|
}
|
|
466
472
|
|
|
467
|
-
if (adjustOffset && this
|
|
473
|
+
if (adjustOffset && this.#offset) {
|
|
468
474
|
const resolvedDate = setOffsetTime(this, timestamp);
|
|
469
|
-
this.
|
|
470
|
-
this
|
|
475
|
+
this.#date.setTime(resolvedDate.getTime());
|
|
476
|
+
this.#offset = resolvedDate.getTimeZoneOffset();
|
|
471
477
|
}
|
|
472
478
|
}
|
|
473
479
|
|
|
474
480
|
/**
|
|
475
481
|
* Adds a day to the current DateTime.
|
|
476
|
-
* @
|
|
482
|
+
* @returns {DateTime} A new DateTime instance.
|
|
477
483
|
*/
|
|
478
484
|
addDay() {
|
|
479
485
|
return this.addDays(1);
|
|
@@ -482,7 +488,7 @@ export default class DateTime {
|
|
|
482
488
|
/**
|
|
483
489
|
* Adds days to the current DateTime.
|
|
484
490
|
* @param {number} amount The number of days to add.
|
|
485
|
-
* @
|
|
491
|
+
* @returns {DateTime} A new DateTime instance.
|
|
486
492
|
*/
|
|
487
493
|
addDays(amount) {
|
|
488
494
|
return setOffsetTime(
|
|
@@ -496,7 +502,7 @@ export default class DateTime {
|
|
|
496
502
|
|
|
497
503
|
/**
|
|
498
504
|
* Adds an hour to the current DateTime.
|
|
499
|
-
* @
|
|
505
|
+
* @returns {DateTime} A new DateTime instance.
|
|
500
506
|
*/
|
|
501
507
|
addHour() {
|
|
502
508
|
return this.addHours(1);
|
|
@@ -505,7 +511,7 @@ export default class DateTime {
|
|
|
505
511
|
/**
|
|
506
512
|
* Adds hours to the current DateTime.
|
|
507
513
|
* @param {number} amount The number of hours to add.
|
|
508
|
-
* @
|
|
514
|
+
* @returns {DateTime} A new DateTime instance.
|
|
509
515
|
*/
|
|
510
516
|
addHours(amount) {
|
|
511
517
|
return this.withTime(
|
|
@@ -515,7 +521,7 @@ export default class DateTime {
|
|
|
515
521
|
|
|
516
522
|
/**
|
|
517
523
|
* Adds a minute to the current DateTime.
|
|
518
|
-
* @
|
|
524
|
+
* @returns {DateTime} A new DateTime instance.
|
|
519
525
|
*/
|
|
520
526
|
addMinute() {
|
|
521
527
|
return this.addMinutes(1);
|
|
@@ -524,7 +530,7 @@ export default class DateTime {
|
|
|
524
530
|
/**
|
|
525
531
|
* Adds minutes to the current DateTime.
|
|
526
532
|
* @param {number} amount The number of minutes to add.
|
|
527
|
-
* @
|
|
533
|
+
* @returns {DateTime} A new DateTime instance.
|
|
528
534
|
*/
|
|
529
535
|
addMinutes(amount) {
|
|
530
536
|
return this.withTime(
|
|
@@ -534,7 +540,7 @@ export default class DateTime {
|
|
|
534
540
|
|
|
535
541
|
/**
|
|
536
542
|
* Adds a month to the current DateTime.
|
|
537
|
-
* @
|
|
543
|
+
* @returns {DateTime} A new DateTime instance.
|
|
538
544
|
*/
|
|
539
545
|
addMonth() {
|
|
540
546
|
return this.addMonths(1);
|
|
@@ -543,7 +549,7 @@ export default class DateTime {
|
|
|
543
549
|
/**
|
|
544
550
|
* Adds months to the current DateTime.
|
|
545
551
|
* @param {number} amount The number of months to add.
|
|
546
|
-
* @
|
|
552
|
+
* @returns {DateTime} A new DateTime instance.
|
|
547
553
|
*/
|
|
548
554
|
addMonths(amount) {
|
|
549
555
|
return this.withMonth(
|
|
@@ -553,7 +559,7 @@ export default class DateTime {
|
|
|
553
559
|
|
|
554
560
|
/**
|
|
555
561
|
* Adds a second to the current DateTime.
|
|
556
|
-
* @
|
|
562
|
+
* @returns {DateTime} A new DateTime instance.
|
|
557
563
|
*/
|
|
558
564
|
addSecond() {
|
|
559
565
|
return this.addSeconds(1);
|
|
@@ -562,7 +568,7 @@ export default class DateTime {
|
|
|
562
568
|
/**
|
|
563
569
|
* Adds seconds to the current DateTime.
|
|
564
570
|
* @param {number} amount The number of seconds to add.
|
|
565
|
-
* @
|
|
571
|
+
* @returns {DateTime} A new DateTime instance.
|
|
566
572
|
*/
|
|
567
573
|
addSeconds(amount) {
|
|
568
574
|
return this.withTime(
|
|
@@ -572,7 +578,7 @@ export default class DateTime {
|
|
|
572
578
|
|
|
573
579
|
/**
|
|
574
580
|
* Adds a week to the current DateTime.
|
|
575
|
-
* @
|
|
581
|
+
* @returns {DateTime} A new DateTime instance.
|
|
576
582
|
*/
|
|
577
583
|
addWeek() {
|
|
578
584
|
return this.addWeeks(1);
|
|
@@ -581,7 +587,7 @@ export default class DateTime {
|
|
|
581
587
|
/**
|
|
582
588
|
* Adds weeks to the current DateTime.
|
|
583
589
|
* @param {number} amount The number of weeks to add.
|
|
584
|
-
* @
|
|
590
|
+
* @returns {DateTime} A new DateTime instance.
|
|
585
591
|
*/
|
|
586
592
|
addWeeks(amount) {
|
|
587
593
|
return this.withDate(
|
|
@@ -591,7 +597,7 @@ export default class DateTime {
|
|
|
591
597
|
|
|
592
598
|
/**
|
|
593
599
|
* Adds a year to the current DateTime.
|
|
594
|
-
* @
|
|
600
|
+
* @returns {DateTime} A new DateTime instance.
|
|
595
601
|
*/
|
|
596
602
|
addYear() {
|
|
597
603
|
return this.addYears(1);
|
|
@@ -600,7 +606,7 @@ export default class DateTime {
|
|
|
600
606
|
/**
|
|
601
607
|
* Adds years to the current DateTime.
|
|
602
608
|
* @param {number} amount The number of years to add.
|
|
603
|
-
* @
|
|
609
|
+
* @returns {DateTime} A new DateTime instance.
|
|
604
610
|
*/
|
|
605
611
|
addYears(amount) {
|
|
606
612
|
return this.withYear(
|
|
@@ -611,7 +617,7 @@ export default class DateTime {
|
|
|
611
617
|
/**
|
|
612
618
|
* Gets the localized day name for the current date.
|
|
613
619
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of day name to return.
|
|
614
|
-
* @
|
|
620
|
+
* @returns {string} The localized day name.
|
|
615
621
|
*/
|
|
616
622
|
dayName(type = 'long') {
|
|
617
623
|
return formatDay(this.getLocale(), this.getDay(), type);
|
|
@@ -620,7 +626,7 @@ export default class DateTime {
|
|
|
620
626
|
/**
|
|
621
627
|
* Gets the localized day period for the current time.
|
|
622
628
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of day period to return.
|
|
623
|
-
* @
|
|
629
|
+
* @returns {string} The localized day period.
|
|
624
630
|
*/
|
|
625
631
|
dayPeriod(type = 'long') {
|
|
626
632
|
return formatDayPeriod(
|
|
@@ -634,7 +640,7 @@ export default class DateTime {
|
|
|
634
640
|
|
|
635
641
|
/**
|
|
636
642
|
* Gets the number of days in the current month.
|
|
637
|
-
* @
|
|
643
|
+
* @returns {number} The number of days in the current month.
|
|
638
644
|
*/
|
|
639
645
|
daysInMonth() {
|
|
640
646
|
return this.constructor.daysInMonth(
|
|
@@ -645,7 +651,7 @@ export default class DateTime {
|
|
|
645
651
|
|
|
646
652
|
/**
|
|
647
653
|
* Gets the number of days in the current year.
|
|
648
|
-
* @
|
|
654
|
+
* @returns {number} The number of days in the current year.
|
|
649
655
|
*/
|
|
650
656
|
daysInYear() {
|
|
651
657
|
return this.constructor.daysInYear(
|
|
@@ -656,7 +662,7 @@ export default class DateTime {
|
|
|
656
662
|
/**
|
|
657
663
|
* Gets the difference between this and another Date in milliseconds.
|
|
658
664
|
* @param {DateTime} other The date to compare to.
|
|
659
|
-
* @
|
|
665
|
+
* @returns {number} The difference.
|
|
660
666
|
*/
|
|
661
667
|
diff(other) {
|
|
662
668
|
return this - other;
|
|
@@ -666,7 +672,7 @@ export default class DateTime {
|
|
|
666
672
|
* Gets the difference between this and another Date in days.
|
|
667
673
|
* @param {DateTime} other The date to compare to.
|
|
668
674
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
669
|
-
* @
|
|
675
|
+
* @returns {number} The difference.
|
|
670
676
|
*/
|
|
671
677
|
diffInDays(other, { relative = true } = {}) {
|
|
672
678
|
return calculateDiff(this, other, 'day', relative);
|
|
@@ -676,7 +682,7 @@ export default class DateTime {
|
|
|
676
682
|
* Gets the difference between this and another Date in hours.
|
|
677
683
|
* @param {DateTime} other The date to compare to.
|
|
678
684
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
679
|
-
* @
|
|
685
|
+
* @returns {number} The difference.
|
|
680
686
|
*/
|
|
681
687
|
diffInHours(other, { relative = true } = {}) {
|
|
682
688
|
return calculateDiff(this, other, 'hour', relative);
|
|
@@ -686,7 +692,7 @@ export default class DateTime {
|
|
|
686
692
|
* Gets the difference between this and another Date in minutes.
|
|
687
693
|
* @param {DateTime} other The date to compare to.
|
|
688
694
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
689
|
-
* @
|
|
695
|
+
* @returns {number} The difference.
|
|
690
696
|
*/
|
|
691
697
|
diffInMinutes(other, { relative = true } = {}) {
|
|
692
698
|
return calculateDiff(this, other, 'minute', relative);
|
|
@@ -696,7 +702,7 @@ export default class DateTime {
|
|
|
696
702
|
* Gets the difference between this and another Date in months.
|
|
697
703
|
* @param {DateTime} other The date to compare to.
|
|
698
704
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
699
|
-
* @
|
|
705
|
+
* @returns {number} The difference.
|
|
700
706
|
*/
|
|
701
707
|
diffInMonths(other, { relative = true } = {}) {
|
|
702
708
|
return calculateDiff(this, other, 'month', relative);
|
|
@@ -706,7 +712,7 @@ export default class DateTime {
|
|
|
706
712
|
* Gets the difference between this and another Date in seconds.
|
|
707
713
|
* @param {DateTime} other The date to compare to.
|
|
708
714
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
709
|
-
* @
|
|
715
|
+
* @returns {number} The difference.
|
|
710
716
|
*/
|
|
711
717
|
diffInSeconds(other, { relative = true } = {}) {
|
|
712
718
|
return calculateDiff(this, other, 'second', relative);
|
|
@@ -716,7 +722,7 @@ export default class DateTime {
|
|
|
716
722
|
* Gets the difference between this and another Date in weeks.
|
|
717
723
|
* @param {DateTime} other The date to compare to.
|
|
718
724
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
719
|
-
* @
|
|
725
|
+
* @returns {number} The difference.
|
|
720
726
|
*/
|
|
721
727
|
diffInWeeks(other, { relative = true } = {}) {
|
|
722
728
|
return calculateDiff(this, other, 'week', relative);
|
|
@@ -726,7 +732,7 @@ export default class DateTime {
|
|
|
726
732
|
* Gets the difference between this and another Date in years.
|
|
727
733
|
* @param {DateTime} other The date to compare to.
|
|
728
734
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
729
|
-
* @
|
|
735
|
+
* @returns {number} The difference.
|
|
730
736
|
*/
|
|
731
737
|
diffInYears(other, { relative = true } = {}) {
|
|
732
738
|
return calculateDiff(this, other, 'year', relative);
|
|
@@ -734,7 +740,7 @@ export default class DateTime {
|
|
|
734
740
|
|
|
735
741
|
/**
|
|
736
742
|
* Sets the DateTime to the end of the day.
|
|
737
|
-
* @
|
|
743
|
+
* @returns {DateTime} A new DateTime instance.
|
|
738
744
|
*/
|
|
739
745
|
endOfDay() {
|
|
740
746
|
return this.withHours(23, 59, 59, 999);
|
|
@@ -742,7 +748,7 @@ export default class DateTime {
|
|
|
742
748
|
|
|
743
749
|
/**
|
|
744
750
|
* Sets the DateTime to the end of the hour.
|
|
745
|
-
* @
|
|
751
|
+
* @returns {DateTime} A new DateTime instance.
|
|
746
752
|
*/
|
|
747
753
|
endOfHour() {
|
|
748
754
|
return this.withMinutes(59, 59, 999);
|
|
@@ -750,7 +756,7 @@ export default class DateTime {
|
|
|
750
756
|
|
|
751
757
|
/**
|
|
752
758
|
* Sets the DateTime to the end of the minute.
|
|
753
|
-
* @
|
|
759
|
+
* @returns {DateTime} A new DateTime instance.
|
|
754
760
|
*/
|
|
755
761
|
endOfMinute() {
|
|
756
762
|
return this.withSeconds(59, 999);
|
|
@@ -758,7 +764,7 @@ export default class DateTime {
|
|
|
758
764
|
|
|
759
765
|
/**
|
|
760
766
|
* Sets the DateTime to the end of the month.
|
|
761
|
-
* @
|
|
767
|
+
* @returns {DateTime} A new DateTime instance.
|
|
762
768
|
*/
|
|
763
769
|
endOfMonth() {
|
|
764
770
|
return this.withDate(this.daysInMonth())
|
|
@@ -767,7 +773,7 @@ export default class DateTime {
|
|
|
767
773
|
|
|
768
774
|
/**
|
|
769
775
|
* Sets the DateTime to the end of the quarter.
|
|
770
|
-
* @
|
|
776
|
+
* @returns {DateTime} A new DateTime instance.
|
|
771
777
|
*/
|
|
772
778
|
endOfQuarter() {
|
|
773
779
|
const month = this.getQuarter() * 3;
|
|
@@ -777,7 +783,7 @@ export default class DateTime {
|
|
|
777
783
|
|
|
778
784
|
/**
|
|
779
785
|
* Sets the DateTime to the end of the second.
|
|
780
|
-
* @
|
|
786
|
+
* @returns {DateTime} A new DateTime instance.
|
|
781
787
|
*/
|
|
782
788
|
endOfSecond() {
|
|
783
789
|
return this.withMilliseconds(999);
|
|
@@ -785,7 +791,7 @@ export default class DateTime {
|
|
|
785
791
|
|
|
786
792
|
/**
|
|
787
793
|
* Sets the DateTime to the end of the week.
|
|
788
|
-
* @
|
|
794
|
+
* @returns {DateTime} A new DateTime instance.
|
|
789
795
|
*/
|
|
790
796
|
endOfWeek() {
|
|
791
797
|
return this.withWeekDay(7)
|
|
@@ -794,7 +800,7 @@ export default class DateTime {
|
|
|
794
800
|
|
|
795
801
|
/**
|
|
796
802
|
* Sets the DateTime to the end of the year.
|
|
797
|
-
* @
|
|
803
|
+
* @returns {DateTime} A new DateTime instance.
|
|
798
804
|
*/
|
|
799
805
|
endOfYear() {
|
|
800
806
|
return this.withMonth(12, 31)
|
|
@@ -804,7 +810,7 @@ export default class DateTime {
|
|
|
804
810
|
/**
|
|
805
811
|
* Gets the localized era for the current date.
|
|
806
812
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of era to return.
|
|
807
|
-
* @
|
|
813
|
+
* @returns {string} The localized era.
|
|
808
814
|
*/
|
|
809
815
|
era(type = 'long') {
|
|
810
816
|
return formatEra(
|
|
@@ -819,7 +825,7 @@ export default class DateTime {
|
|
|
819
825
|
/**
|
|
820
826
|
* Formats the current date using a format string.
|
|
821
827
|
* @param {string} formatString The format string.
|
|
822
|
-
* @
|
|
828
|
+
* @returns {string} The formatted date string.
|
|
823
829
|
*/
|
|
824
830
|
format(formatString) {
|
|
825
831
|
let match;
|
|
@@ -859,7 +865,7 @@ export default class DateTime {
|
|
|
859
865
|
|
|
860
866
|
/**
|
|
861
867
|
* Gets the date of the month in the current time zone.
|
|
862
|
-
* @
|
|
868
|
+
* @returns {number} The date of the month.
|
|
863
869
|
*/
|
|
864
870
|
getDate() {
|
|
865
871
|
return new Date(getOffsetTime(this)).getUTCDate();
|
|
@@ -867,7 +873,7 @@ export default class DateTime {
|
|
|
867
873
|
|
|
868
874
|
/**
|
|
869
875
|
* Gets the day of the week in the current time zone.
|
|
870
|
-
* @
|
|
876
|
+
* @returns {number} The day of the week. (0 = Sunday, 6 = Saturday)
|
|
871
877
|
*/
|
|
872
878
|
getDay() {
|
|
873
879
|
return new Date(getOffsetTime(this)).getUTCDay();
|
|
@@ -875,7 +881,7 @@ export default class DateTime {
|
|
|
875
881
|
|
|
876
882
|
/**
|
|
877
883
|
* Gets the day of the year in the current time zone.
|
|
878
|
-
* @
|
|
884
|
+
* @returns {number} The day of the year. (1-366)
|
|
879
885
|
*/
|
|
880
886
|
getDayOfYear() {
|
|
881
887
|
return this.constructor.dayOfYear(
|
|
@@ -887,7 +893,7 @@ export default class DateTime {
|
|
|
887
893
|
|
|
888
894
|
/**
|
|
889
895
|
* Gets the hours of the day in the current time zone.
|
|
890
|
-
* @
|
|
896
|
+
* @returns {number} The hours of the day. (0-23)
|
|
891
897
|
*/
|
|
892
898
|
getHours() {
|
|
893
899
|
return new Date(getOffsetTime(this)).getUTCHours();
|
|
@@ -895,15 +901,15 @@ export default class DateTime {
|
|
|
895
901
|
|
|
896
902
|
/**
|
|
897
903
|
* Gets the current locale.
|
|
898
|
-
* @
|
|
904
|
+
* @returns {string} The locale.
|
|
899
905
|
*/
|
|
900
906
|
getLocale() {
|
|
901
|
-
return this
|
|
907
|
+
return this.#locale;
|
|
902
908
|
}
|
|
903
909
|
|
|
904
910
|
/**
|
|
905
911
|
* Gets the milliseconds in the current time zone.
|
|
906
|
-
* @
|
|
912
|
+
* @returns {number} The milliseconds.
|
|
907
913
|
*/
|
|
908
914
|
getMilliseconds() {
|
|
909
915
|
return new Date(getOffsetTime(this)).getUTCMilliseconds();
|
|
@@ -911,7 +917,7 @@ export default class DateTime {
|
|
|
911
917
|
|
|
912
918
|
/**
|
|
913
919
|
* Gets the minutes in the current time zone.
|
|
914
|
-
* @
|
|
920
|
+
* @returns {number} The minutes. (0-59)
|
|
915
921
|
*/
|
|
916
922
|
getMinutes() {
|
|
917
923
|
return new Date(getOffsetTime(this)).getUTCMinutes();
|
|
@@ -919,7 +925,7 @@ export default class DateTime {
|
|
|
919
925
|
|
|
920
926
|
/**
|
|
921
927
|
* Gets the month in the current time zone.
|
|
922
|
-
* @
|
|
928
|
+
* @returns {number} The month. (1-12)
|
|
923
929
|
*/
|
|
924
930
|
getMonth() {
|
|
925
931
|
return new Date(getOffsetTime(this)).getUTCMonth() + 1;
|
|
@@ -927,7 +933,7 @@ export default class DateTime {
|
|
|
927
933
|
|
|
928
934
|
/**
|
|
929
935
|
* Gets the quarter of the year in the current time zone.
|
|
930
|
-
* @
|
|
936
|
+
* @returns {number} The quarter of the year. (1-4)
|
|
931
937
|
*/
|
|
932
938
|
getQuarter() {
|
|
933
939
|
return Math.ceil(this.getMonth() / 3);
|
|
@@ -935,7 +941,7 @@ export default class DateTime {
|
|
|
935
941
|
|
|
936
942
|
/**
|
|
937
943
|
* Gets the seconds in the current time zone.
|
|
938
|
-
* @
|
|
944
|
+
* @returns {number} The seconds. (0-59)
|
|
939
945
|
*/
|
|
940
946
|
getSeconds() {
|
|
941
947
|
return new Date(getOffsetTime(this)).getUTCSeconds();
|
|
@@ -943,15 +949,15 @@ export default class DateTime {
|
|
|
943
949
|
|
|
944
950
|
/**
|
|
945
951
|
* Gets the number of milliseconds since the UNIX epoch.
|
|
946
|
-
* @
|
|
952
|
+
* @returns {number} The number of milliseconds since the UNIX epoch.
|
|
947
953
|
*/
|
|
948
954
|
getTime() {
|
|
949
|
-
return this.
|
|
955
|
+
return this.#date.getTime();
|
|
950
956
|
}
|
|
951
957
|
|
|
952
958
|
/**
|
|
953
959
|
* Gets the number of seconds since the UNIX epoch.
|
|
954
|
-
* @
|
|
960
|
+
* @returns {number} The number of seconds since the UNIX epoch.
|
|
955
961
|
*/
|
|
956
962
|
getTimestamp() {
|
|
957
963
|
return Math.floor(this.getTime() / 1000);
|
|
@@ -959,23 +965,23 @@ export default class DateTime {
|
|
|
959
965
|
|
|
960
966
|
/**
|
|
961
967
|
* Gets the current time zone.
|
|
962
|
-
* @
|
|
968
|
+
* @returns {string} The time zone.
|
|
963
969
|
*/
|
|
964
970
|
getTimeZone() {
|
|
965
|
-
return this
|
|
971
|
+
return this.#timeZone;
|
|
966
972
|
}
|
|
967
973
|
|
|
968
974
|
/**
|
|
969
975
|
* Gets the current UTC offset in minutes.
|
|
970
|
-
* @
|
|
976
|
+
* @returns {number} The UTC offset in minutes.
|
|
971
977
|
*/
|
|
972
978
|
getTimeZoneOffset() {
|
|
973
|
-
return this
|
|
979
|
+
return this.#offset;
|
|
974
980
|
}
|
|
975
981
|
|
|
976
982
|
/**
|
|
977
983
|
* Gets the local week in the current time zone.
|
|
978
|
-
* @
|
|
984
|
+
* @returns {number} The local week. (1-53)
|
|
979
985
|
*/
|
|
980
986
|
getWeek() {
|
|
981
987
|
const thisWeek = this.startOfDay().withWeekDay(1);
|
|
@@ -989,7 +995,7 @@ export default class DateTime {
|
|
|
989
995
|
|
|
990
996
|
/**
|
|
991
997
|
* Gets the local day of the week in the current time zone.
|
|
992
|
-
* @
|
|
998
|
+
* @returns {number} The local day of the week. (1-7)
|
|
993
999
|
*/
|
|
994
1000
|
getWeekDay() {
|
|
995
1001
|
return weekDay(
|
|
@@ -1000,7 +1006,7 @@ export default class DateTime {
|
|
|
1000
1006
|
|
|
1001
1007
|
/**
|
|
1002
1008
|
* Gets the week day in month in the current time zone.
|
|
1003
|
-
* @
|
|
1009
|
+
* @returns {number} The week day in month.
|
|
1004
1010
|
*/
|
|
1005
1011
|
getWeekDayInMonth() {
|
|
1006
1012
|
const thisWeek = this.getWeek();
|
|
@@ -1015,7 +1021,7 @@ export default class DateTime {
|
|
|
1015
1021
|
|
|
1016
1022
|
/**
|
|
1017
1023
|
* Gets the week of month in the current time zone.
|
|
1018
|
-
* @
|
|
1024
|
+
* @returns {number} The week of month.
|
|
1019
1025
|
*/
|
|
1020
1026
|
getWeekOfMonth() {
|
|
1021
1027
|
const thisWeek = this.getWeek();
|
|
@@ -1027,7 +1033,7 @@ export default class DateTime {
|
|
|
1027
1033
|
|
|
1028
1034
|
/**
|
|
1029
1035
|
* Gets the week year in the current time zone.
|
|
1030
|
-
* @
|
|
1036
|
+
* @returns {number} The week year.
|
|
1031
1037
|
*/
|
|
1032
1038
|
getWeekYear() {
|
|
1033
1039
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -1036,7 +1042,7 @@ export default class DateTime {
|
|
|
1036
1042
|
|
|
1037
1043
|
/**
|
|
1038
1044
|
* Gets the year in the current time zone.
|
|
1039
|
-
* @
|
|
1045
|
+
* @returns {number} The year.
|
|
1040
1046
|
*/
|
|
1041
1047
|
getYear() {
|
|
1042
1048
|
return new Date(getOffsetTime(this)).getUTCFullYear();
|
|
@@ -1045,7 +1051,7 @@ export default class DateTime {
|
|
|
1045
1051
|
/**
|
|
1046
1052
|
* Gets the difference between this and another Date in human readable form.
|
|
1047
1053
|
* @param {DateTime} other The date to compare to.
|
|
1048
|
-
* @
|
|
1054
|
+
* @returns {string} The difference in human readable form.
|
|
1049
1055
|
*/
|
|
1050
1056
|
humanDiff(other) {
|
|
1051
1057
|
const [amount, unit] = getBiggestDiff(this, other);
|
|
@@ -1055,7 +1061,7 @@ export default class DateTime {
|
|
|
1055
1061
|
/**
|
|
1056
1062
|
* Gets the difference between this and another Date in days in human readable form.
|
|
1057
1063
|
* @param {DateTime} other The date to compare to.
|
|
1058
|
-
* @
|
|
1064
|
+
* @returns {string} The difference in days in human readable form.
|
|
1059
1065
|
*/
|
|
1060
1066
|
humanDiffInDays(other) {
|
|
1061
1067
|
return formatRelative(this.getLocale(), this.diffInDays(other), 'day');
|
|
@@ -1064,7 +1070,7 @@ export default class DateTime {
|
|
|
1064
1070
|
/**
|
|
1065
1071
|
* Gets the difference between this and another Date in hours in human readable form.
|
|
1066
1072
|
* @param {DateTime} other The date to compare to.
|
|
1067
|
-
* @
|
|
1073
|
+
* @returns {string} The difference in hours in human readable form.
|
|
1068
1074
|
*/
|
|
1069
1075
|
humanDiffInHours(other) {
|
|
1070
1076
|
return formatRelative(this.getLocale(), this.diffInHours(other), 'hour');
|
|
@@ -1073,7 +1079,7 @@ export default class DateTime {
|
|
|
1073
1079
|
/**
|
|
1074
1080
|
* Gets the difference between this and another Date in minutes in human readable form.
|
|
1075
1081
|
* @param {DateTime} other The date to compare to.
|
|
1076
|
-
* @
|
|
1082
|
+
* @returns {string} The difference in minutes in human readable form.
|
|
1077
1083
|
*/
|
|
1078
1084
|
humanDiffInMinutes(other) {
|
|
1079
1085
|
return formatRelative(this.getLocale(), this.diffInMinutes(other), 'minute');
|
|
@@ -1082,7 +1088,7 @@ export default class DateTime {
|
|
|
1082
1088
|
/**
|
|
1083
1089
|
* Gets the difference between this and another Date in months in human readable form.
|
|
1084
1090
|
* @param {DateTime} other The date to compare to.
|
|
1085
|
-
* @
|
|
1091
|
+
* @returns {string} The difference in months in human readable form.
|
|
1086
1092
|
*/
|
|
1087
1093
|
humanDiffInMonths(other) {
|
|
1088
1094
|
return formatRelative(this.getLocale(), this.diffInMonths(other), 'month');
|
|
@@ -1091,7 +1097,7 @@ export default class DateTime {
|
|
|
1091
1097
|
/**
|
|
1092
1098
|
* Gets the difference between this and another Date in seconds in human readable form.
|
|
1093
1099
|
* @param {DateTime} other The date to compare to.
|
|
1094
|
-
* @
|
|
1100
|
+
* @returns {string} The difference in seconds in human readable form.
|
|
1095
1101
|
*/
|
|
1096
1102
|
humanDiffInSeconds(other) {
|
|
1097
1103
|
return formatRelative(this.getLocale(), this.diffInSeconds(other), 'second');
|
|
@@ -1100,7 +1106,7 @@ export default class DateTime {
|
|
|
1100
1106
|
/**
|
|
1101
1107
|
* Gets the difference between this and another Date in weeks in human readable form.
|
|
1102
1108
|
* @param {DateTime} other The date to compare to.
|
|
1103
|
-
* @
|
|
1109
|
+
* @returns {string} The difference in weeks in human readable form.
|
|
1104
1110
|
*/
|
|
1105
1111
|
humanDiffInWeeks(other) {
|
|
1106
1112
|
return formatRelative(this.getLocale(), this.diffInWeeks(other), 'week');
|
|
@@ -1109,7 +1115,7 @@ export default class DateTime {
|
|
|
1109
1115
|
/**
|
|
1110
1116
|
* Gets the difference between this and another Date in years in human readable form.
|
|
1111
1117
|
* @param {DateTime} other The date to compare to.
|
|
1112
|
-
* @
|
|
1118
|
+
* @returns {string} The difference in years in human readable form.
|
|
1113
1119
|
*/
|
|
1114
1120
|
humanDiffInYears(other) {
|
|
1115
1121
|
return formatRelative(this.getLocale(), this.diffInYears(other), 'year');
|
|
@@ -1118,7 +1124,7 @@ export default class DateTime {
|
|
|
1118
1124
|
/**
|
|
1119
1125
|
* Checks whether this DateTime is after another date.
|
|
1120
1126
|
* @param {DateTime} other The date to compare to.
|
|
1121
|
-
* @
|
|
1127
|
+
* @returns {boolean} Whether this DateTime is after the other date.
|
|
1122
1128
|
*/
|
|
1123
1129
|
isAfter(other) {
|
|
1124
1130
|
return this.diff(other) > 0;
|
|
@@ -1127,7 +1133,7 @@ export default class DateTime {
|
|
|
1127
1133
|
/**
|
|
1128
1134
|
* Checks whether this DateTime is after another date (comparing by day).
|
|
1129
1135
|
* @param {DateTime} other The date to compare to.
|
|
1130
|
-
* @
|
|
1136
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by day).
|
|
1131
1137
|
*/
|
|
1132
1138
|
isAfterDay(other) {
|
|
1133
1139
|
return this.diffInDays(other) > 0;
|
|
@@ -1136,7 +1142,7 @@ export default class DateTime {
|
|
|
1136
1142
|
/**
|
|
1137
1143
|
* Checks whether this DateTime is after another date (comparing by hour).
|
|
1138
1144
|
* @param {DateTime} other The date to compare to.
|
|
1139
|
-
* @
|
|
1145
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by hour).
|
|
1140
1146
|
*/
|
|
1141
1147
|
isAfterHour(other) {
|
|
1142
1148
|
return this.diffInHours(other) > 0;
|
|
@@ -1145,7 +1151,7 @@ export default class DateTime {
|
|
|
1145
1151
|
/**
|
|
1146
1152
|
* Checks whether this DateTime is after another date (comparing by minute).
|
|
1147
1153
|
* @param {DateTime} other The date to compare to.
|
|
1148
|
-
* @
|
|
1154
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by minute).
|
|
1149
1155
|
*/
|
|
1150
1156
|
isAfterMinute(other) {
|
|
1151
1157
|
return this.diffInMinutes(other) > 0;
|
|
@@ -1154,7 +1160,7 @@ export default class DateTime {
|
|
|
1154
1160
|
/**
|
|
1155
1161
|
* Checks whether this DateTime is after another date (comparing by month).
|
|
1156
1162
|
* @param {DateTime} other The date to compare to.
|
|
1157
|
-
* @
|
|
1163
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by month).
|
|
1158
1164
|
*/
|
|
1159
1165
|
isAfterMonth(other) {
|
|
1160
1166
|
return this.diffInMonths(other) > 0;
|
|
@@ -1163,7 +1169,7 @@ export default class DateTime {
|
|
|
1163
1169
|
/**
|
|
1164
1170
|
* Checks whether this DateTime is after another date (comparing by second).
|
|
1165
1171
|
* @param {DateTime} other The date to compare to.
|
|
1166
|
-
* @
|
|
1172
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by second).
|
|
1167
1173
|
*/
|
|
1168
1174
|
isAfterSecond(other) {
|
|
1169
1175
|
return this.diffInSeconds(other) > 0;
|
|
@@ -1172,7 +1178,7 @@ export default class DateTime {
|
|
|
1172
1178
|
/**
|
|
1173
1179
|
* Checks whether this DateTime is after another date (comparing by week).
|
|
1174
1180
|
* @param {DateTime} other The date to compare to.
|
|
1175
|
-
* @
|
|
1181
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by week).
|
|
1176
1182
|
*/
|
|
1177
1183
|
isAfterWeek(other) {
|
|
1178
1184
|
return this.diffInWeeks(other) > 0;
|
|
@@ -1181,7 +1187,7 @@ export default class DateTime {
|
|
|
1181
1187
|
/**
|
|
1182
1188
|
* Checks whether this DateTime is after another date (comparing by year).
|
|
1183
1189
|
* @param {DateTime} other The date to compare to.
|
|
1184
|
-
* @
|
|
1190
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by year).
|
|
1185
1191
|
*/
|
|
1186
1192
|
isAfterYear(other) {
|
|
1187
1193
|
return this.diffInYears(other) > 0;
|
|
@@ -1190,7 +1196,7 @@ export default class DateTime {
|
|
|
1190
1196
|
/**
|
|
1191
1197
|
* Checks whether this DateTime is before another date.
|
|
1192
1198
|
* @param {DateTime} other The date to compare to.
|
|
1193
|
-
* @
|
|
1199
|
+
* @returns {boolean} Whether this DateTime is before the other date.
|
|
1194
1200
|
*/
|
|
1195
1201
|
isBefore(other) {
|
|
1196
1202
|
return this.diff(other) < 0;
|
|
@@ -1199,7 +1205,7 @@ export default class DateTime {
|
|
|
1199
1205
|
/**
|
|
1200
1206
|
* Checks whether this DateTime is before another date (comparing by day).
|
|
1201
1207
|
* @param {DateTime} other The date to compare to.
|
|
1202
|
-
* @
|
|
1208
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by day).
|
|
1203
1209
|
*/
|
|
1204
1210
|
isBeforeDay(other) {
|
|
1205
1211
|
return this.diffInDays(other) < 0;
|
|
@@ -1208,7 +1214,7 @@ export default class DateTime {
|
|
|
1208
1214
|
/**
|
|
1209
1215
|
* Checks whether this DateTime is before another date (comparing by hour).
|
|
1210
1216
|
* @param {DateTime} other The date to compare to.
|
|
1211
|
-
* @
|
|
1217
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by hour).
|
|
1212
1218
|
*/
|
|
1213
1219
|
isBeforeHour(other) {
|
|
1214
1220
|
return this.diffInHours(other) < 0;
|
|
@@ -1217,7 +1223,7 @@ export default class DateTime {
|
|
|
1217
1223
|
/**
|
|
1218
1224
|
* Checks whether this DateTime is before another date (comparing by minute).
|
|
1219
1225
|
* @param {DateTime} other The date to compare to.
|
|
1220
|
-
* @
|
|
1226
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by minute).
|
|
1221
1227
|
*/
|
|
1222
1228
|
isBeforeMinute(other) {
|
|
1223
1229
|
return this.diffInMinutes(other) < 0;
|
|
@@ -1226,7 +1232,7 @@ export default class DateTime {
|
|
|
1226
1232
|
/**
|
|
1227
1233
|
* Checks whether this DateTime is before another date (comparing by month).
|
|
1228
1234
|
* @param {DateTime} other The date to compare to.
|
|
1229
|
-
* @
|
|
1235
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by month).
|
|
1230
1236
|
*/
|
|
1231
1237
|
isBeforeMonth(other) {
|
|
1232
1238
|
return this.diffInMonths(other) < 0;
|
|
@@ -1235,7 +1241,7 @@ export default class DateTime {
|
|
|
1235
1241
|
/**
|
|
1236
1242
|
* Checks whether this DateTime is before another date (comparing by second).
|
|
1237
1243
|
* @param {DateTime} other The date to compare to.
|
|
1238
|
-
* @
|
|
1244
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by second).
|
|
1239
1245
|
*/
|
|
1240
1246
|
isBeforeSecond(other) {
|
|
1241
1247
|
return this.diffInSeconds(other) < 0;
|
|
@@ -1244,7 +1250,7 @@ export default class DateTime {
|
|
|
1244
1250
|
/**
|
|
1245
1251
|
* Checks whether this DateTime is before another date (comparing by week).
|
|
1246
1252
|
* @param {DateTime} other The date to compare to.
|
|
1247
|
-
* @
|
|
1253
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by week).
|
|
1248
1254
|
*/
|
|
1249
1255
|
isBeforeWeek(other) {
|
|
1250
1256
|
return this.diffInWeeks(other) < 0;
|
|
@@ -1253,7 +1259,7 @@ export default class DateTime {
|
|
|
1253
1259
|
/**
|
|
1254
1260
|
* Checks whether this DateTime is before another date (comparing by year).
|
|
1255
1261
|
* @param {DateTime} other The date to compare to.
|
|
1256
|
-
* @
|
|
1262
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by year).
|
|
1257
1263
|
*/
|
|
1258
1264
|
isBeforeYear(other) {
|
|
1259
1265
|
return this.diffInYears(other) < 0;
|
|
@@ -1263,7 +1269,7 @@ export default class DateTime {
|
|
|
1263
1269
|
* Checks whether this DateTime is between two other dates.
|
|
1264
1270
|
* @param {DateTime} start The first date to compare to.
|
|
1265
1271
|
* @param {DateTime} end The second date to compare to.
|
|
1266
|
-
* @
|
|
1272
|
+
* @returns {boolean} Whether this DateTime is between two other dates.
|
|
1267
1273
|
*/
|
|
1268
1274
|
isBetween(start, end) {
|
|
1269
1275
|
return this.isAfter(start) && this.isBefore(end);
|
|
@@ -1273,7 +1279,7 @@ export default class DateTime {
|
|
|
1273
1279
|
* Checks whether this DateTime is between two other dates (comparing by day).
|
|
1274
1280
|
* @param {DateTime} start The first date to compare to.
|
|
1275
1281
|
* @param {DateTime} end The second date to compare to.
|
|
1276
|
-
* @
|
|
1282
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by day).
|
|
1277
1283
|
*/
|
|
1278
1284
|
isBetweenDay(start, end) {
|
|
1279
1285
|
return this.isAfterDay(start) && this.isBeforeDay(end);
|
|
@@ -1283,7 +1289,7 @@ export default class DateTime {
|
|
|
1283
1289
|
* Checks whether this DateTime is between two other dates (comparing by hour).
|
|
1284
1290
|
* @param {DateTime} start The first date to compare to.
|
|
1285
1291
|
* @param {DateTime} end The second date to compare to.
|
|
1286
|
-
* @
|
|
1292
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by hour).
|
|
1287
1293
|
*/
|
|
1288
1294
|
isBetweenHour(start, end) {
|
|
1289
1295
|
return this.isAfterHour(start) && this.isBeforeHour(end);
|
|
@@ -1293,7 +1299,7 @@ export default class DateTime {
|
|
|
1293
1299
|
* Checks whether this DateTime is between two other dates (comparing by minute).
|
|
1294
1300
|
* @param {DateTime} start The first date to compare to.
|
|
1295
1301
|
* @param {DateTime} end The second date to compare to.
|
|
1296
|
-
* @
|
|
1302
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by minute).
|
|
1297
1303
|
*/
|
|
1298
1304
|
isBetweenMinute(start, end) {
|
|
1299
1305
|
return this.isAfterMinute(start) && this.isBeforeMinute(end);
|
|
@@ -1303,7 +1309,7 @@ export default class DateTime {
|
|
|
1303
1309
|
* Checks whether this DateTime is between two other dates (comparing by month).
|
|
1304
1310
|
* @param {DateTime} start The first date to compare to.
|
|
1305
1311
|
* @param {DateTime} end The second date to compare to.
|
|
1306
|
-
* @
|
|
1312
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by month).
|
|
1307
1313
|
*/
|
|
1308
1314
|
isBetweenMonth(start, end) {
|
|
1309
1315
|
return this.isAfterMonth(start) && this.isBeforeMonth(end);
|
|
@@ -1313,7 +1319,7 @@ export default class DateTime {
|
|
|
1313
1319
|
* Checks whether this DateTime is between two other dates (comparing by second).
|
|
1314
1320
|
* @param {DateTime} start The first date to compare to.
|
|
1315
1321
|
* @param {DateTime} end The second date to compare to.
|
|
1316
|
-
* @
|
|
1322
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by second).
|
|
1317
1323
|
*/
|
|
1318
1324
|
isBetweenSecond(start, end) {
|
|
1319
1325
|
return this.isAfterSecond(start) && this.isBeforeSecond(end);
|
|
@@ -1323,7 +1329,7 @@ export default class DateTime {
|
|
|
1323
1329
|
* Checks whether this DateTime is between two other dates (comparing by week).
|
|
1324
1330
|
* @param {DateTime} start The first date to compare to.
|
|
1325
1331
|
* @param {DateTime} end The second date to compare to.
|
|
1326
|
-
* @
|
|
1332
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by week).
|
|
1327
1333
|
*/
|
|
1328
1334
|
isBetweenWeek(start, end) {
|
|
1329
1335
|
return this.isAfterWeek(start) && this.isBeforeWeek(end);
|
|
@@ -1333,7 +1339,7 @@ export default class DateTime {
|
|
|
1333
1339
|
* Checks whether this DateTime is between two other dates (comparing by year).
|
|
1334
1340
|
* @param {DateTime} start The first date to compare to.
|
|
1335
1341
|
* @param {DateTime} end The second date to compare to.
|
|
1336
|
-
* @
|
|
1342
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by year).
|
|
1337
1343
|
*/
|
|
1338
1344
|
isBetweenYear(start, end) {
|
|
1339
1345
|
return this.isAfterYear(start) && this.isBeforeYear(end);
|
|
@@ -1341,10 +1347,10 @@ export default class DateTime {
|
|
|
1341
1347
|
|
|
1342
1348
|
/**
|
|
1343
1349
|
* Checks whether the DateTime is in daylight saving time.
|
|
1344
|
-
* @
|
|
1350
|
+
* @returns {boolean} Whether the current time is in daylight saving time.
|
|
1345
1351
|
*/
|
|
1346
1352
|
isDst() {
|
|
1347
|
-
if (!this
|
|
1353
|
+
if (!this.#dynamicTz) {
|
|
1348
1354
|
return false;
|
|
1349
1355
|
}
|
|
1350
1356
|
|
|
@@ -1361,7 +1367,7 @@ export default class DateTime {
|
|
|
1361
1367
|
|
|
1362
1368
|
/**
|
|
1363
1369
|
* Checks whether the year is a leap year.
|
|
1364
|
-
* @
|
|
1370
|
+
* @returns {boolean} Whether the current year is a leap year.
|
|
1365
1371
|
*/
|
|
1366
1372
|
isLeapYear() {
|
|
1367
1373
|
return this.constructor.isLeapYear(
|
|
@@ -1372,7 +1378,7 @@ export default class DateTime {
|
|
|
1372
1378
|
/**
|
|
1373
1379
|
* Checks whether this DateTime is the same as another date.
|
|
1374
1380
|
* @param {DateTime} other The date to compare to.
|
|
1375
|
-
* @
|
|
1381
|
+
* @returns {boolean} Whether this DateTime is the same as the other date.
|
|
1376
1382
|
*/
|
|
1377
1383
|
isSame(other) {
|
|
1378
1384
|
return this.diff(other) === 0;
|
|
@@ -1381,7 +1387,7 @@ export default class DateTime {
|
|
|
1381
1387
|
/**
|
|
1382
1388
|
* Checks whether this DateTime is the same as another date (comparing by day).
|
|
1383
1389
|
* @param {DateTime} other The date to compare to.
|
|
1384
|
-
* @
|
|
1390
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by day).
|
|
1385
1391
|
*/
|
|
1386
1392
|
isSameDay(other) {
|
|
1387
1393
|
return this.diffInDays(other) === 0;
|
|
@@ -1390,7 +1396,7 @@ export default class DateTime {
|
|
|
1390
1396
|
/**
|
|
1391
1397
|
* Checks whether this DateTime is the same as another date (comparing by hour).
|
|
1392
1398
|
* @param {DateTime} other The date to compare to.
|
|
1393
|
-
* @
|
|
1399
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by hour).
|
|
1394
1400
|
*/
|
|
1395
1401
|
isSameHour(other) {
|
|
1396
1402
|
return this.diffInHours(other) === 0;
|
|
@@ -1399,7 +1405,7 @@ export default class DateTime {
|
|
|
1399
1405
|
/**
|
|
1400
1406
|
* Checks whether this DateTime is the same as another date (comparing by minute).
|
|
1401
1407
|
* @param {DateTime} other The date to compare to.
|
|
1402
|
-
* @
|
|
1408
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by minute).
|
|
1403
1409
|
*/
|
|
1404
1410
|
isSameMinute(other) {
|
|
1405
1411
|
return this.diffInMinutes(other) === 0;
|
|
@@ -1408,7 +1414,7 @@ export default class DateTime {
|
|
|
1408
1414
|
/**
|
|
1409
1415
|
* Checks whether this DateTime is the same as another date (comparing by month).
|
|
1410
1416
|
* @param {DateTime} other The date to compare to.
|
|
1411
|
-
* @
|
|
1417
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by month).
|
|
1412
1418
|
*/
|
|
1413
1419
|
isSameMonth(other) {
|
|
1414
1420
|
return this.diffInMonths(other) === 0;
|
|
@@ -1417,7 +1423,7 @@ export default class DateTime {
|
|
|
1417
1423
|
/**
|
|
1418
1424
|
* Checks whether this DateTime is the same as or after another date.
|
|
1419
1425
|
* @param {DateTime} other The date to compare to.
|
|
1420
|
-
* @
|
|
1426
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date.
|
|
1421
1427
|
*/
|
|
1422
1428
|
isSameOrAfter(other) {
|
|
1423
1429
|
return this.diff(other) >= 0;
|
|
@@ -1426,7 +1432,7 @@ export default class DateTime {
|
|
|
1426
1432
|
/**
|
|
1427
1433
|
* Checks whether this DateTime is the same as or after another date (comparing by day).
|
|
1428
1434
|
* @param {DateTime} other The date to compare to.
|
|
1429
|
-
* @
|
|
1435
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by day).
|
|
1430
1436
|
*/
|
|
1431
1437
|
isSameOrAfterDay(other) {
|
|
1432
1438
|
return this.diffInDays(other) >= 0;
|
|
@@ -1435,7 +1441,7 @@ export default class DateTime {
|
|
|
1435
1441
|
/**
|
|
1436
1442
|
* Checks whether this DateTime is the same as or after another date (comparing by hour).
|
|
1437
1443
|
* @param {DateTime} other The date to compare to.
|
|
1438
|
-
* @
|
|
1444
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by hour).
|
|
1439
1445
|
*/
|
|
1440
1446
|
isSameOrAfterHour(other) {
|
|
1441
1447
|
return this.diffInHours(other) >= 0;
|
|
@@ -1444,7 +1450,7 @@ export default class DateTime {
|
|
|
1444
1450
|
/**
|
|
1445
1451
|
* Checks whether this DateTime is the same as or after another date (comparing by minute).
|
|
1446
1452
|
* @param {DateTime} other The date to compare to.
|
|
1447
|
-
* @
|
|
1453
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by minute).
|
|
1448
1454
|
*/
|
|
1449
1455
|
isSameOrAfterMinute(other) {
|
|
1450
1456
|
return this.diffInMinutes(other) >= 0;
|
|
@@ -1453,7 +1459,7 @@ export default class DateTime {
|
|
|
1453
1459
|
/**
|
|
1454
1460
|
* Checks whether this DateTime is the same as or after another date (comparing by month).
|
|
1455
1461
|
* @param {DateTime} other The date to compare to.
|
|
1456
|
-
* @
|
|
1462
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by month).
|
|
1457
1463
|
*/
|
|
1458
1464
|
isSameOrAfterMonth(other) {
|
|
1459
1465
|
return this.diffInMonths(other) >= 0;
|
|
@@ -1462,7 +1468,7 @@ export default class DateTime {
|
|
|
1462
1468
|
/**
|
|
1463
1469
|
* Checks whether this DateTime is the same as or after another date (comparing by second).
|
|
1464
1470
|
* @param {DateTime} other The date to compare to.
|
|
1465
|
-
* @
|
|
1471
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by second).
|
|
1466
1472
|
*/
|
|
1467
1473
|
isSameOrAfterSecond(other) {
|
|
1468
1474
|
return this.diffInSeconds(other) >= 0;
|
|
@@ -1471,7 +1477,7 @@ export default class DateTime {
|
|
|
1471
1477
|
/**
|
|
1472
1478
|
* Checks whether this DateTime is the same as or after another date (comparing by week).
|
|
1473
1479
|
* @param {DateTime} other The date to compare to.
|
|
1474
|
-
* @
|
|
1480
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by week).
|
|
1475
1481
|
*/
|
|
1476
1482
|
isSameOrAfterWeek(other) {
|
|
1477
1483
|
return this.diffInWeeks(other) >= 0;
|
|
@@ -1480,7 +1486,7 @@ export default class DateTime {
|
|
|
1480
1486
|
/**
|
|
1481
1487
|
* Checks whether this DateTime is the same as or after another date (comparing by year).
|
|
1482
1488
|
* @param {DateTime} other The date to compare to.
|
|
1483
|
-
* @
|
|
1489
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by year).
|
|
1484
1490
|
*/
|
|
1485
1491
|
isSameOrAfterYear(other) {
|
|
1486
1492
|
return this.diffInYears(other) >= 0;
|
|
@@ -1489,7 +1495,7 @@ export default class DateTime {
|
|
|
1489
1495
|
/**
|
|
1490
1496
|
* Checks whether this DateTime is the same as or before another date.
|
|
1491
1497
|
* @param {DateTime} other The date to compare to.
|
|
1492
|
-
* @
|
|
1498
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date.
|
|
1493
1499
|
*/
|
|
1494
1500
|
isSameOrBefore(other) {
|
|
1495
1501
|
return this.diff(other) <= 0;
|
|
@@ -1498,7 +1504,7 @@ export default class DateTime {
|
|
|
1498
1504
|
/**
|
|
1499
1505
|
* Checks whether this DateTime is the same as or before another date (comparing by day).
|
|
1500
1506
|
* @param {DateTime} other The date to compare to.
|
|
1501
|
-
* @
|
|
1507
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by day).
|
|
1502
1508
|
*/
|
|
1503
1509
|
isSameOrBeforeDay(other) {
|
|
1504
1510
|
return this.diffInDays(other) <= 0;
|
|
@@ -1507,7 +1513,7 @@ export default class DateTime {
|
|
|
1507
1513
|
/**
|
|
1508
1514
|
* Checks whether this DateTime is the same as or before another date (comparing by hour).
|
|
1509
1515
|
* @param {DateTime} other The date to compare to.
|
|
1510
|
-
* @
|
|
1516
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by hour).
|
|
1511
1517
|
*/
|
|
1512
1518
|
isSameOrBeforeHour(other) {
|
|
1513
1519
|
return this.diffInHours(other) <= 0;
|
|
@@ -1516,7 +1522,7 @@ export default class DateTime {
|
|
|
1516
1522
|
/**
|
|
1517
1523
|
* Checks whether this DateTime is the same as or before another date (comparing by minute).
|
|
1518
1524
|
* @param {DateTime} other The date to compare to.
|
|
1519
|
-
* @
|
|
1525
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by minute).
|
|
1520
1526
|
*/
|
|
1521
1527
|
isSameOrBeforeMinute(other) {
|
|
1522
1528
|
return this.diffInMinutes(other) <= 0;
|
|
@@ -1525,7 +1531,7 @@ export default class DateTime {
|
|
|
1525
1531
|
/**
|
|
1526
1532
|
* Checks whether this DateTime is the same as or before another date (comparing by month).
|
|
1527
1533
|
* @param {DateTime} other The date to compare to.
|
|
1528
|
-
* @
|
|
1534
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by month).
|
|
1529
1535
|
*/
|
|
1530
1536
|
isSameOrBeforeMonth(other) {
|
|
1531
1537
|
return this.diffInMonths(other) <= 0;
|
|
@@ -1534,7 +1540,7 @@ export default class DateTime {
|
|
|
1534
1540
|
/**
|
|
1535
1541
|
* Checks whether this DateTime is the same as or before another date (comparing by second).
|
|
1536
1542
|
* @param {DateTime} other The date to compare to.
|
|
1537
|
-
* @
|
|
1543
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by second).
|
|
1538
1544
|
*/
|
|
1539
1545
|
isSameOrBeforeSecond(other) {
|
|
1540
1546
|
return this.diffInSeconds(other) <= 0;
|
|
@@ -1543,7 +1549,7 @@ export default class DateTime {
|
|
|
1543
1549
|
/**
|
|
1544
1550
|
* Checks whether this DateTime is the same as or before another date (comparing by week).
|
|
1545
1551
|
* @param {DateTime} other The date to compare to.
|
|
1546
|
-
* @
|
|
1552
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by week).
|
|
1547
1553
|
*/
|
|
1548
1554
|
isSameOrBeforeWeek(other) {
|
|
1549
1555
|
return this.diffInWeeks(other) <= 0;
|
|
@@ -1552,7 +1558,7 @@ export default class DateTime {
|
|
|
1552
1558
|
/**
|
|
1553
1559
|
* Checks whether this DateTime is the same as or before another date (comparing by year).
|
|
1554
1560
|
* @param {DateTime} other The date to compare to.
|
|
1555
|
-
* @
|
|
1561
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by year).
|
|
1556
1562
|
*/
|
|
1557
1563
|
isSameOrBeforeYear(other) {
|
|
1558
1564
|
return this.diffInYears(other) <= 0;
|
|
@@ -1561,7 +1567,7 @@ export default class DateTime {
|
|
|
1561
1567
|
/**
|
|
1562
1568
|
* Checks whether this DateTime is the same as another date (comparing by second).
|
|
1563
1569
|
* @param {DateTime} other The date to compare to.
|
|
1564
|
-
* @
|
|
1570
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by second).
|
|
1565
1571
|
*/
|
|
1566
1572
|
isSameSecond(other) {
|
|
1567
1573
|
return this.diffInSeconds(other) === 0;
|
|
@@ -1570,7 +1576,7 @@ export default class DateTime {
|
|
|
1570
1576
|
/**
|
|
1571
1577
|
* Checks whether this DateTime is the same as another date (comparing by week).
|
|
1572
1578
|
* @param {DateTime} other The date to compare to.
|
|
1573
|
-
* @
|
|
1579
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by week).
|
|
1574
1580
|
*/
|
|
1575
1581
|
isSameWeek(other) {
|
|
1576
1582
|
return this.diffInWeeks(other) === 0;
|
|
@@ -1579,7 +1585,7 @@ export default class DateTime {
|
|
|
1579
1585
|
/**
|
|
1580
1586
|
* Checks whether this DateTime is the same as another date (comparing by year).
|
|
1581
1587
|
* @param {DateTime} other The date to compare to.
|
|
1582
|
-
* @
|
|
1588
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by year).
|
|
1583
1589
|
*/
|
|
1584
1590
|
isSameYear(other) {
|
|
1585
1591
|
return this.diffInYears(other) === 0;
|
|
@@ -1588,7 +1594,7 @@ export default class DateTime {
|
|
|
1588
1594
|
/**
|
|
1589
1595
|
* Gets the localized month name for the current date.
|
|
1590
1596
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of month name to return.
|
|
1591
|
-
* @
|
|
1597
|
+
* @returns {string} The localized month name.
|
|
1592
1598
|
*/
|
|
1593
1599
|
monthName(type = 'long') {
|
|
1594
1600
|
return formatMonth(this.getLocale(), this.getMonth(), type);
|
|
@@ -1596,7 +1602,7 @@ export default class DateTime {
|
|
|
1596
1602
|
|
|
1597
1603
|
/**
|
|
1598
1604
|
* Sets the DateTime to the start of the day.
|
|
1599
|
-
* @
|
|
1605
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1600
1606
|
*/
|
|
1601
1607
|
startOfDay() {
|
|
1602
1608
|
return this.withHours(0, 0, 0, 0);
|
|
@@ -1604,7 +1610,7 @@ export default class DateTime {
|
|
|
1604
1610
|
|
|
1605
1611
|
/**
|
|
1606
1612
|
* Sets the DateTime to the start of the hour.
|
|
1607
|
-
* @
|
|
1613
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1608
1614
|
*/
|
|
1609
1615
|
startOfHour() {
|
|
1610
1616
|
return this.withMinutes(0, 0, 0);
|
|
@@ -1612,7 +1618,7 @@ export default class DateTime {
|
|
|
1612
1618
|
|
|
1613
1619
|
/**
|
|
1614
1620
|
* Sets the DateTime to the start of the minute.
|
|
1615
|
-
* @
|
|
1621
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1616
1622
|
*/
|
|
1617
1623
|
startOfMinute() {
|
|
1618
1624
|
return this.withSeconds(0, 0);
|
|
@@ -1620,7 +1626,7 @@ export default class DateTime {
|
|
|
1620
1626
|
|
|
1621
1627
|
/**
|
|
1622
1628
|
* Sets the DateTime to the start of the month.
|
|
1623
|
-
* @
|
|
1629
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1624
1630
|
*/
|
|
1625
1631
|
startOfMonth() {
|
|
1626
1632
|
return this.withDate(1)
|
|
@@ -1629,7 +1635,7 @@ export default class DateTime {
|
|
|
1629
1635
|
|
|
1630
1636
|
/**
|
|
1631
1637
|
* Sets the DateTime to the start of the quarter.
|
|
1632
|
-
* @
|
|
1638
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1633
1639
|
*/
|
|
1634
1640
|
startOfQuarter() {
|
|
1635
1641
|
const month = this.getQuarter() * 3 - 2;
|
|
@@ -1639,7 +1645,7 @@ export default class DateTime {
|
|
|
1639
1645
|
|
|
1640
1646
|
/**
|
|
1641
1647
|
* Sets the DateTime to the start of the second.
|
|
1642
|
-
* @
|
|
1648
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1643
1649
|
*/
|
|
1644
1650
|
startOfSecond() {
|
|
1645
1651
|
return this.withMilliseconds(0);
|
|
@@ -1647,7 +1653,7 @@ export default class DateTime {
|
|
|
1647
1653
|
|
|
1648
1654
|
/**
|
|
1649
1655
|
* Sets the DateTime to the start of the week.
|
|
1650
|
-
* @
|
|
1656
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1651
1657
|
*/
|
|
1652
1658
|
startOfWeek() {
|
|
1653
1659
|
return this.withWeekDay(1)
|
|
@@ -1656,7 +1662,7 @@ export default class DateTime {
|
|
|
1656
1662
|
|
|
1657
1663
|
/**
|
|
1658
1664
|
* Sets the DateTime to the start of the year.
|
|
1659
|
-
* @
|
|
1665
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1660
1666
|
*/
|
|
1661
1667
|
startOfYear() {
|
|
1662
1668
|
return this.withMonth(1, 1)
|
|
@@ -1665,7 +1671,7 @@ export default class DateTime {
|
|
|
1665
1671
|
|
|
1666
1672
|
/**
|
|
1667
1673
|
* Subtracts a day from the current DateTime.
|
|
1668
|
-
* @
|
|
1674
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1669
1675
|
*/
|
|
1670
1676
|
subDay() {
|
|
1671
1677
|
return this.addDays(-1);
|
|
@@ -1674,7 +1680,7 @@ export default class DateTime {
|
|
|
1674
1680
|
/**
|
|
1675
1681
|
* Subtracts days from the current DateTime.
|
|
1676
1682
|
* @param {number} amount The number of days to subtract.
|
|
1677
|
-
* @
|
|
1683
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1678
1684
|
*/
|
|
1679
1685
|
subDays(amount) {
|
|
1680
1686
|
return this.addDays(-amount);
|
|
@@ -1682,7 +1688,7 @@ export default class DateTime {
|
|
|
1682
1688
|
|
|
1683
1689
|
/**
|
|
1684
1690
|
* Subtracts an hour from the current DateTime.
|
|
1685
|
-
* @
|
|
1691
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1686
1692
|
*/
|
|
1687
1693
|
subHour() {
|
|
1688
1694
|
return this.addHours(-1);
|
|
@@ -1691,7 +1697,7 @@ export default class DateTime {
|
|
|
1691
1697
|
/**
|
|
1692
1698
|
* Subtracts hours from the current DateTime.
|
|
1693
1699
|
* @param {number} amount The number of hours to subtract.
|
|
1694
|
-
* @
|
|
1700
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1695
1701
|
*/
|
|
1696
1702
|
subHours(amount) {
|
|
1697
1703
|
return this.addHours(-amount);
|
|
@@ -1699,7 +1705,7 @@ export default class DateTime {
|
|
|
1699
1705
|
|
|
1700
1706
|
/**
|
|
1701
1707
|
* Subtracts a minute from the current DateTime.
|
|
1702
|
-
* @
|
|
1708
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1703
1709
|
*/
|
|
1704
1710
|
subMinute() {
|
|
1705
1711
|
return this.addMinutes(-1);
|
|
@@ -1708,7 +1714,7 @@ export default class DateTime {
|
|
|
1708
1714
|
/**
|
|
1709
1715
|
* Subtracts minutes from the current DateTime.
|
|
1710
1716
|
* @param {number} amount The number of minutes to subtract.
|
|
1711
|
-
* @
|
|
1717
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1712
1718
|
*/
|
|
1713
1719
|
subMinutes(amount) {
|
|
1714
1720
|
return this.addMinutes(-amount);
|
|
@@ -1716,7 +1722,7 @@ export default class DateTime {
|
|
|
1716
1722
|
|
|
1717
1723
|
/**
|
|
1718
1724
|
* Subtracts a month from the current DateTime.
|
|
1719
|
-
* @
|
|
1725
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1720
1726
|
*/
|
|
1721
1727
|
subMonth() {
|
|
1722
1728
|
return this.addMonths(-1);
|
|
@@ -1725,7 +1731,7 @@ export default class DateTime {
|
|
|
1725
1731
|
/**
|
|
1726
1732
|
* Subtracts months from the current DateTime.
|
|
1727
1733
|
* @param {number} amount The number of months to subtract.
|
|
1728
|
-
* @
|
|
1734
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1729
1735
|
*/
|
|
1730
1736
|
subMonths(amount) {
|
|
1731
1737
|
return this.addMonths(-amount);
|
|
@@ -1733,7 +1739,7 @@ export default class DateTime {
|
|
|
1733
1739
|
|
|
1734
1740
|
/**
|
|
1735
1741
|
* Subtracts a second from the current DateTime.
|
|
1736
|
-
* @
|
|
1742
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1737
1743
|
*/
|
|
1738
1744
|
subSecond() {
|
|
1739
1745
|
return this.addSeconds(-1);
|
|
@@ -1742,7 +1748,7 @@ export default class DateTime {
|
|
|
1742
1748
|
/**
|
|
1743
1749
|
* Subtracts seconds from the current DateTime.
|
|
1744
1750
|
* @param {number} amount The number of seconds to subtract.
|
|
1745
|
-
* @
|
|
1751
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1746
1752
|
*/
|
|
1747
1753
|
subSeconds(amount) {
|
|
1748
1754
|
return this.addSeconds(-amount);
|
|
@@ -1750,7 +1756,7 @@ export default class DateTime {
|
|
|
1750
1756
|
|
|
1751
1757
|
/**
|
|
1752
1758
|
* Subtracts a week from the current DateTime.
|
|
1753
|
-
* @
|
|
1759
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1754
1760
|
*/
|
|
1755
1761
|
subWeek() {
|
|
1756
1762
|
return this.addWeeks(-1);
|
|
@@ -1759,7 +1765,7 @@ export default class DateTime {
|
|
|
1759
1765
|
/**
|
|
1760
1766
|
* Subtracts weeks from the current DateTime.
|
|
1761
1767
|
* @param {number} amount The number of weeks to subtract.
|
|
1762
|
-
* @
|
|
1768
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1763
1769
|
*/
|
|
1764
1770
|
subWeeks(amount) {
|
|
1765
1771
|
return this.addWeeks(-amount);
|
|
@@ -1767,7 +1773,7 @@ export default class DateTime {
|
|
|
1767
1773
|
|
|
1768
1774
|
/**
|
|
1769
1775
|
* Subtracts a year from the current DateTime.
|
|
1770
|
-
* @
|
|
1776
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1771
1777
|
*/
|
|
1772
1778
|
subYear() {
|
|
1773
1779
|
return this.addYears(-1);
|
|
@@ -1776,7 +1782,7 @@ export default class DateTime {
|
|
|
1776
1782
|
/**
|
|
1777
1783
|
* Subtracts years from the current DateTime.
|
|
1778
1784
|
* @param {number} amount The number of years to subtract.
|
|
1779
|
-
* @
|
|
1785
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1780
1786
|
*/
|
|
1781
1787
|
subYears(amount) {
|
|
1782
1788
|
return this.addYears(-amount);
|
|
@@ -1785,7 +1791,7 @@ export default class DateTime {
|
|
|
1785
1791
|
/**
|
|
1786
1792
|
* Returns the primitive representation of the DateTime.
|
|
1787
1793
|
* @param {'default'|'number'|'string'} hint The conversion hint.
|
|
1788
|
-
* @
|
|
1794
|
+
* @returns {string|number} A string for default/string coercion or epoch milliseconds for numeric coercion.
|
|
1789
1795
|
*/
|
|
1790
1796
|
[Symbol.toPrimitive](hint) {
|
|
1791
1797
|
return hint === 'number' ?
|
|
@@ -1796,17 +1802,17 @@ export default class DateTime {
|
|
|
1796
1802
|
/**
|
|
1797
1803
|
* Gets the name of the current time zone.
|
|
1798
1804
|
* @param {'long'|'short'} [type='long'] The formatting type.
|
|
1799
|
-
* @
|
|
1805
|
+
* @returns {string} The name of the time zone.
|
|
1800
1806
|
*/
|
|
1801
1807
|
timeZoneName(type = 'long') {
|
|
1802
|
-
return this
|
|
1808
|
+
return this.#dynamicTz ?
|
|
1803
1809
|
formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
|
|
1804
1810
|
'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
|
|
1805
1811
|
}
|
|
1806
1812
|
|
|
1807
1813
|
/**
|
|
1808
1814
|
* Formats the current date using "eee MMM dd yyyy".
|
|
1809
|
-
* @
|
|
1815
|
+
* @returns {string} The formatted date string.
|
|
1810
1816
|
*/
|
|
1811
1817
|
toDateString() {
|
|
1812
1818
|
return this.format(formats.date);
|
|
@@ -1814,7 +1820,7 @@ export default class DateTime {
|
|
|
1814
1820
|
|
|
1815
1821
|
/**
|
|
1816
1822
|
* Formats the current date using "yyyy-MM-dd'T'HH:mm:ss.SSSxxx".
|
|
1817
|
-
* @
|
|
1823
|
+
* @returns {string} The formatted date string.
|
|
1818
1824
|
*/
|
|
1819
1825
|
toIsoString() {
|
|
1820
1826
|
return this
|
|
@@ -1825,7 +1831,7 @@ export default class DateTime {
|
|
|
1825
1831
|
|
|
1826
1832
|
/**
|
|
1827
1833
|
* Returns the JSON representation of the current date.
|
|
1828
|
-
* @
|
|
1834
|
+
* @returns {string|null} The ISO string for valid dates or null for invalid dates.
|
|
1829
1835
|
*/
|
|
1830
1836
|
toJSON() {
|
|
1831
1837
|
return this.isValid ?
|
|
@@ -1835,7 +1841,7 @@ export default class DateTime {
|
|
|
1835
1841
|
|
|
1836
1842
|
/**
|
|
1837
1843
|
* Formats the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
1838
|
-
* @
|
|
1844
|
+
* @returns {string} The formatted date string.
|
|
1839
1845
|
*/
|
|
1840
1846
|
toString() {
|
|
1841
1847
|
return this.format(formats.string);
|
|
@@ -1843,7 +1849,7 @@ export default class DateTime {
|
|
|
1843
1849
|
|
|
1844
1850
|
/**
|
|
1845
1851
|
* Formats the current date using "HH:mm:ss xx (VV)".
|
|
1846
|
-
* @
|
|
1852
|
+
* @returns {string} The formatted date string.
|
|
1847
1853
|
*/
|
|
1848
1854
|
toTimeString() {
|
|
1849
1855
|
return this.format(formats.time);
|
|
@@ -1851,7 +1857,7 @@ export default class DateTime {
|
|
|
1851
1857
|
|
|
1852
1858
|
/**
|
|
1853
1859
|
* Formats the current date in the UTC time zone using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
1854
|
-
* @
|
|
1860
|
+
* @returns {string} The formatted date string.
|
|
1855
1861
|
*/
|
|
1856
1862
|
toUTCString() {
|
|
1857
1863
|
return this
|
|
@@ -1862,7 +1868,7 @@ export default class DateTime {
|
|
|
1862
1868
|
|
|
1863
1869
|
/**
|
|
1864
1870
|
* Returns the number of milliseconds since the UNIX epoch.
|
|
1865
|
-
* @
|
|
1871
|
+
* @returns {number} The number of milliseconds since the UNIX epoch.
|
|
1866
1872
|
*/
|
|
1867
1873
|
valueOf() {
|
|
1868
1874
|
return this.getTime();
|
|
@@ -1870,7 +1876,7 @@ export default class DateTime {
|
|
|
1870
1876
|
|
|
1871
1877
|
/**
|
|
1872
1878
|
* Gets the number of weeks in the current year.
|
|
1873
|
-
* @
|
|
1879
|
+
* @returns {number} The number of weeks in the current year.
|
|
1874
1880
|
*/
|
|
1875
1881
|
weeksInYear() {
|
|
1876
1882
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -1880,7 +1886,7 @@ export default class DateTime {
|
|
|
1880
1886
|
/**
|
|
1881
1887
|
* Returns a copy with the date of the month changed in the current time zone.
|
|
1882
1888
|
* @param {number} date The date of the month.
|
|
1883
|
-
* @
|
|
1889
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1884
1890
|
*/
|
|
1885
1891
|
withDate(date) {
|
|
1886
1892
|
return setOffsetTime(
|
|
@@ -1892,7 +1898,7 @@ export default class DateTime {
|
|
|
1892
1898
|
/**
|
|
1893
1899
|
* Returns a copy with the day of the week changed in the current time zone.
|
|
1894
1900
|
* @param {number} day The day of the week. (0 = Sunday, 6 = Saturday)
|
|
1895
|
-
* @
|
|
1901
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1896
1902
|
*/
|
|
1897
1903
|
withDay(day) {
|
|
1898
1904
|
return setOffsetTime(
|
|
@@ -1908,7 +1914,7 @@ export default class DateTime {
|
|
|
1908
1914
|
/**
|
|
1909
1915
|
* Returns a copy with the day of the year changed in the current time zone.
|
|
1910
1916
|
* @param {number} day The day of the year. (1-366)
|
|
1911
|
-
* @
|
|
1917
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1912
1918
|
*/
|
|
1913
1919
|
withDayOfYear(day) {
|
|
1914
1920
|
return setOffsetTime(
|
|
@@ -1926,7 +1932,7 @@ export default class DateTime {
|
|
|
1926
1932
|
* @param {number} [minutes] The minutes. (0-59)
|
|
1927
1933
|
* @param {number} [seconds] The seconds. (0-59)
|
|
1928
1934
|
* @param {number} [milliseconds] The milliseconds.
|
|
1929
|
-
* @
|
|
1935
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1930
1936
|
*/
|
|
1931
1937
|
withHours(...args) {
|
|
1932
1938
|
return setOffsetTime(
|
|
@@ -1938,19 +1944,19 @@ export default class DateTime {
|
|
|
1938
1944
|
/**
|
|
1939
1945
|
* Returns a copy with a different locale.
|
|
1940
1946
|
* @param {string} locale The locale to use.
|
|
1941
|
-
* @
|
|
1947
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1942
1948
|
*/
|
|
1943
1949
|
withLocale(locale) {
|
|
1944
1950
|
return new this.constructor(this.getTime(), {
|
|
1945
1951
|
locale,
|
|
1946
|
-
timeZone: this
|
|
1952
|
+
timeZone: this.#timeZone,
|
|
1947
1953
|
});
|
|
1948
1954
|
}
|
|
1949
1955
|
|
|
1950
1956
|
/**
|
|
1951
1957
|
* Returns a copy with the milliseconds changed in the current time zone.
|
|
1952
1958
|
* @param {number} milliseconds The milliseconds.
|
|
1953
|
-
* @
|
|
1959
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1954
1960
|
*/
|
|
1955
1961
|
withMilliseconds(milliseconds) {
|
|
1956
1962
|
return setOffsetTime(
|
|
@@ -1964,7 +1970,7 @@ export default class DateTime {
|
|
|
1964
1970
|
* @param {number} minutes The minutes. (0-59)
|
|
1965
1971
|
* @param {number} [seconds] The seconds. (0-59)
|
|
1966
1972
|
* @param {number} [milliseconds] The milliseconds.
|
|
1967
|
-
* @
|
|
1973
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1968
1974
|
*/
|
|
1969
1975
|
withMinutes(...args) {
|
|
1970
1976
|
return setOffsetTime(
|
|
@@ -1977,7 +1983,7 @@ export default class DateTime {
|
|
|
1977
1983
|
* Returns a copy with the month changed in the current time zone.
|
|
1978
1984
|
* @param {number} month The month. (1-12)
|
|
1979
1985
|
* @param {number|null} [date] The date of the month.
|
|
1980
|
-
* @
|
|
1986
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1981
1987
|
*/
|
|
1982
1988
|
withMonth(month, date = null) {
|
|
1983
1989
|
if (date === null) {
|
|
@@ -2006,7 +2012,7 @@ export default class DateTime {
|
|
|
2006
2012
|
/**
|
|
2007
2013
|
* Returns a copy with the quarter of the year changed in the current time zone.
|
|
2008
2014
|
* @param {number} quarter The quarter of the year. (1-4)
|
|
2009
|
-
* @
|
|
2015
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2010
2016
|
*/
|
|
2011
2017
|
withQuarter(quarter) {
|
|
2012
2018
|
return setOffsetTime(
|
|
@@ -2022,7 +2028,7 @@ export default class DateTime {
|
|
|
2022
2028
|
* Returns a copy with the seconds changed in the current time zone.
|
|
2023
2029
|
* @param {number} seconds The seconds. (0-59)
|
|
2024
2030
|
* @param {number} [milliseconds] The milliseconds.
|
|
2025
|
-
* @
|
|
2031
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2026
2032
|
*/
|
|
2027
2033
|
withSeconds(...args) {
|
|
2028
2034
|
return setOffsetTime(
|
|
@@ -2034,19 +2040,19 @@ export default class DateTime {
|
|
|
2034
2040
|
/**
|
|
2035
2041
|
* Returns a copy with a different epoch-millisecond value.
|
|
2036
2042
|
* @param {number} time The number of milliseconds since the UNIX epoch.
|
|
2037
|
-
* @
|
|
2043
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2038
2044
|
*/
|
|
2039
2045
|
withTime(time) {
|
|
2040
2046
|
return new this.constructor(time, {
|
|
2041
|
-
locale: this
|
|
2042
|
-
timeZone: this
|
|
2047
|
+
locale: this.#locale,
|
|
2048
|
+
timeZone: this.#timeZone,
|
|
2043
2049
|
});
|
|
2044
2050
|
}
|
|
2045
2051
|
|
|
2046
2052
|
/**
|
|
2047
2053
|
* Returns a copy with a different number of seconds since the UNIX epoch.
|
|
2048
2054
|
* @param {number} timestamp The number of seconds since the UNIX epoch.
|
|
2049
|
-
* @
|
|
2055
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2050
2056
|
*/
|
|
2051
2057
|
withTimestamp(timestamp) {
|
|
2052
2058
|
return this.withTime(timestamp * 1000);
|
|
@@ -2055,11 +2061,11 @@ export default class DateTime {
|
|
|
2055
2061
|
/**
|
|
2056
2062
|
* Returns a copy in a different time zone.
|
|
2057
2063
|
* @param {string} timeZone The time zone to use.
|
|
2058
|
-
* @
|
|
2064
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2059
2065
|
*/
|
|
2060
2066
|
withTimeZone(timeZone) {
|
|
2061
2067
|
return new this.constructor(this.getTime(), {
|
|
2062
|
-
locale: this
|
|
2068
|
+
locale: this.#locale,
|
|
2063
2069
|
timeZone,
|
|
2064
2070
|
});
|
|
2065
2071
|
}
|
|
@@ -2067,11 +2073,11 @@ export default class DateTime {
|
|
|
2067
2073
|
/**
|
|
2068
2074
|
* Returns a copy with a fixed numeric UTC offset.
|
|
2069
2075
|
* @param {number} offset The UTC offset in minutes.
|
|
2070
|
-
* @
|
|
2076
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2071
2077
|
*/
|
|
2072
2078
|
withTimeZoneOffset(offset) {
|
|
2073
2079
|
return new this.constructor(this.getTime(), {
|
|
2074
|
-
locale: this
|
|
2080
|
+
locale: this.#locale,
|
|
2075
2081
|
timeZone: formatOffset(offset),
|
|
2076
2082
|
});
|
|
2077
2083
|
}
|
|
@@ -2080,7 +2086,7 @@ export default class DateTime {
|
|
|
2080
2086
|
* Returns a copy with the local week changed in the current time zone.
|
|
2081
2087
|
* @param {number} week The local week.
|
|
2082
2088
|
* @param {number|null} [day] The local day of the week. (1-7)
|
|
2083
|
-
* @
|
|
2089
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2084
2090
|
*/
|
|
2085
2091
|
withWeek(week, day = null) {
|
|
2086
2092
|
if (day === null) {
|
|
@@ -2094,7 +2100,7 @@ export default class DateTime {
|
|
|
2094
2100
|
/**
|
|
2095
2101
|
* Returns a copy with the local day of the week changed in the current time zone.
|
|
2096
2102
|
* @param {number} day The local day of the week. (1-7)
|
|
2097
|
-
* @
|
|
2103
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2098
2104
|
*/
|
|
2099
2105
|
withWeekDay(day) {
|
|
2100
2106
|
return setOffsetTime(
|
|
@@ -2110,7 +2116,7 @@ export default class DateTime {
|
|
|
2110
2116
|
/**
|
|
2111
2117
|
* Returns a copy with the week day in month changed in the current time zone.
|
|
2112
2118
|
* @param {number} week The week day in month.
|
|
2113
|
-
* @
|
|
2119
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2114
2120
|
*/
|
|
2115
2121
|
withWeekDayInMonth(week) {
|
|
2116
2122
|
return this.withDate(
|
|
@@ -2125,7 +2131,7 @@ export default class DateTime {
|
|
|
2125
2131
|
/**
|
|
2126
2132
|
* Returns a copy with the week of month changed in the current time zone.
|
|
2127
2133
|
* @param {number} week The week of month.
|
|
2128
|
-
* @
|
|
2134
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2129
2135
|
*/
|
|
2130
2136
|
withWeekOfMonth(week) {
|
|
2131
2137
|
return this.withDate(
|
|
@@ -2142,7 +2148,7 @@ export default class DateTime {
|
|
|
2142
2148
|
* @param {number} year The local week year.
|
|
2143
2149
|
* @param {number|null} [week] The local week.
|
|
2144
2150
|
* @param {number|null} [day] The local day of the week. (1-7)
|
|
2145
|
-
* @
|
|
2151
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2146
2152
|
*/
|
|
2147
2153
|
withWeekYear(year, week = null, day = null) {
|
|
2148
2154
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -2170,7 +2176,7 @@ export default class DateTime {
|
|
|
2170
2176
|
* @param {number} year The year.
|
|
2171
2177
|
* @param {number|null} [month] The month. (1-12)
|
|
2172
2178
|
* @param {number|null} [date] The date of the month.
|
|
2173
|
-
* @
|
|
2179
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2174
2180
|
*/
|
|
2175
2181
|
withYear(year, month = null, date = null) {
|
|
2176
2182
|
if (month === null) {
|