@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/dist/frost-datetime.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* @template T
|
|
22
22
|
* @param {string} key The key for the values.
|
|
23
23
|
* @param {() => T} callback The callback to generate the values.
|
|
24
|
-
* @
|
|
24
|
+
* @returns {T} The cached value.
|
|
25
25
|
*/
|
|
26
26
|
function getData(key, callback) {
|
|
27
27
|
if (!data.has(key)) {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
/**
|
|
34
34
|
* Creates a date formatter for a time zone.
|
|
35
35
|
* @param {string} timeZone The time zone.
|
|
36
|
-
* @
|
|
36
|
+
* @returns {Intl.DateTimeFormat} The formatter instance.
|
|
37
37
|
*/
|
|
38
38
|
function getDateFormatter(timeZone) {
|
|
39
39
|
return getData(
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
/**
|
|
56
56
|
* Creates a relative-time formatter for a locale.
|
|
57
57
|
* @param {string} locale The locale.
|
|
58
|
-
* @
|
|
58
|
+
* @returns {Intl.RelativeTimeFormat|null} The formatter instance, or null when unsupported.
|
|
59
59
|
*/
|
|
60
60
|
function getRelativeFormatter(locale) {
|
|
61
61
|
if (!('RelativeTimeFormat' in Intl)) {
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
* Creates a formatter for a locale.
|
|
75
75
|
* @param {string} locale The locale.
|
|
76
76
|
* @param {Intl.DateTimeFormatOptions} options The options for the formatter.
|
|
77
|
-
* @
|
|
77
|
+
* @returns {Intl.DateTimeFormat} The formatter instance.
|
|
78
78
|
*/
|
|
79
79
|
function makeFormatter(locale, options) {
|
|
80
80
|
return new Intl.DateTimeFormat(locale, {
|
|
@@ -150,7 +150,7 @@
|
|
|
150
150
|
/**
|
|
151
151
|
* Escapes a string for safe use inside a RegExp source.
|
|
152
152
|
* @param {string} value The string to escape.
|
|
153
|
-
* @
|
|
153
|
+
* @returns {string} The escaped string.
|
|
154
154
|
*/
|
|
155
155
|
function escapeRegExp(value) {
|
|
156
156
|
return value.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&');
|
|
@@ -159,7 +159,7 @@
|
|
|
159
159
|
/**
|
|
160
160
|
* Gets a stable day number from a DateTime's local calendar fields.
|
|
161
161
|
* @param {DateTime} date The DateTime.
|
|
162
|
-
* @
|
|
162
|
+
* @returns {number} The local calendar day number.
|
|
163
163
|
*/
|
|
164
164
|
function calendarDay(date) {
|
|
165
165
|
const calendarDate = new Date(0);
|
|
@@ -174,7 +174,7 @@
|
|
|
174
174
|
* @param {DateTime} other The DateTime to compare to.
|
|
175
175
|
* @param {'year' | 'month' | 'week' | 'day' | 'hour' | 'minute' | 'second'} timeUnit The time unit to compare in.
|
|
176
176
|
* @param {boolean} [relative=true] Whether to use relative boundaries when calculating the difference.
|
|
177
|
-
* @
|
|
177
|
+
* @returns {number} The difference between the dates in the given time unit.
|
|
178
178
|
*/
|
|
179
179
|
function calculateDiff(date, other, timeUnit, relative = true) {
|
|
180
180
|
other = other.withTimeZone(date.getTimeZone());
|
|
@@ -286,7 +286,7 @@
|
|
|
286
286
|
* Gets the RegExp for a list of string values.
|
|
287
287
|
* Longer values are matched first to avoid prefix collisions.
|
|
288
288
|
* @param {string[]} values The values to include in the RegExp.
|
|
289
|
-
* @
|
|
289
|
+
* @returns {string} The values RegExp.
|
|
290
290
|
*/
|
|
291
291
|
function valuesRegExp(values) {
|
|
292
292
|
return values.slice()
|
|
@@ -301,7 +301,7 @@
|
|
|
301
301
|
* @param {number} amount The amount to compensate.
|
|
302
302
|
* @param {boolean} [compensate=true] Whether to compensate the amount.
|
|
303
303
|
* @param {number} [compensation=1] The compensation offset.
|
|
304
|
-
* @
|
|
304
|
+
* @returns {number} The compensated amount.
|
|
305
305
|
*/
|
|
306
306
|
function compensateDiff(date, other, amount, compensate = true, compensation = 1) {
|
|
307
307
|
if (amount > 0) {
|
|
@@ -324,7 +324,7 @@
|
|
|
324
324
|
* Gets the biggest difference between two dates.
|
|
325
325
|
* @param {DateTime} date The DateTime.
|
|
326
326
|
* @param {DateTime} [other] The DateTime to compare to.
|
|
327
|
-
* @
|
|
327
|
+
* @returns {[number, string]} The biggest difference (amount and time unit).
|
|
328
328
|
*/
|
|
329
329
|
function getBiggestDiff(date, other) {
|
|
330
330
|
let lastResult;
|
|
@@ -355,7 +355,7 @@
|
|
|
355
355
|
/**
|
|
356
356
|
* Gets the offset for a DateTime.
|
|
357
357
|
* @param {DateTime} date The DateTime.
|
|
358
|
-
* @
|
|
358
|
+
* @returns {number} The offset.
|
|
359
359
|
*/
|
|
360
360
|
function getOffset(date) {
|
|
361
361
|
const timeZone = date.getTimeZone();
|
|
@@ -394,7 +394,7 @@
|
|
|
394
394
|
/**
|
|
395
395
|
* Gets the number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
396
396
|
* @param {DateTime} date The DateTime.
|
|
397
|
-
* @
|
|
397
|
+
* @returns {number} The number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
398
398
|
*/
|
|
399
399
|
function getOffsetTime(date) {
|
|
400
400
|
return date.getTime() - (date.getTimeZoneOffset() * 60000);
|
|
@@ -417,7 +417,7 @@
|
|
|
417
417
|
/**
|
|
418
418
|
* Parses a supported unzoned ISO string as a neutral wall-clock timestamp.
|
|
419
419
|
* @param {string} dateString The date string to parse.
|
|
420
|
-
* @
|
|
420
|
+
* @returns {number|null} The timestamp, or null if the shape is not supported.
|
|
421
421
|
*/
|
|
422
422
|
function parseLocalTimestamp(dateString) {
|
|
423
423
|
const match =
|
|
@@ -446,7 +446,7 @@
|
|
|
446
446
|
}
|
|
447
447
|
/**
|
|
448
448
|
* Generates methods for parsing a date.
|
|
449
|
-
* @
|
|
449
|
+
* @returns {Record<string, {get: Function, set: Function}>} An object containing date parsing methods.
|
|
450
450
|
*/
|
|
451
451
|
function parseFactory() {
|
|
452
452
|
let isPM = false;
|
|
@@ -552,7 +552,7 @@
|
|
|
552
552
|
* @param {DateTime} date The DateTime.
|
|
553
553
|
* @param {number} time The number of milliseconds since the UNIX epoch (offset to timeZone).
|
|
554
554
|
* @param {number} [direction=1] The direction to resolve a gap.
|
|
555
|
-
* @
|
|
555
|
+
* @returns {DateTime} A new DateTime instance.
|
|
556
556
|
*/
|
|
557
557
|
function setOffsetTime(date, time, direction = 1) {
|
|
558
558
|
const newDate = date.withTime(
|
|
@@ -591,8 +591,8 @@
|
|
|
591
591
|
/**
|
|
592
592
|
* Gets cached localized day-period labels.
|
|
593
593
|
* @param {string} locale The locale.
|
|
594
|
-
* @param {string} [type=long] The formatting type.
|
|
595
|
-
* @
|
|
594
|
+
* @param {string} [type='long'] The formatting type.
|
|
595
|
+
* @returns {string[]} The localized day-period labels.
|
|
596
596
|
*/
|
|
597
597
|
function getDayPeriods(locale, type = 'long') {
|
|
598
598
|
return getData(
|
|
@@ -612,9 +612,9 @@
|
|
|
612
612
|
/**
|
|
613
613
|
* Gets cached localized weekday labels.
|
|
614
614
|
* @param {string} locale The locale.
|
|
615
|
-
* @param {string} [type=long] The formatting type.
|
|
615
|
+
* @param {string} [type='long'] The formatting type.
|
|
616
616
|
* @param {boolean} [standalone=true] Whether the values are standalone.
|
|
617
|
-
* @
|
|
617
|
+
* @returns {string[]} The localized weekday labels.
|
|
618
618
|
*/
|
|
619
619
|
function getDays(locale, type = 'long', standalone = true) {
|
|
620
620
|
return getData(
|
|
@@ -643,8 +643,8 @@
|
|
|
643
643
|
/**
|
|
644
644
|
* Gets cached localized era labels.
|
|
645
645
|
* @param {string} locale The locale.
|
|
646
|
-
* @param {string} [type=long] The formatting type.
|
|
647
|
-
* @
|
|
646
|
+
* @param {string} [type='long'] The formatting type.
|
|
647
|
+
* @returns {string[]} The localized era labels.
|
|
648
648
|
*/
|
|
649
649
|
function getEras(locale, type = 'long') {
|
|
650
650
|
return getData(
|
|
@@ -664,9 +664,9 @@
|
|
|
664
664
|
/**
|
|
665
665
|
* Gets cached localized month labels.
|
|
666
666
|
* @param {string} locale The locale.
|
|
667
|
-
* @param {string} [type=long] The formatting type.
|
|
667
|
+
* @param {string} [type='long'] The formatting type.
|
|
668
668
|
* @param {boolean} [standalone=true] Whether the values are standalone.
|
|
669
|
-
* @
|
|
669
|
+
* @returns {string[]} The localized month labels.
|
|
670
670
|
*/
|
|
671
671
|
function getMonths(locale, type = 'long', standalone = true) {
|
|
672
672
|
return getData(
|
|
@@ -695,7 +695,7 @@
|
|
|
695
695
|
/**
|
|
696
696
|
* Gets cached localized digit glyphs.
|
|
697
697
|
* @param {string} locale The locale.
|
|
698
|
-
* @
|
|
698
|
+
* @returns {string[]} The localized digit glyphs.
|
|
699
699
|
*/
|
|
700
700
|
function getNumbers(locale) {
|
|
701
701
|
return getData(
|
|
@@ -714,7 +714,7 @@
|
|
|
714
714
|
* Gets the RegExp for the number values.
|
|
715
715
|
* @param {string} locale The locale.
|
|
716
716
|
* @param {number|null} [length=null] The exact number of digits to match.
|
|
717
|
-
* @
|
|
717
|
+
* @returns {string} The number values RegExp.
|
|
718
718
|
*/
|
|
719
719
|
function numberRegExp(locale, length = null) {
|
|
720
720
|
const quantifier = length === null ?
|
|
@@ -727,9 +727,9 @@
|
|
|
727
727
|
* Formats a day as a locale string.
|
|
728
728
|
* @param {string} locale The locale.
|
|
729
729
|
* @param {number} day The day to format (0-6).
|
|
730
|
-
* @param {string} [type=long] The formatting type.
|
|
730
|
+
* @param {string} [type='long'] The formatting type.
|
|
731
731
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
732
|
-
* @
|
|
732
|
+
* @returns {string} The formatted string.
|
|
733
733
|
*/
|
|
734
734
|
function formatDay(locale, day, type = 'long', standalone = true) {
|
|
735
735
|
return getDays(locale, type, standalone)[day];
|
|
@@ -738,8 +738,8 @@
|
|
|
738
738
|
* Formats a day period as a locale string.
|
|
739
739
|
* @param {string} locale The locale.
|
|
740
740
|
* @param {number} period The day-period index to format. (0-1)
|
|
741
|
-
* @param {string} [type=long] The formatting type.
|
|
742
|
-
* @
|
|
741
|
+
* @param {string} [type='long'] The formatting type.
|
|
742
|
+
* @returns {string} The formatted string.
|
|
743
743
|
*/
|
|
744
744
|
function formatDayPeriod(locale, period, type = 'long') {
|
|
745
745
|
return getDayPeriods(locale, type)[period];
|
|
@@ -748,8 +748,8 @@
|
|
|
748
748
|
* Formats an era as a locale string.
|
|
749
749
|
* @param {string} locale The locale.
|
|
750
750
|
* @param {number} era The era index to format. (0-1)
|
|
751
|
-
* @param {string} [type=long] The formatting type.
|
|
752
|
-
* @
|
|
751
|
+
* @param {string} [type='long'] The formatting type.
|
|
752
|
+
* @returns {string} The formatted string.
|
|
753
753
|
*/
|
|
754
754
|
function formatEra(locale, era, type = 'long') {
|
|
755
755
|
return getEras(locale, type)[era];
|
|
@@ -758,9 +758,9 @@
|
|
|
758
758
|
* Formats a month as a locale string.
|
|
759
759
|
* @param {string} locale The locale.
|
|
760
760
|
* @param {number} month The month to format (1-12).
|
|
761
|
-
* @param {string} [type=long] The formatting type.
|
|
761
|
+
* @param {string} [type='long'] The formatting type.
|
|
762
762
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
763
|
-
* @
|
|
763
|
+
* @returns {string} The formatted string.
|
|
764
764
|
*/
|
|
765
765
|
function formatMonth(locale, month, type = 'long', standalone = true) {
|
|
766
766
|
return getMonths(locale, type, standalone)[month - 1];
|
|
@@ -770,7 +770,7 @@
|
|
|
770
770
|
* @param {string} locale The locale.
|
|
771
771
|
* @param {number} number The number to format.
|
|
772
772
|
* @param {number} [padding=0] The amount of padding to use.
|
|
773
|
-
* @
|
|
773
|
+
* @returns {string} The formatted string.
|
|
774
774
|
*/
|
|
775
775
|
function formatNumber(locale, number, padding = 0) {
|
|
776
776
|
const numbers = getNumbers(locale);
|
|
@@ -784,7 +784,7 @@
|
|
|
784
784
|
* @param {boolean} [useColon=true] Whether to use a colon separator.
|
|
785
785
|
* @param {boolean} [optionalMinutes=false] Whether minutes are optional.
|
|
786
786
|
* @param {boolean} [includeSeconds=true] Whether seconds are included.
|
|
787
|
-
* @
|
|
787
|
+
* @returns {string} The formatted offset string.
|
|
788
788
|
*/
|
|
789
789
|
function formatOffset(offset, useColon = true, optionalMinutes = false, includeSeconds = true) {
|
|
790
790
|
const absoluteSeconds = Math.abs(offset * 60);
|
|
@@ -818,7 +818,7 @@
|
|
|
818
818
|
* @param {string} locale The locale.
|
|
819
819
|
* @param {number} amount The amount of duration.
|
|
820
820
|
* @param {string} unit The time unit.
|
|
821
|
-
* @
|
|
821
|
+
* @returns {string} The relative duration.
|
|
822
822
|
*/
|
|
823
823
|
function formatRelative(locale, amount, unit) {
|
|
824
824
|
const relativeFormatter = getRelativeFormatter(locale);
|
|
@@ -834,8 +834,8 @@
|
|
|
834
834
|
* @param {string} locale The locale.
|
|
835
835
|
* @param {number} timestamp The timestamp to use.
|
|
836
836
|
* @param {string} timeZone The time zone to format.
|
|
837
|
-
* @param {string} [type=long] The formatting type.
|
|
838
|
-
* @
|
|
837
|
+
* @param {string} [type='long'] The formatting type.
|
|
838
|
+
* @returns {string} The formatted string.
|
|
839
839
|
*/
|
|
840
840
|
function formatTimeZoneName(locale, timestamp, timeZone, type = 'long') {
|
|
841
841
|
return makeFormatter(locale, { second: 'numeric', timeZone, timeZoneName: type })
|
|
@@ -852,7 +852,7 @@
|
|
|
852
852
|
* @param {object} data The generated locale data.
|
|
853
853
|
* @param {string[]} candidates The locale candidates.
|
|
854
854
|
* @param {number} fallback The fallback value.
|
|
855
|
-
* @
|
|
855
|
+
* @returns {number} The locale value.
|
|
856
856
|
*/
|
|
857
857
|
function generatedValue(data, candidates, fallback) {
|
|
858
858
|
for (const candidate of candidates) {
|
|
@@ -869,7 +869,7 @@
|
|
|
869
869
|
/**
|
|
870
870
|
* Gets generated-data candidates for a locale.
|
|
871
871
|
* @param {Intl.Locale} locale The locale.
|
|
872
|
-
* @
|
|
872
|
+
* @returns {string[]} The locale candidates.
|
|
873
873
|
*/
|
|
874
874
|
function localeCandidates(locale) {
|
|
875
875
|
const localeName = locale.toString().split('-x-', 1)[0];
|
|
@@ -894,7 +894,7 @@
|
|
|
894
894
|
/**
|
|
895
895
|
* Gets week information for a locale.
|
|
896
896
|
* @param {string} locale The locale.
|
|
897
|
-
* @
|
|
897
|
+
* @returns {{firstDay: number, minimalDays: number}} The week information.
|
|
898
898
|
*/
|
|
899
899
|
function getWeekInfo(locale) {
|
|
900
900
|
return getData(
|
|
@@ -928,7 +928,7 @@
|
|
|
928
928
|
/**
|
|
929
929
|
* Decodes a quoted ICU format literal.
|
|
930
930
|
* @param {string} literal The literal to decode.
|
|
931
|
-
* @
|
|
931
|
+
* @returns {string} The decoded literal.
|
|
932
932
|
*/
|
|
933
933
|
function decodeLiteral(literal) {
|
|
934
934
|
return literal === `''` ?
|
|
@@ -938,7 +938,7 @@
|
|
|
938
938
|
/**
|
|
939
939
|
* Gets the formatting type from the component token length.
|
|
940
940
|
* @param {number} length The component token length.
|
|
941
|
-
* @
|
|
941
|
+
* @returns {string} The formatting type.
|
|
942
942
|
*/
|
|
943
943
|
function getType(length) {
|
|
944
944
|
switch (length) {
|
|
@@ -957,7 +957,7 @@
|
|
|
957
957
|
* @param {number} length The token length.
|
|
958
958
|
* @param {string} locale The parsing locale.
|
|
959
959
|
* @param {boolean} previousNumeric Whether the previous token was an adjacent numeric token.
|
|
960
|
-
* @
|
|
960
|
+
* @returns {{numeric: boolean, source: string}} The token RegExp data.
|
|
961
961
|
*/
|
|
962
962
|
function getTokenRegExp(source, nextSource, length, locale, previousNumeric) {
|
|
963
963
|
const numberSource = numberRegExp(locale);
|
|
@@ -974,7 +974,7 @@
|
|
|
974
974
|
/**
|
|
975
975
|
* Gets the locale's minimum days in the first week of the year.
|
|
976
976
|
* @param {string} locale The locale.
|
|
977
|
-
* @
|
|
977
|
+
* @returns {number} The minimum day count.
|
|
978
978
|
*/
|
|
979
979
|
function minimumDays(locale) {
|
|
980
980
|
return getWeekInfo(locale).minimalDays;
|
|
@@ -983,7 +983,7 @@
|
|
|
983
983
|
* Converts a Sunday-based day-of-week value to the locale's week numbering.
|
|
984
984
|
* @param {string} locale The locale.
|
|
985
985
|
* @param {number} day The day of the week. (0 = Sunday, 6 = Saturday)
|
|
986
|
-
* @
|
|
986
|
+
* @returns {number} The local day of the week.
|
|
987
987
|
*/
|
|
988
988
|
function weekDay(locale, day) {
|
|
989
989
|
return (7 + parseInt(day, 10) - (getWeekInfo(locale).firstDay % 7)) % 7 + 1;
|
|
@@ -993,9 +993,9 @@
|
|
|
993
993
|
* Parses a day from a locale string.
|
|
994
994
|
* @param {string} locale The locale.
|
|
995
995
|
* @param {string} value The value to parse.
|
|
996
|
-
* @param {string} [type=long] The formatting type.
|
|
996
|
+
* @param {string} [type='long'] The formatting type.
|
|
997
997
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
998
|
-
* @
|
|
998
|
+
* @returns {number} The local day of the week (1-7).
|
|
999
999
|
*/
|
|
1000
1000
|
function parseDay(locale, value, type = 'long', standalone = true) {
|
|
1001
1001
|
const day = getDays(locale, type, standalone).indexOf(value);
|
|
@@ -1008,8 +1008,8 @@
|
|
|
1008
1008
|
* Parses a day period from a locale string.
|
|
1009
1009
|
* @param {string} locale The locale.
|
|
1010
1010
|
* @param {string} value The value to parse.
|
|
1011
|
-
* @param {string} [type=long] The formatting type.
|
|
1012
|
-
* @
|
|
1011
|
+
* @param {string} [type='long'] The formatting type.
|
|
1012
|
+
* @returns {number} The day period (0-1).
|
|
1013
1013
|
*/
|
|
1014
1014
|
function parseDayPeriod(locale, value, type = 'long') {
|
|
1015
1015
|
return getDayPeriods(locale, type).indexOf(value);
|
|
@@ -1018,8 +1018,8 @@
|
|
|
1018
1018
|
* Parses an era from a locale string.
|
|
1019
1019
|
* @param {string} locale The locale.
|
|
1020
1020
|
* @param {string} value The value to parse.
|
|
1021
|
-
* @param {string} [type=long] The formatting type.
|
|
1022
|
-
* @
|
|
1021
|
+
* @param {string} [type='long'] The formatting type.
|
|
1022
|
+
* @returns {number} The era (0-1).
|
|
1023
1023
|
*/
|
|
1024
1024
|
function parseEra(locale, value, type = 'long') {
|
|
1025
1025
|
return getEras(locale, type).indexOf(value);
|
|
@@ -1028,9 +1028,9 @@
|
|
|
1028
1028
|
* Parses a month from a locale string.
|
|
1029
1029
|
* @param {string} locale The locale.
|
|
1030
1030
|
* @param {string} value The value to parse.
|
|
1031
|
-
* @param {string} [type=long] The formatting type.
|
|
1031
|
+
* @param {string} [type='long'] The formatting type.
|
|
1032
1032
|
* @param {boolean} [standalone=true] Whether the value is standalone.
|
|
1033
|
-
* @
|
|
1033
|
+
* @returns {number} The month number (1-12).
|
|
1034
1034
|
*/
|
|
1035
1035
|
function parseMonth(locale, value, type = 'long', standalone = true) {
|
|
1036
1036
|
return getMonths(locale, type, standalone).indexOf(value) + 1;
|
|
@@ -1039,7 +1039,7 @@
|
|
|
1039
1039
|
* Parses locale digits into an ASCII digit string.
|
|
1040
1040
|
* @param {string} locale The locale.
|
|
1041
1041
|
* @param {string} value The value to parse.
|
|
1042
|
-
* @
|
|
1042
|
+
* @returns {string} The parsed ASCII digit string.
|
|
1043
1043
|
*/
|
|
1044
1044
|
function parseNumberString(locale, value) {
|
|
1045
1045
|
const numbers = getNumbers(locale);
|
|
@@ -1049,7 +1049,7 @@
|
|
|
1049
1049
|
* Parses a number from a locale number string.
|
|
1050
1050
|
* @param {string} locale The locale.
|
|
1051
1051
|
* @param {string} value The value to parse.
|
|
1052
|
-
* @
|
|
1052
|
+
* @returns {number} The parsed number.
|
|
1053
1053
|
*/
|
|
1054
1054
|
function parseNumber(locale, value) {
|
|
1055
1055
|
return parseInt(
|
|
@@ -1711,6 +1711,12 @@
|
|
|
1711
1711
|
* An immutable date and time object with locale-aware formatting and time-zone support.
|
|
1712
1712
|
*/
|
|
1713
1713
|
class DateTime {
|
|
1714
|
+
#date;
|
|
1715
|
+
#dynamicTz;
|
|
1716
|
+
#locale;
|
|
1717
|
+
#offset;
|
|
1718
|
+
#timeZone;
|
|
1719
|
+
|
|
1714
1720
|
/**
|
|
1715
1721
|
* Clears cached formatter and locale data.
|
|
1716
1722
|
*/
|
|
@@ -1723,7 +1729,7 @@
|
|
|
1723
1729
|
* @param {number} year The year.
|
|
1724
1730
|
* @param {number} month The month. (1-12)
|
|
1725
1731
|
* @param {number} date The date.
|
|
1726
|
-
* @
|
|
1732
|
+
* @returns {number} The day of the year. (1-366)
|
|
1727
1733
|
*/
|
|
1728
1734
|
static dayOfYear(year, month, date) {
|
|
1729
1735
|
return new Array(month - 1)
|
|
@@ -1739,7 +1745,7 @@
|
|
|
1739
1745
|
* Gets the number of days in a month for a given year.
|
|
1740
1746
|
* @param {number} year The year.
|
|
1741
1747
|
* @param {number} month The month. (1-12)
|
|
1742
|
-
* @
|
|
1748
|
+
* @returns {number} The number of days in the month.
|
|
1743
1749
|
*/
|
|
1744
1750
|
static daysInMonth(year, month) {
|
|
1745
1751
|
const date = new Date(0);
|
|
@@ -1759,7 +1765,7 @@
|
|
|
1759
1765
|
/**
|
|
1760
1766
|
* Gets the number of days in a given year.
|
|
1761
1767
|
* @param {number} year The year.
|
|
1762
|
-
* @
|
|
1768
|
+
* @returns {number} The number of days in the year.
|
|
1763
1769
|
*/
|
|
1764
1770
|
static daysInYear(year) {
|
|
1765
1771
|
return !this.isLeapYear(year) ?
|
|
@@ -1774,7 +1780,7 @@
|
|
|
1774
1780
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
1775
1781
|
* @param {string} [options.timeZone] The time zone to use.
|
|
1776
1782
|
* @param {string} [options.locale] The locale to use.
|
|
1777
|
-
* @
|
|
1783
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1778
1784
|
*/
|
|
1779
1785
|
static fromArray(dateArray, options = {}) {
|
|
1780
1786
|
const dateValues = dateArray.slice(0, 3);
|
|
@@ -1800,7 +1806,7 @@
|
|
|
1800
1806
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
1801
1807
|
* @param {string} [options.timeZone] The time zone to use.
|
|
1802
1808
|
* @param {string} [options.locale] The locale to use.
|
|
1803
|
-
* @
|
|
1809
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1804
1810
|
*/
|
|
1805
1811
|
static fromDate(date, options = {}) {
|
|
1806
1812
|
return new this(date.getTime(), options);
|
|
@@ -1813,9 +1819,9 @@
|
|
|
1813
1819
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
1814
1820
|
* @param {string} [options.timeZone] The time zone to use.
|
|
1815
1821
|
* @param {string} [options.locale] The locale to use.
|
|
1816
|
-
* @
|
|
1822
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1823
|
+
* @throws {Error} When the format contains unsupported parsing tokens such as
|
|
1817
1824
|
* `MMMMM` or `LLLLL`.
|
|
1818
|
-
* @return {DateTime} A new DateTime instance.
|
|
1819
1825
|
*/
|
|
1820
1826
|
static fromFormat(formatString, dateString, options = {}) {
|
|
1821
1827
|
const locale = 'locale' in options ?
|
|
@@ -1963,7 +1969,7 @@
|
|
|
1963
1969
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
1964
1970
|
* @param {string} [options.timeZone] The time zone to use.
|
|
1965
1971
|
* @param {string} [options.locale] The locale to use.
|
|
1966
|
-
* @
|
|
1972
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1967
1973
|
*/
|
|
1968
1974
|
static fromISOString(dateString, options = {}) {
|
|
1969
1975
|
let date = this.fromFormat(formats.rfc3339_extended, dateString, {
|
|
@@ -1987,7 +1993,7 @@
|
|
|
1987
1993
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
1988
1994
|
* @param {string} [options.timeZone] The time zone to use.
|
|
1989
1995
|
* @param {string} [options.locale] The locale to use.
|
|
1990
|
-
* @
|
|
1996
|
+
* @returns {DateTime} A new DateTime instance.
|
|
1991
1997
|
*/
|
|
1992
1998
|
static fromTimestamp(timestamp, options = {}) {
|
|
1993
1999
|
return new this(null, options)
|
|
@@ -1996,7 +2002,7 @@
|
|
|
1996
2002
|
|
|
1997
2003
|
/**
|
|
1998
2004
|
* Gets the default locale.
|
|
1999
|
-
* @
|
|
2005
|
+
* @returns {string} The locale.
|
|
2000
2006
|
*/
|
|
2001
2007
|
static getDefaultLocale() {
|
|
2002
2008
|
return config.defaultLocale;
|
|
@@ -2004,7 +2010,7 @@
|
|
|
2004
2010
|
|
|
2005
2011
|
/**
|
|
2006
2012
|
* Gets the default time zone.
|
|
2007
|
-
* @
|
|
2013
|
+
* @returns {string} The default time zone.
|
|
2008
2014
|
*/
|
|
2009
2015
|
static getDefaultTimeZone() {
|
|
2010
2016
|
return config.defaultTimeZone;
|
|
@@ -2013,7 +2019,7 @@
|
|
|
2013
2019
|
/**
|
|
2014
2020
|
* Checks whether the year is a leap year.
|
|
2015
2021
|
* @param {number} year The year.
|
|
2016
|
-
* @
|
|
2022
|
+
* @returns {boolean} Whether the given year is a leap year.
|
|
2017
2023
|
*/
|
|
2018
2024
|
static isLeapYear(year) {
|
|
2019
2025
|
const date = new Date(0);
|
|
@@ -2027,7 +2033,7 @@
|
|
|
2027
2033
|
* @param {DateTimeOptions} [options={}] Options for the new DateTime.
|
|
2028
2034
|
* @param {string} [options.timeZone] The time zone to use.
|
|
2029
2035
|
* @param {string} [options.locale] The locale to use.
|
|
2030
|
-
* @
|
|
2036
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2031
2037
|
*/
|
|
2032
2038
|
static now(options = {}) {
|
|
2033
2039
|
return new this(null, options);
|
|
@@ -2094,8 +2100,8 @@
|
|
|
2094
2100
|
throw new Error('Invalid date supplied');
|
|
2095
2101
|
}
|
|
2096
2102
|
|
|
2097
|
-
this
|
|
2098
|
-
this
|
|
2103
|
+
this.#date = new Date(timestamp);
|
|
2104
|
+
this.#dynamicTz = false;
|
|
2099
2105
|
this.isValid = true;
|
|
2100
2106
|
|
|
2101
2107
|
let timeZone = options.timeZone;
|
|
@@ -2110,43 +2116,43 @@
|
|
|
2110
2116
|
|
|
2111
2117
|
const match = timeZone.match(offsetRegExp);
|
|
2112
2118
|
if (match) {
|
|
2113
|
-
this
|
|
2119
|
+
this.#offset =
|
|
2114
2120
|
match[2] * 60 +
|
|
2115
2121
|
parseInt(match[4] || 0, 10) +
|
|
2116
2122
|
parseInt(match[5] || 0, 10) / 60;
|
|
2117
|
-
if (this
|
|
2118
|
-
this
|
|
2123
|
+
if (this.#offset && match[1] === '+') {
|
|
2124
|
+
this.#offset *= -1;
|
|
2119
2125
|
}
|
|
2120
2126
|
|
|
2121
|
-
if (this
|
|
2122
|
-
this
|
|
2127
|
+
if (this.#offset) {
|
|
2128
|
+
this.#timeZone = formatOffset(this.#offset);
|
|
2123
2129
|
} else {
|
|
2124
|
-
this
|
|
2125
|
-
this
|
|
2130
|
+
this.#dynamicTz = true;
|
|
2131
|
+
this.#timeZone = 'UTC';
|
|
2126
2132
|
}
|
|
2127
2133
|
} else {
|
|
2128
|
-
this
|
|
2129
|
-
this
|
|
2134
|
+
this.#dynamicTz = true;
|
|
2135
|
+
this.#timeZone = timeZone;
|
|
2130
2136
|
}
|
|
2131
2137
|
|
|
2132
|
-
this
|
|
2138
|
+
this.#locale = 'locale' in options ?
|
|
2133
2139
|
options.locale :
|
|
2134
2140
|
config.defaultLocale;
|
|
2135
2141
|
|
|
2136
|
-
if (this
|
|
2137
|
-
this
|
|
2142
|
+
if (this.#dynamicTz) {
|
|
2143
|
+
this.#offset = getOffset(this);
|
|
2138
2144
|
}
|
|
2139
2145
|
|
|
2140
|
-
if (adjustOffset && this
|
|
2146
|
+
if (adjustOffset && this.#offset) {
|
|
2141
2147
|
const resolvedDate = setOffsetTime(this, timestamp);
|
|
2142
|
-
this.
|
|
2143
|
-
this
|
|
2148
|
+
this.#date.setTime(resolvedDate.getTime());
|
|
2149
|
+
this.#offset = resolvedDate.getTimeZoneOffset();
|
|
2144
2150
|
}
|
|
2145
2151
|
}
|
|
2146
2152
|
|
|
2147
2153
|
/**
|
|
2148
2154
|
* Adds a day to the current DateTime.
|
|
2149
|
-
* @
|
|
2155
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2150
2156
|
*/
|
|
2151
2157
|
addDay() {
|
|
2152
2158
|
return this.addDays(1);
|
|
@@ -2155,7 +2161,7 @@
|
|
|
2155
2161
|
/**
|
|
2156
2162
|
* Adds days to the current DateTime.
|
|
2157
2163
|
* @param {number} amount The number of days to add.
|
|
2158
|
-
* @
|
|
2164
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2159
2165
|
*/
|
|
2160
2166
|
addDays(amount) {
|
|
2161
2167
|
return setOffsetTime(
|
|
@@ -2169,7 +2175,7 @@
|
|
|
2169
2175
|
|
|
2170
2176
|
/**
|
|
2171
2177
|
* Adds an hour to the current DateTime.
|
|
2172
|
-
* @
|
|
2178
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2173
2179
|
*/
|
|
2174
2180
|
addHour() {
|
|
2175
2181
|
return this.addHours(1);
|
|
@@ -2178,7 +2184,7 @@
|
|
|
2178
2184
|
/**
|
|
2179
2185
|
* Adds hours to the current DateTime.
|
|
2180
2186
|
* @param {number} amount The number of hours to add.
|
|
2181
|
-
* @
|
|
2187
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2182
2188
|
*/
|
|
2183
2189
|
addHours(amount) {
|
|
2184
2190
|
return this.withTime(
|
|
@@ -2188,7 +2194,7 @@
|
|
|
2188
2194
|
|
|
2189
2195
|
/**
|
|
2190
2196
|
* Adds a minute to the current DateTime.
|
|
2191
|
-
* @
|
|
2197
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2192
2198
|
*/
|
|
2193
2199
|
addMinute() {
|
|
2194
2200
|
return this.addMinutes(1);
|
|
@@ -2197,7 +2203,7 @@
|
|
|
2197
2203
|
/**
|
|
2198
2204
|
* Adds minutes to the current DateTime.
|
|
2199
2205
|
* @param {number} amount The number of minutes to add.
|
|
2200
|
-
* @
|
|
2206
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2201
2207
|
*/
|
|
2202
2208
|
addMinutes(amount) {
|
|
2203
2209
|
return this.withTime(
|
|
@@ -2207,7 +2213,7 @@
|
|
|
2207
2213
|
|
|
2208
2214
|
/**
|
|
2209
2215
|
* Adds a month to the current DateTime.
|
|
2210
|
-
* @
|
|
2216
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2211
2217
|
*/
|
|
2212
2218
|
addMonth() {
|
|
2213
2219
|
return this.addMonths(1);
|
|
@@ -2216,7 +2222,7 @@
|
|
|
2216
2222
|
/**
|
|
2217
2223
|
* Adds months to the current DateTime.
|
|
2218
2224
|
* @param {number} amount The number of months to add.
|
|
2219
|
-
* @
|
|
2225
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2220
2226
|
*/
|
|
2221
2227
|
addMonths(amount) {
|
|
2222
2228
|
return this.withMonth(
|
|
@@ -2226,7 +2232,7 @@
|
|
|
2226
2232
|
|
|
2227
2233
|
/**
|
|
2228
2234
|
* Adds a second to the current DateTime.
|
|
2229
|
-
* @
|
|
2235
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2230
2236
|
*/
|
|
2231
2237
|
addSecond() {
|
|
2232
2238
|
return this.addSeconds(1);
|
|
@@ -2235,7 +2241,7 @@
|
|
|
2235
2241
|
/**
|
|
2236
2242
|
* Adds seconds to the current DateTime.
|
|
2237
2243
|
* @param {number} amount The number of seconds to add.
|
|
2238
|
-
* @
|
|
2244
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2239
2245
|
*/
|
|
2240
2246
|
addSeconds(amount) {
|
|
2241
2247
|
return this.withTime(
|
|
@@ -2245,7 +2251,7 @@
|
|
|
2245
2251
|
|
|
2246
2252
|
/**
|
|
2247
2253
|
* Adds a week to the current DateTime.
|
|
2248
|
-
* @
|
|
2254
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2249
2255
|
*/
|
|
2250
2256
|
addWeek() {
|
|
2251
2257
|
return this.addWeeks(1);
|
|
@@ -2254,7 +2260,7 @@
|
|
|
2254
2260
|
/**
|
|
2255
2261
|
* Adds weeks to the current DateTime.
|
|
2256
2262
|
* @param {number} amount The number of weeks to add.
|
|
2257
|
-
* @
|
|
2263
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2258
2264
|
*/
|
|
2259
2265
|
addWeeks(amount) {
|
|
2260
2266
|
return this.withDate(
|
|
@@ -2264,7 +2270,7 @@
|
|
|
2264
2270
|
|
|
2265
2271
|
/**
|
|
2266
2272
|
* Adds a year to the current DateTime.
|
|
2267
|
-
* @
|
|
2273
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2268
2274
|
*/
|
|
2269
2275
|
addYear() {
|
|
2270
2276
|
return this.addYears(1);
|
|
@@ -2273,7 +2279,7 @@
|
|
|
2273
2279
|
/**
|
|
2274
2280
|
* Adds years to the current DateTime.
|
|
2275
2281
|
* @param {number} amount The number of years to add.
|
|
2276
|
-
* @
|
|
2282
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2277
2283
|
*/
|
|
2278
2284
|
addYears(amount) {
|
|
2279
2285
|
return this.withYear(
|
|
@@ -2284,7 +2290,7 @@
|
|
|
2284
2290
|
/**
|
|
2285
2291
|
* Gets the localized day name for the current date.
|
|
2286
2292
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of day name to return.
|
|
2287
|
-
* @
|
|
2293
|
+
* @returns {string} The localized day name.
|
|
2288
2294
|
*/
|
|
2289
2295
|
dayName(type = 'long') {
|
|
2290
2296
|
return formatDay(this.getLocale(), this.getDay(), type);
|
|
@@ -2293,7 +2299,7 @@
|
|
|
2293
2299
|
/**
|
|
2294
2300
|
* Gets the localized day period for the current time.
|
|
2295
2301
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of day period to return.
|
|
2296
|
-
* @
|
|
2302
|
+
* @returns {string} The localized day period.
|
|
2297
2303
|
*/
|
|
2298
2304
|
dayPeriod(type = 'long') {
|
|
2299
2305
|
return formatDayPeriod(
|
|
@@ -2307,7 +2313,7 @@
|
|
|
2307
2313
|
|
|
2308
2314
|
/**
|
|
2309
2315
|
* Gets the number of days in the current month.
|
|
2310
|
-
* @
|
|
2316
|
+
* @returns {number} The number of days in the current month.
|
|
2311
2317
|
*/
|
|
2312
2318
|
daysInMonth() {
|
|
2313
2319
|
return this.constructor.daysInMonth(
|
|
@@ -2318,7 +2324,7 @@
|
|
|
2318
2324
|
|
|
2319
2325
|
/**
|
|
2320
2326
|
* Gets the number of days in the current year.
|
|
2321
|
-
* @
|
|
2327
|
+
* @returns {number} The number of days in the current year.
|
|
2322
2328
|
*/
|
|
2323
2329
|
daysInYear() {
|
|
2324
2330
|
return this.constructor.daysInYear(
|
|
@@ -2329,7 +2335,7 @@
|
|
|
2329
2335
|
/**
|
|
2330
2336
|
* Gets the difference between this and another Date in milliseconds.
|
|
2331
2337
|
* @param {DateTime} other The date to compare to.
|
|
2332
|
-
* @
|
|
2338
|
+
* @returns {number} The difference.
|
|
2333
2339
|
*/
|
|
2334
2340
|
diff(other) {
|
|
2335
2341
|
return this - other;
|
|
@@ -2339,7 +2345,7 @@
|
|
|
2339
2345
|
* Gets the difference between this and another Date in days.
|
|
2340
2346
|
* @param {DateTime} other The date to compare to.
|
|
2341
2347
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2342
|
-
* @
|
|
2348
|
+
* @returns {number} The difference.
|
|
2343
2349
|
*/
|
|
2344
2350
|
diffInDays(other, { relative = true } = {}) {
|
|
2345
2351
|
return calculateDiff(this, other, 'day', relative);
|
|
@@ -2349,7 +2355,7 @@
|
|
|
2349
2355
|
* Gets the difference between this and another Date in hours.
|
|
2350
2356
|
* @param {DateTime} other The date to compare to.
|
|
2351
2357
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2352
|
-
* @
|
|
2358
|
+
* @returns {number} The difference.
|
|
2353
2359
|
*/
|
|
2354
2360
|
diffInHours(other, { relative = true } = {}) {
|
|
2355
2361
|
return calculateDiff(this, other, 'hour', relative);
|
|
@@ -2359,7 +2365,7 @@
|
|
|
2359
2365
|
* Gets the difference between this and another Date in minutes.
|
|
2360
2366
|
* @param {DateTime} other The date to compare to.
|
|
2361
2367
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2362
|
-
* @
|
|
2368
|
+
* @returns {number} The difference.
|
|
2363
2369
|
*/
|
|
2364
2370
|
diffInMinutes(other, { relative = true } = {}) {
|
|
2365
2371
|
return calculateDiff(this, other, 'minute', relative);
|
|
@@ -2369,7 +2375,7 @@
|
|
|
2369
2375
|
* Gets the difference between this and another Date in months.
|
|
2370
2376
|
* @param {DateTime} other The date to compare to.
|
|
2371
2377
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2372
|
-
* @
|
|
2378
|
+
* @returns {number} The difference.
|
|
2373
2379
|
*/
|
|
2374
2380
|
diffInMonths(other, { relative = true } = {}) {
|
|
2375
2381
|
return calculateDiff(this, other, 'month', relative);
|
|
@@ -2379,7 +2385,7 @@
|
|
|
2379
2385
|
* Gets the difference between this and another Date in seconds.
|
|
2380
2386
|
* @param {DateTime} other The date to compare to.
|
|
2381
2387
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2382
|
-
* @
|
|
2388
|
+
* @returns {number} The difference.
|
|
2383
2389
|
*/
|
|
2384
2390
|
diffInSeconds(other, { relative = true } = {}) {
|
|
2385
2391
|
return calculateDiff(this, other, 'second', relative);
|
|
@@ -2389,7 +2395,7 @@
|
|
|
2389
2395
|
* Gets the difference between this and another Date in weeks.
|
|
2390
2396
|
* @param {DateTime} other The date to compare to.
|
|
2391
2397
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2392
|
-
* @
|
|
2398
|
+
* @returns {number} The difference.
|
|
2393
2399
|
*/
|
|
2394
2400
|
diffInWeeks(other, { relative = true } = {}) {
|
|
2395
2401
|
return calculateDiff(this, other, 'week', relative);
|
|
@@ -2399,7 +2405,7 @@
|
|
|
2399
2405
|
* Gets the difference between this and another Date in years.
|
|
2400
2406
|
* @param {DateTime} other The date to compare to.
|
|
2401
2407
|
* @param {{relative?: boolean}} [options] Options for comparing the dates.
|
|
2402
|
-
* @
|
|
2408
|
+
* @returns {number} The difference.
|
|
2403
2409
|
*/
|
|
2404
2410
|
diffInYears(other, { relative = true } = {}) {
|
|
2405
2411
|
return calculateDiff(this, other, 'year', relative);
|
|
@@ -2407,7 +2413,7 @@
|
|
|
2407
2413
|
|
|
2408
2414
|
/**
|
|
2409
2415
|
* Sets the DateTime to the end of the day.
|
|
2410
|
-
* @
|
|
2416
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2411
2417
|
*/
|
|
2412
2418
|
endOfDay() {
|
|
2413
2419
|
return this.withHours(23, 59, 59, 999);
|
|
@@ -2415,7 +2421,7 @@
|
|
|
2415
2421
|
|
|
2416
2422
|
/**
|
|
2417
2423
|
* Sets the DateTime to the end of the hour.
|
|
2418
|
-
* @
|
|
2424
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2419
2425
|
*/
|
|
2420
2426
|
endOfHour() {
|
|
2421
2427
|
return this.withMinutes(59, 59, 999);
|
|
@@ -2423,7 +2429,7 @@
|
|
|
2423
2429
|
|
|
2424
2430
|
/**
|
|
2425
2431
|
* Sets the DateTime to the end of the minute.
|
|
2426
|
-
* @
|
|
2432
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2427
2433
|
*/
|
|
2428
2434
|
endOfMinute() {
|
|
2429
2435
|
return this.withSeconds(59, 999);
|
|
@@ -2431,7 +2437,7 @@
|
|
|
2431
2437
|
|
|
2432
2438
|
/**
|
|
2433
2439
|
* Sets the DateTime to the end of the month.
|
|
2434
|
-
* @
|
|
2440
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2435
2441
|
*/
|
|
2436
2442
|
endOfMonth() {
|
|
2437
2443
|
return this.withDate(this.daysInMonth())
|
|
@@ -2440,7 +2446,7 @@
|
|
|
2440
2446
|
|
|
2441
2447
|
/**
|
|
2442
2448
|
* Sets the DateTime to the end of the quarter.
|
|
2443
|
-
* @
|
|
2449
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2444
2450
|
*/
|
|
2445
2451
|
endOfQuarter() {
|
|
2446
2452
|
const month = this.getQuarter() * 3;
|
|
@@ -2450,7 +2456,7 @@
|
|
|
2450
2456
|
|
|
2451
2457
|
/**
|
|
2452
2458
|
* Sets the DateTime to the end of the second.
|
|
2453
|
-
* @
|
|
2459
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2454
2460
|
*/
|
|
2455
2461
|
endOfSecond() {
|
|
2456
2462
|
return this.withMilliseconds(999);
|
|
@@ -2458,7 +2464,7 @@
|
|
|
2458
2464
|
|
|
2459
2465
|
/**
|
|
2460
2466
|
* Sets the DateTime to the end of the week.
|
|
2461
|
-
* @
|
|
2467
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2462
2468
|
*/
|
|
2463
2469
|
endOfWeek() {
|
|
2464
2470
|
return this.withWeekDay(7)
|
|
@@ -2467,7 +2473,7 @@
|
|
|
2467
2473
|
|
|
2468
2474
|
/**
|
|
2469
2475
|
* Sets the DateTime to the end of the year.
|
|
2470
|
-
* @
|
|
2476
|
+
* @returns {DateTime} A new DateTime instance.
|
|
2471
2477
|
*/
|
|
2472
2478
|
endOfYear() {
|
|
2473
2479
|
return this.withMonth(12, 31)
|
|
@@ -2477,7 +2483,7 @@
|
|
|
2477
2483
|
/**
|
|
2478
2484
|
* Gets the localized era for the current date.
|
|
2479
2485
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of era to return.
|
|
2480
|
-
* @
|
|
2486
|
+
* @returns {string} The localized era.
|
|
2481
2487
|
*/
|
|
2482
2488
|
era(type = 'long') {
|
|
2483
2489
|
return formatEra(
|
|
@@ -2492,7 +2498,7 @@
|
|
|
2492
2498
|
/**
|
|
2493
2499
|
* Formats the current date using a format string.
|
|
2494
2500
|
* @param {string} formatString The format string.
|
|
2495
|
-
* @
|
|
2501
|
+
* @returns {string} The formatted date string.
|
|
2496
2502
|
*/
|
|
2497
2503
|
format(formatString) {
|
|
2498
2504
|
let match;
|
|
@@ -2532,7 +2538,7 @@
|
|
|
2532
2538
|
|
|
2533
2539
|
/**
|
|
2534
2540
|
* Gets the date of the month in the current time zone.
|
|
2535
|
-
* @
|
|
2541
|
+
* @returns {number} The date of the month.
|
|
2536
2542
|
*/
|
|
2537
2543
|
getDate() {
|
|
2538
2544
|
return new Date(getOffsetTime(this)).getUTCDate();
|
|
@@ -2540,7 +2546,7 @@
|
|
|
2540
2546
|
|
|
2541
2547
|
/**
|
|
2542
2548
|
* Gets the day of the week in the current time zone.
|
|
2543
|
-
* @
|
|
2549
|
+
* @returns {number} The day of the week. (0 = Sunday, 6 = Saturday)
|
|
2544
2550
|
*/
|
|
2545
2551
|
getDay() {
|
|
2546
2552
|
return new Date(getOffsetTime(this)).getUTCDay();
|
|
@@ -2548,7 +2554,7 @@
|
|
|
2548
2554
|
|
|
2549
2555
|
/**
|
|
2550
2556
|
* Gets the day of the year in the current time zone.
|
|
2551
|
-
* @
|
|
2557
|
+
* @returns {number} The day of the year. (1-366)
|
|
2552
2558
|
*/
|
|
2553
2559
|
getDayOfYear() {
|
|
2554
2560
|
return this.constructor.dayOfYear(
|
|
@@ -2560,7 +2566,7 @@
|
|
|
2560
2566
|
|
|
2561
2567
|
/**
|
|
2562
2568
|
* Gets the hours of the day in the current time zone.
|
|
2563
|
-
* @
|
|
2569
|
+
* @returns {number} The hours of the day. (0-23)
|
|
2564
2570
|
*/
|
|
2565
2571
|
getHours() {
|
|
2566
2572
|
return new Date(getOffsetTime(this)).getUTCHours();
|
|
@@ -2568,15 +2574,15 @@
|
|
|
2568
2574
|
|
|
2569
2575
|
/**
|
|
2570
2576
|
* Gets the current locale.
|
|
2571
|
-
* @
|
|
2577
|
+
* @returns {string} The locale.
|
|
2572
2578
|
*/
|
|
2573
2579
|
getLocale() {
|
|
2574
|
-
return this
|
|
2580
|
+
return this.#locale;
|
|
2575
2581
|
}
|
|
2576
2582
|
|
|
2577
2583
|
/**
|
|
2578
2584
|
* Gets the milliseconds in the current time zone.
|
|
2579
|
-
* @
|
|
2585
|
+
* @returns {number} The milliseconds.
|
|
2580
2586
|
*/
|
|
2581
2587
|
getMilliseconds() {
|
|
2582
2588
|
return new Date(getOffsetTime(this)).getUTCMilliseconds();
|
|
@@ -2584,7 +2590,7 @@
|
|
|
2584
2590
|
|
|
2585
2591
|
/**
|
|
2586
2592
|
* Gets the minutes in the current time zone.
|
|
2587
|
-
* @
|
|
2593
|
+
* @returns {number} The minutes. (0-59)
|
|
2588
2594
|
*/
|
|
2589
2595
|
getMinutes() {
|
|
2590
2596
|
return new Date(getOffsetTime(this)).getUTCMinutes();
|
|
@@ -2592,7 +2598,7 @@
|
|
|
2592
2598
|
|
|
2593
2599
|
/**
|
|
2594
2600
|
* Gets the month in the current time zone.
|
|
2595
|
-
* @
|
|
2601
|
+
* @returns {number} The month. (1-12)
|
|
2596
2602
|
*/
|
|
2597
2603
|
getMonth() {
|
|
2598
2604
|
return new Date(getOffsetTime(this)).getUTCMonth() + 1;
|
|
@@ -2600,7 +2606,7 @@
|
|
|
2600
2606
|
|
|
2601
2607
|
/**
|
|
2602
2608
|
* Gets the quarter of the year in the current time zone.
|
|
2603
|
-
* @
|
|
2609
|
+
* @returns {number} The quarter of the year. (1-4)
|
|
2604
2610
|
*/
|
|
2605
2611
|
getQuarter() {
|
|
2606
2612
|
return Math.ceil(this.getMonth() / 3);
|
|
@@ -2608,7 +2614,7 @@
|
|
|
2608
2614
|
|
|
2609
2615
|
/**
|
|
2610
2616
|
* Gets the seconds in the current time zone.
|
|
2611
|
-
* @
|
|
2617
|
+
* @returns {number} The seconds. (0-59)
|
|
2612
2618
|
*/
|
|
2613
2619
|
getSeconds() {
|
|
2614
2620
|
return new Date(getOffsetTime(this)).getUTCSeconds();
|
|
@@ -2616,15 +2622,15 @@
|
|
|
2616
2622
|
|
|
2617
2623
|
/**
|
|
2618
2624
|
* Gets the number of milliseconds since the UNIX epoch.
|
|
2619
|
-
* @
|
|
2625
|
+
* @returns {number} The number of milliseconds since the UNIX epoch.
|
|
2620
2626
|
*/
|
|
2621
2627
|
getTime() {
|
|
2622
|
-
return this.
|
|
2628
|
+
return this.#date.getTime();
|
|
2623
2629
|
}
|
|
2624
2630
|
|
|
2625
2631
|
/**
|
|
2626
2632
|
* Gets the number of seconds since the UNIX epoch.
|
|
2627
|
-
* @
|
|
2633
|
+
* @returns {number} The number of seconds since the UNIX epoch.
|
|
2628
2634
|
*/
|
|
2629
2635
|
getTimestamp() {
|
|
2630
2636
|
return Math.floor(this.getTime() / 1000);
|
|
@@ -2632,23 +2638,23 @@
|
|
|
2632
2638
|
|
|
2633
2639
|
/**
|
|
2634
2640
|
* Gets the current time zone.
|
|
2635
|
-
* @
|
|
2641
|
+
* @returns {string} The time zone.
|
|
2636
2642
|
*/
|
|
2637
2643
|
getTimeZone() {
|
|
2638
|
-
return this
|
|
2644
|
+
return this.#timeZone;
|
|
2639
2645
|
}
|
|
2640
2646
|
|
|
2641
2647
|
/**
|
|
2642
2648
|
* Gets the current UTC offset in minutes.
|
|
2643
|
-
* @
|
|
2649
|
+
* @returns {number} The UTC offset in minutes.
|
|
2644
2650
|
*/
|
|
2645
2651
|
getTimeZoneOffset() {
|
|
2646
|
-
return this
|
|
2652
|
+
return this.#offset;
|
|
2647
2653
|
}
|
|
2648
2654
|
|
|
2649
2655
|
/**
|
|
2650
2656
|
* Gets the local week in the current time zone.
|
|
2651
|
-
* @
|
|
2657
|
+
* @returns {number} The local week. (1-53)
|
|
2652
2658
|
*/
|
|
2653
2659
|
getWeek() {
|
|
2654
2660
|
const thisWeek = this.startOfDay().withWeekDay(1);
|
|
@@ -2662,7 +2668,7 @@
|
|
|
2662
2668
|
|
|
2663
2669
|
/**
|
|
2664
2670
|
* Gets the local day of the week in the current time zone.
|
|
2665
|
-
* @
|
|
2671
|
+
* @returns {number} The local day of the week. (1-7)
|
|
2666
2672
|
*/
|
|
2667
2673
|
getWeekDay() {
|
|
2668
2674
|
return weekDay(
|
|
@@ -2673,7 +2679,7 @@
|
|
|
2673
2679
|
|
|
2674
2680
|
/**
|
|
2675
2681
|
* Gets the week day in month in the current time zone.
|
|
2676
|
-
* @
|
|
2682
|
+
* @returns {number} The week day in month.
|
|
2677
2683
|
*/
|
|
2678
2684
|
getWeekDayInMonth() {
|
|
2679
2685
|
const thisWeek = this.getWeek();
|
|
@@ -2688,7 +2694,7 @@
|
|
|
2688
2694
|
|
|
2689
2695
|
/**
|
|
2690
2696
|
* Gets the week of month in the current time zone.
|
|
2691
|
-
* @
|
|
2697
|
+
* @returns {number} The week of month.
|
|
2692
2698
|
*/
|
|
2693
2699
|
getWeekOfMonth() {
|
|
2694
2700
|
const thisWeek = this.getWeek();
|
|
@@ -2700,7 +2706,7 @@
|
|
|
2700
2706
|
|
|
2701
2707
|
/**
|
|
2702
2708
|
* Gets the week year in the current time zone.
|
|
2703
|
-
* @
|
|
2709
|
+
* @returns {number} The week year.
|
|
2704
2710
|
*/
|
|
2705
2711
|
getWeekYear() {
|
|
2706
2712
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -2709,7 +2715,7 @@
|
|
|
2709
2715
|
|
|
2710
2716
|
/**
|
|
2711
2717
|
* Gets the year in the current time zone.
|
|
2712
|
-
* @
|
|
2718
|
+
* @returns {number} The year.
|
|
2713
2719
|
*/
|
|
2714
2720
|
getYear() {
|
|
2715
2721
|
return new Date(getOffsetTime(this)).getUTCFullYear();
|
|
@@ -2718,7 +2724,7 @@
|
|
|
2718
2724
|
/**
|
|
2719
2725
|
* Gets the difference between this and another Date in human readable form.
|
|
2720
2726
|
* @param {DateTime} other The date to compare to.
|
|
2721
|
-
* @
|
|
2727
|
+
* @returns {string} The difference in human readable form.
|
|
2722
2728
|
*/
|
|
2723
2729
|
humanDiff(other) {
|
|
2724
2730
|
const [amount, unit] = getBiggestDiff(this, other);
|
|
@@ -2728,7 +2734,7 @@
|
|
|
2728
2734
|
/**
|
|
2729
2735
|
* Gets the difference between this and another Date in days in human readable form.
|
|
2730
2736
|
* @param {DateTime} other The date to compare to.
|
|
2731
|
-
* @
|
|
2737
|
+
* @returns {string} The difference in days in human readable form.
|
|
2732
2738
|
*/
|
|
2733
2739
|
humanDiffInDays(other) {
|
|
2734
2740
|
return formatRelative(this.getLocale(), this.diffInDays(other), 'day');
|
|
@@ -2737,7 +2743,7 @@
|
|
|
2737
2743
|
/**
|
|
2738
2744
|
* Gets the difference between this and another Date in hours in human readable form.
|
|
2739
2745
|
* @param {DateTime} other The date to compare to.
|
|
2740
|
-
* @
|
|
2746
|
+
* @returns {string} The difference in hours in human readable form.
|
|
2741
2747
|
*/
|
|
2742
2748
|
humanDiffInHours(other) {
|
|
2743
2749
|
return formatRelative(this.getLocale(), this.diffInHours(other), 'hour');
|
|
@@ -2746,7 +2752,7 @@
|
|
|
2746
2752
|
/**
|
|
2747
2753
|
* Gets the difference between this and another Date in minutes in human readable form.
|
|
2748
2754
|
* @param {DateTime} other The date to compare to.
|
|
2749
|
-
* @
|
|
2755
|
+
* @returns {string} The difference in minutes in human readable form.
|
|
2750
2756
|
*/
|
|
2751
2757
|
humanDiffInMinutes(other) {
|
|
2752
2758
|
return formatRelative(this.getLocale(), this.diffInMinutes(other), 'minute');
|
|
@@ -2755,7 +2761,7 @@
|
|
|
2755
2761
|
/**
|
|
2756
2762
|
* Gets the difference between this and another Date in months in human readable form.
|
|
2757
2763
|
* @param {DateTime} other The date to compare to.
|
|
2758
|
-
* @
|
|
2764
|
+
* @returns {string} The difference in months in human readable form.
|
|
2759
2765
|
*/
|
|
2760
2766
|
humanDiffInMonths(other) {
|
|
2761
2767
|
return formatRelative(this.getLocale(), this.diffInMonths(other), 'month');
|
|
@@ -2764,7 +2770,7 @@
|
|
|
2764
2770
|
/**
|
|
2765
2771
|
* Gets the difference between this and another Date in seconds in human readable form.
|
|
2766
2772
|
* @param {DateTime} other The date to compare to.
|
|
2767
|
-
* @
|
|
2773
|
+
* @returns {string} The difference in seconds in human readable form.
|
|
2768
2774
|
*/
|
|
2769
2775
|
humanDiffInSeconds(other) {
|
|
2770
2776
|
return formatRelative(this.getLocale(), this.diffInSeconds(other), 'second');
|
|
@@ -2773,7 +2779,7 @@
|
|
|
2773
2779
|
/**
|
|
2774
2780
|
* Gets the difference between this and another Date in weeks in human readable form.
|
|
2775
2781
|
* @param {DateTime} other The date to compare to.
|
|
2776
|
-
* @
|
|
2782
|
+
* @returns {string} The difference in weeks in human readable form.
|
|
2777
2783
|
*/
|
|
2778
2784
|
humanDiffInWeeks(other) {
|
|
2779
2785
|
return formatRelative(this.getLocale(), this.diffInWeeks(other), 'week');
|
|
@@ -2782,7 +2788,7 @@
|
|
|
2782
2788
|
/**
|
|
2783
2789
|
* Gets the difference between this and another Date in years in human readable form.
|
|
2784
2790
|
* @param {DateTime} other The date to compare to.
|
|
2785
|
-
* @
|
|
2791
|
+
* @returns {string} The difference in years in human readable form.
|
|
2786
2792
|
*/
|
|
2787
2793
|
humanDiffInYears(other) {
|
|
2788
2794
|
return formatRelative(this.getLocale(), this.diffInYears(other), 'year');
|
|
@@ -2791,7 +2797,7 @@
|
|
|
2791
2797
|
/**
|
|
2792
2798
|
* Checks whether this DateTime is after another date.
|
|
2793
2799
|
* @param {DateTime} other The date to compare to.
|
|
2794
|
-
* @
|
|
2800
|
+
* @returns {boolean} Whether this DateTime is after the other date.
|
|
2795
2801
|
*/
|
|
2796
2802
|
isAfter(other) {
|
|
2797
2803
|
return this.diff(other) > 0;
|
|
@@ -2800,7 +2806,7 @@
|
|
|
2800
2806
|
/**
|
|
2801
2807
|
* Checks whether this DateTime is after another date (comparing by day).
|
|
2802
2808
|
* @param {DateTime} other The date to compare to.
|
|
2803
|
-
* @
|
|
2809
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by day).
|
|
2804
2810
|
*/
|
|
2805
2811
|
isAfterDay(other) {
|
|
2806
2812
|
return this.diffInDays(other) > 0;
|
|
@@ -2809,7 +2815,7 @@
|
|
|
2809
2815
|
/**
|
|
2810
2816
|
* Checks whether this DateTime is after another date (comparing by hour).
|
|
2811
2817
|
* @param {DateTime} other The date to compare to.
|
|
2812
|
-
* @
|
|
2818
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by hour).
|
|
2813
2819
|
*/
|
|
2814
2820
|
isAfterHour(other) {
|
|
2815
2821
|
return this.diffInHours(other) > 0;
|
|
@@ -2818,7 +2824,7 @@
|
|
|
2818
2824
|
/**
|
|
2819
2825
|
* Checks whether this DateTime is after another date (comparing by minute).
|
|
2820
2826
|
* @param {DateTime} other The date to compare to.
|
|
2821
|
-
* @
|
|
2827
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by minute).
|
|
2822
2828
|
*/
|
|
2823
2829
|
isAfterMinute(other) {
|
|
2824
2830
|
return this.diffInMinutes(other) > 0;
|
|
@@ -2827,7 +2833,7 @@
|
|
|
2827
2833
|
/**
|
|
2828
2834
|
* Checks whether this DateTime is after another date (comparing by month).
|
|
2829
2835
|
* @param {DateTime} other The date to compare to.
|
|
2830
|
-
* @
|
|
2836
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by month).
|
|
2831
2837
|
*/
|
|
2832
2838
|
isAfterMonth(other) {
|
|
2833
2839
|
return this.diffInMonths(other) > 0;
|
|
@@ -2836,7 +2842,7 @@
|
|
|
2836
2842
|
/**
|
|
2837
2843
|
* Checks whether this DateTime is after another date (comparing by second).
|
|
2838
2844
|
* @param {DateTime} other The date to compare to.
|
|
2839
|
-
* @
|
|
2845
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by second).
|
|
2840
2846
|
*/
|
|
2841
2847
|
isAfterSecond(other) {
|
|
2842
2848
|
return this.diffInSeconds(other) > 0;
|
|
@@ -2845,7 +2851,7 @@
|
|
|
2845
2851
|
/**
|
|
2846
2852
|
* Checks whether this DateTime is after another date (comparing by week).
|
|
2847
2853
|
* @param {DateTime} other The date to compare to.
|
|
2848
|
-
* @
|
|
2854
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by week).
|
|
2849
2855
|
*/
|
|
2850
2856
|
isAfterWeek(other) {
|
|
2851
2857
|
return this.diffInWeeks(other) > 0;
|
|
@@ -2854,7 +2860,7 @@
|
|
|
2854
2860
|
/**
|
|
2855
2861
|
* Checks whether this DateTime is after another date (comparing by year).
|
|
2856
2862
|
* @param {DateTime} other The date to compare to.
|
|
2857
|
-
* @
|
|
2863
|
+
* @returns {boolean} Whether this DateTime is after the other date (comparing by year).
|
|
2858
2864
|
*/
|
|
2859
2865
|
isAfterYear(other) {
|
|
2860
2866
|
return this.diffInYears(other) > 0;
|
|
@@ -2863,7 +2869,7 @@
|
|
|
2863
2869
|
/**
|
|
2864
2870
|
* Checks whether this DateTime is before another date.
|
|
2865
2871
|
* @param {DateTime} other The date to compare to.
|
|
2866
|
-
* @
|
|
2872
|
+
* @returns {boolean} Whether this DateTime is before the other date.
|
|
2867
2873
|
*/
|
|
2868
2874
|
isBefore(other) {
|
|
2869
2875
|
return this.diff(other) < 0;
|
|
@@ -2872,7 +2878,7 @@
|
|
|
2872
2878
|
/**
|
|
2873
2879
|
* Checks whether this DateTime is before another date (comparing by day).
|
|
2874
2880
|
* @param {DateTime} other The date to compare to.
|
|
2875
|
-
* @
|
|
2881
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by day).
|
|
2876
2882
|
*/
|
|
2877
2883
|
isBeforeDay(other) {
|
|
2878
2884
|
return this.diffInDays(other) < 0;
|
|
@@ -2881,7 +2887,7 @@
|
|
|
2881
2887
|
/**
|
|
2882
2888
|
* Checks whether this DateTime is before another date (comparing by hour).
|
|
2883
2889
|
* @param {DateTime} other The date to compare to.
|
|
2884
|
-
* @
|
|
2890
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by hour).
|
|
2885
2891
|
*/
|
|
2886
2892
|
isBeforeHour(other) {
|
|
2887
2893
|
return this.diffInHours(other) < 0;
|
|
@@ -2890,7 +2896,7 @@
|
|
|
2890
2896
|
/**
|
|
2891
2897
|
* Checks whether this DateTime is before another date (comparing by minute).
|
|
2892
2898
|
* @param {DateTime} other The date to compare to.
|
|
2893
|
-
* @
|
|
2899
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by minute).
|
|
2894
2900
|
*/
|
|
2895
2901
|
isBeforeMinute(other) {
|
|
2896
2902
|
return this.diffInMinutes(other) < 0;
|
|
@@ -2899,7 +2905,7 @@
|
|
|
2899
2905
|
/**
|
|
2900
2906
|
* Checks whether this DateTime is before another date (comparing by month).
|
|
2901
2907
|
* @param {DateTime} other The date to compare to.
|
|
2902
|
-
* @
|
|
2908
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by month).
|
|
2903
2909
|
*/
|
|
2904
2910
|
isBeforeMonth(other) {
|
|
2905
2911
|
return this.diffInMonths(other) < 0;
|
|
@@ -2908,7 +2914,7 @@
|
|
|
2908
2914
|
/**
|
|
2909
2915
|
* Checks whether this DateTime is before another date (comparing by second).
|
|
2910
2916
|
* @param {DateTime} other The date to compare to.
|
|
2911
|
-
* @
|
|
2917
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by second).
|
|
2912
2918
|
*/
|
|
2913
2919
|
isBeforeSecond(other) {
|
|
2914
2920
|
return this.diffInSeconds(other) < 0;
|
|
@@ -2917,7 +2923,7 @@
|
|
|
2917
2923
|
/**
|
|
2918
2924
|
* Checks whether this DateTime is before another date (comparing by week).
|
|
2919
2925
|
* @param {DateTime} other The date to compare to.
|
|
2920
|
-
* @
|
|
2926
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by week).
|
|
2921
2927
|
*/
|
|
2922
2928
|
isBeforeWeek(other) {
|
|
2923
2929
|
return this.diffInWeeks(other) < 0;
|
|
@@ -2926,7 +2932,7 @@
|
|
|
2926
2932
|
/**
|
|
2927
2933
|
* Checks whether this DateTime is before another date (comparing by year).
|
|
2928
2934
|
* @param {DateTime} other The date to compare to.
|
|
2929
|
-
* @
|
|
2935
|
+
* @returns {boolean} Whether this DateTime is before the other date (comparing by year).
|
|
2930
2936
|
*/
|
|
2931
2937
|
isBeforeYear(other) {
|
|
2932
2938
|
return this.diffInYears(other) < 0;
|
|
@@ -2936,7 +2942,7 @@
|
|
|
2936
2942
|
* Checks whether this DateTime is between two other dates.
|
|
2937
2943
|
* @param {DateTime} start The first date to compare to.
|
|
2938
2944
|
* @param {DateTime} end The second date to compare to.
|
|
2939
|
-
* @
|
|
2945
|
+
* @returns {boolean} Whether this DateTime is between two other dates.
|
|
2940
2946
|
*/
|
|
2941
2947
|
isBetween(start, end) {
|
|
2942
2948
|
return this.isAfter(start) && this.isBefore(end);
|
|
@@ -2946,7 +2952,7 @@
|
|
|
2946
2952
|
* Checks whether this DateTime is between two other dates (comparing by day).
|
|
2947
2953
|
* @param {DateTime} start The first date to compare to.
|
|
2948
2954
|
* @param {DateTime} end The second date to compare to.
|
|
2949
|
-
* @
|
|
2955
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by day).
|
|
2950
2956
|
*/
|
|
2951
2957
|
isBetweenDay(start, end) {
|
|
2952
2958
|
return this.isAfterDay(start) && this.isBeforeDay(end);
|
|
@@ -2956,7 +2962,7 @@
|
|
|
2956
2962
|
* Checks whether this DateTime is between two other dates (comparing by hour).
|
|
2957
2963
|
* @param {DateTime} start The first date to compare to.
|
|
2958
2964
|
* @param {DateTime} end The second date to compare to.
|
|
2959
|
-
* @
|
|
2965
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by hour).
|
|
2960
2966
|
*/
|
|
2961
2967
|
isBetweenHour(start, end) {
|
|
2962
2968
|
return this.isAfterHour(start) && this.isBeforeHour(end);
|
|
@@ -2966,7 +2972,7 @@
|
|
|
2966
2972
|
* Checks whether this DateTime is between two other dates (comparing by minute).
|
|
2967
2973
|
* @param {DateTime} start The first date to compare to.
|
|
2968
2974
|
* @param {DateTime} end The second date to compare to.
|
|
2969
|
-
* @
|
|
2975
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by minute).
|
|
2970
2976
|
*/
|
|
2971
2977
|
isBetweenMinute(start, end) {
|
|
2972
2978
|
return this.isAfterMinute(start) && this.isBeforeMinute(end);
|
|
@@ -2976,7 +2982,7 @@
|
|
|
2976
2982
|
* Checks whether this DateTime is between two other dates (comparing by month).
|
|
2977
2983
|
* @param {DateTime} start The first date to compare to.
|
|
2978
2984
|
* @param {DateTime} end The second date to compare to.
|
|
2979
|
-
* @
|
|
2985
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by month).
|
|
2980
2986
|
*/
|
|
2981
2987
|
isBetweenMonth(start, end) {
|
|
2982
2988
|
return this.isAfterMonth(start) && this.isBeforeMonth(end);
|
|
@@ -2986,7 +2992,7 @@
|
|
|
2986
2992
|
* Checks whether this DateTime is between two other dates (comparing by second).
|
|
2987
2993
|
* @param {DateTime} start The first date to compare to.
|
|
2988
2994
|
* @param {DateTime} end The second date to compare to.
|
|
2989
|
-
* @
|
|
2995
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by second).
|
|
2990
2996
|
*/
|
|
2991
2997
|
isBetweenSecond(start, end) {
|
|
2992
2998
|
return this.isAfterSecond(start) && this.isBeforeSecond(end);
|
|
@@ -2996,7 +3002,7 @@
|
|
|
2996
3002
|
* Checks whether this DateTime is between two other dates (comparing by week).
|
|
2997
3003
|
* @param {DateTime} start The first date to compare to.
|
|
2998
3004
|
* @param {DateTime} end The second date to compare to.
|
|
2999
|
-
* @
|
|
3005
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by week).
|
|
3000
3006
|
*/
|
|
3001
3007
|
isBetweenWeek(start, end) {
|
|
3002
3008
|
return this.isAfterWeek(start) && this.isBeforeWeek(end);
|
|
@@ -3006,7 +3012,7 @@
|
|
|
3006
3012
|
* Checks whether this DateTime is between two other dates (comparing by year).
|
|
3007
3013
|
* @param {DateTime} start The first date to compare to.
|
|
3008
3014
|
* @param {DateTime} end The second date to compare to.
|
|
3009
|
-
* @
|
|
3015
|
+
* @returns {boolean} Whether this DateTime is between two other dates (comparing by year).
|
|
3010
3016
|
*/
|
|
3011
3017
|
isBetweenYear(start, end) {
|
|
3012
3018
|
return this.isAfterYear(start) && this.isBeforeYear(end);
|
|
@@ -3014,10 +3020,10 @@
|
|
|
3014
3020
|
|
|
3015
3021
|
/**
|
|
3016
3022
|
* Checks whether the DateTime is in daylight saving time.
|
|
3017
|
-
* @
|
|
3023
|
+
* @returns {boolean} Whether the current time is in daylight saving time.
|
|
3018
3024
|
*/
|
|
3019
3025
|
isDst() {
|
|
3020
|
-
if (!this
|
|
3026
|
+
if (!this.#dynamicTz) {
|
|
3021
3027
|
return false;
|
|
3022
3028
|
}
|
|
3023
3029
|
|
|
@@ -3034,7 +3040,7 @@
|
|
|
3034
3040
|
|
|
3035
3041
|
/**
|
|
3036
3042
|
* Checks whether the year is a leap year.
|
|
3037
|
-
* @
|
|
3043
|
+
* @returns {boolean} Whether the current year is a leap year.
|
|
3038
3044
|
*/
|
|
3039
3045
|
isLeapYear() {
|
|
3040
3046
|
return this.constructor.isLeapYear(
|
|
@@ -3045,7 +3051,7 @@
|
|
|
3045
3051
|
/**
|
|
3046
3052
|
* Checks whether this DateTime is the same as another date.
|
|
3047
3053
|
* @param {DateTime} other The date to compare to.
|
|
3048
|
-
* @
|
|
3054
|
+
* @returns {boolean} Whether this DateTime is the same as the other date.
|
|
3049
3055
|
*/
|
|
3050
3056
|
isSame(other) {
|
|
3051
3057
|
return this.diff(other) === 0;
|
|
@@ -3054,7 +3060,7 @@
|
|
|
3054
3060
|
/**
|
|
3055
3061
|
* Checks whether this DateTime is the same as another date (comparing by day).
|
|
3056
3062
|
* @param {DateTime} other The date to compare to.
|
|
3057
|
-
* @
|
|
3063
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by day).
|
|
3058
3064
|
*/
|
|
3059
3065
|
isSameDay(other) {
|
|
3060
3066
|
return this.diffInDays(other) === 0;
|
|
@@ -3063,7 +3069,7 @@
|
|
|
3063
3069
|
/**
|
|
3064
3070
|
* Checks whether this DateTime is the same as another date (comparing by hour).
|
|
3065
3071
|
* @param {DateTime} other The date to compare to.
|
|
3066
|
-
* @
|
|
3072
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by hour).
|
|
3067
3073
|
*/
|
|
3068
3074
|
isSameHour(other) {
|
|
3069
3075
|
return this.diffInHours(other) === 0;
|
|
@@ -3072,7 +3078,7 @@
|
|
|
3072
3078
|
/**
|
|
3073
3079
|
* Checks whether this DateTime is the same as another date (comparing by minute).
|
|
3074
3080
|
* @param {DateTime} other The date to compare to.
|
|
3075
|
-
* @
|
|
3081
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by minute).
|
|
3076
3082
|
*/
|
|
3077
3083
|
isSameMinute(other) {
|
|
3078
3084
|
return this.diffInMinutes(other) === 0;
|
|
@@ -3081,7 +3087,7 @@
|
|
|
3081
3087
|
/**
|
|
3082
3088
|
* Checks whether this DateTime is the same as another date (comparing by month).
|
|
3083
3089
|
* @param {DateTime} other The date to compare to.
|
|
3084
|
-
* @
|
|
3090
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by month).
|
|
3085
3091
|
*/
|
|
3086
3092
|
isSameMonth(other) {
|
|
3087
3093
|
return this.diffInMonths(other) === 0;
|
|
@@ -3090,7 +3096,7 @@
|
|
|
3090
3096
|
/**
|
|
3091
3097
|
* Checks whether this DateTime is the same as or after another date.
|
|
3092
3098
|
* @param {DateTime} other The date to compare to.
|
|
3093
|
-
* @
|
|
3099
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date.
|
|
3094
3100
|
*/
|
|
3095
3101
|
isSameOrAfter(other) {
|
|
3096
3102
|
return this.diff(other) >= 0;
|
|
@@ -3099,7 +3105,7 @@
|
|
|
3099
3105
|
/**
|
|
3100
3106
|
* Checks whether this DateTime is the same as or after another date (comparing by day).
|
|
3101
3107
|
* @param {DateTime} other The date to compare to.
|
|
3102
|
-
* @
|
|
3108
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by day).
|
|
3103
3109
|
*/
|
|
3104
3110
|
isSameOrAfterDay(other) {
|
|
3105
3111
|
return this.diffInDays(other) >= 0;
|
|
@@ -3108,7 +3114,7 @@
|
|
|
3108
3114
|
/**
|
|
3109
3115
|
* Checks whether this DateTime is the same as or after another date (comparing by hour).
|
|
3110
3116
|
* @param {DateTime} other The date to compare to.
|
|
3111
|
-
* @
|
|
3117
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by hour).
|
|
3112
3118
|
*/
|
|
3113
3119
|
isSameOrAfterHour(other) {
|
|
3114
3120
|
return this.diffInHours(other) >= 0;
|
|
@@ -3117,7 +3123,7 @@
|
|
|
3117
3123
|
/**
|
|
3118
3124
|
* Checks whether this DateTime is the same as or after another date (comparing by minute).
|
|
3119
3125
|
* @param {DateTime} other The date to compare to.
|
|
3120
|
-
* @
|
|
3126
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by minute).
|
|
3121
3127
|
*/
|
|
3122
3128
|
isSameOrAfterMinute(other) {
|
|
3123
3129
|
return this.diffInMinutes(other) >= 0;
|
|
@@ -3126,7 +3132,7 @@
|
|
|
3126
3132
|
/**
|
|
3127
3133
|
* Checks whether this DateTime is the same as or after another date (comparing by month).
|
|
3128
3134
|
* @param {DateTime} other The date to compare to.
|
|
3129
|
-
* @
|
|
3135
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by month).
|
|
3130
3136
|
*/
|
|
3131
3137
|
isSameOrAfterMonth(other) {
|
|
3132
3138
|
return this.diffInMonths(other) >= 0;
|
|
@@ -3135,7 +3141,7 @@
|
|
|
3135
3141
|
/**
|
|
3136
3142
|
* Checks whether this DateTime is the same as or after another date (comparing by second).
|
|
3137
3143
|
* @param {DateTime} other The date to compare to.
|
|
3138
|
-
* @
|
|
3144
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by second).
|
|
3139
3145
|
*/
|
|
3140
3146
|
isSameOrAfterSecond(other) {
|
|
3141
3147
|
return this.diffInSeconds(other) >= 0;
|
|
@@ -3144,7 +3150,7 @@
|
|
|
3144
3150
|
/**
|
|
3145
3151
|
* Checks whether this DateTime is the same as or after another date (comparing by week).
|
|
3146
3152
|
* @param {DateTime} other The date to compare to.
|
|
3147
|
-
* @
|
|
3153
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by week).
|
|
3148
3154
|
*/
|
|
3149
3155
|
isSameOrAfterWeek(other) {
|
|
3150
3156
|
return this.diffInWeeks(other) >= 0;
|
|
@@ -3153,7 +3159,7 @@
|
|
|
3153
3159
|
/**
|
|
3154
3160
|
* Checks whether this DateTime is the same as or after another date (comparing by year).
|
|
3155
3161
|
* @param {DateTime} other The date to compare to.
|
|
3156
|
-
* @
|
|
3162
|
+
* @returns {boolean} Whether this DateTime is the same as or after the other date (comparing by year).
|
|
3157
3163
|
*/
|
|
3158
3164
|
isSameOrAfterYear(other) {
|
|
3159
3165
|
return this.diffInYears(other) >= 0;
|
|
@@ -3162,7 +3168,7 @@
|
|
|
3162
3168
|
/**
|
|
3163
3169
|
* Checks whether this DateTime is the same as or before another date.
|
|
3164
3170
|
* @param {DateTime} other The date to compare to.
|
|
3165
|
-
* @
|
|
3171
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date.
|
|
3166
3172
|
*/
|
|
3167
3173
|
isSameOrBefore(other) {
|
|
3168
3174
|
return this.diff(other) <= 0;
|
|
@@ -3171,7 +3177,7 @@
|
|
|
3171
3177
|
/**
|
|
3172
3178
|
* Checks whether this DateTime is the same as or before another date (comparing by day).
|
|
3173
3179
|
* @param {DateTime} other The date to compare to.
|
|
3174
|
-
* @
|
|
3180
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by day).
|
|
3175
3181
|
*/
|
|
3176
3182
|
isSameOrBeforeDay(other) {
|
|
3177
3183
|
return this.diffInDays(other) <= 0;
|
|
@@ -3180,7 +3186,7 @@
|
|
|
3180
3186
|
/**
|
|
3181
3187
|
* Checks whether this DateTime is the same as or before another date (comparing by hour).
|
|
3182
3188
|
* @param {DateTime} other The date to compare to.
|
|
3183
|
-
* @
|
|
3189
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by hour).
|
|
3184
3190
|
*/
|
|
3185
3191
|
isSameOrBeforeHour(other) {
|
|
3186
3192
|
return this.diffInHours(other) <= 0;
|
|
@@ -3189,7 +3195,7 @@
|
|
|
3189
3195
|
/**
|
|
3190
3196
|
* Checks whether this DateTime is the same as or before another date (comparing by minute).
|
|
3191
3197
|
* @param {DateTime} other The date to compare to.
|
|
3192
|
-
* @
|
|
3198
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by minute).
|
|
3193
3199
|
*/
|
|
3194
3200
|
isSameOrBeforeMinute(other) {
|
|
3195
3201
|
return this.diffInMinutes(other) <= 0;
|
|
@@ -3198,7 +3204,7 @@
|
|
|
3198
3204
|
/**
|
|
3199
3205
|
* Checks whether this DateTime is the same as or before another date (comparing by month).
|
|
3200
3206
|
* @param {DateTime} other The date to compare to.
|
|
3201
|
-
* @
|
|
3207
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by month).
|
|
3202
3208
|
*/
|
|
3203
3209
|
isSameOrBeforeMonth(other) {
|
|
3204
3210
|
return this.diffInMonths(other) <= 0;
|
|
@@ -3207,7 +3213,7 @@
|
|
|
3207
3213
|
/**
|
|
3208
3214
|
* Checks whether this DateTime is the same as or before another date (comparing by second).
|
|
3209
3215
|
* @param {DateTime} other The date to compare to.
|
|
3210
|
-
* @
|
|
3216
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by second).
|
|
3211
3217
|
*/
|
|
3212
3218
|
isSameOrBeforeSecond(other) {
|
|
3213
3219
|
return this.diffInSeconds(other) <= 0;
|
|
@@ -3216,7 +3222,7 @@
|
|
|
3216
3222
|
/**
|
|
3217
3223
|
* Checks whether this DateTime is the same as or before another date (comparing by week).
|
|
3218
3224
|
* @param {DateTime} other The date to compare to.
|
|
3219
|
-
* @
|
|
3225
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by week).
|
|
3220
3226
|
*/
|
|
3221
3227
|
isSameOrBeforeWeek(other) {
|
|
3222
3228
|
return this.diffInWeeks(other) <= 0;
|
|
@@ -3225,7 +3231,7 @@
|
|
|
3225
3231
|
/**
|
|
3226
3232
|
* Checks whether this DateTime is the same as or before another date (comparing by year).
|
|
3227
3233
|
* @param {DateTime} other The date to compare to.
|
|
3228
|
-
* @
|
|
3234
|
+
* @returns {boolean} Whether this DateTime is the same as or before the other date (comparing by year).
|
|
3229
3235
|
*/
|
|
3230
3236
|
isSameOrBeforeYear(other) {
|
|
3231
3237
|
return this.diffInYears(other) <= 0;
|
|
@@ -3234,7 +3240,7 @@
|
|
|
3234
3240
|
/**
|
|
3235
3241
|
* Checks whether this DateTime is the same as another date (comparing by second).
|
|
3236
3242
|
* @param {DateTime} other The date to compare to.
|
|
3237
|
-
* @
|
|
3243
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by second).
|
|
3238
3244
|
*/
|
|
3239
3245
|
isSameSecond(other) {
|
|
3240
3246
|
return this.diffInSeconds(other) === 0;
|
|
@@ -3243,7 +3249,7 @@
|
|
|
3243
3249
|
/**
|
|
3244
3250
|
* Checks whether this DateTime is the same as another date (comparing by week).
|
|
3245
3251
|
* @param {DateTime} other The date to compare to.
|
|
3246
|
-
* @
|
|
3252
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by week).
|
|
3247
3253
|
*/
|
|
3248
3254
|
isSameWeek(other) {
|
|
3249
3255
|
return this.diffInWeeks(other) === 0;
|
|
@@ -3252,7 +3258,7 @@
|
|
|
3252
3258
|
/**
|
|
3253
3259
|
* Checks whether this DateTime is the same as another date (comparing by year).
|
|
3254
3260
|
* @param {DateTime} other The date to compare to.
|
|
3255
|
-
* @
|
|
3261
|
+
* @returns {boolean} Whether this DateTime is the same as the other date (comparing by year).
|
|
3256
3262
|
*/
|
|
3257
3263
|
isSameYear(other) {
|
|
3258
3264
|
return this.diffInYears(other) === 0;
|
|
@@ -3261,7 +3267,7 @@
|
|
|
3261
3267
|
/**
|
|
3262
3268
|
* Gets the localized month name for the current date.
|
|
3263
3269
|
* @param {'long'|'short'|'narrow'} [type='long'] The type of month name to return.
|
|
3264
|
-
* @
|
|
3270
|
+
* @returns {string} The localized month name.
|
|
3265
3271
|
*/
|
|
3266
3272
|
monthName(type = 'long') {
|
|
3267
3273
|
return formatMonth(this.getLocale(), this.getMonth(), type);
|
|
@@ -3269,7 +3275,7 @@
|
|
|
3269
3275
|
|
|
3270
3276
|
/**
|
|
3271
3277
|
* Sets the DateTime to the start of the day.
|
|
3272
|
-
* @
|
|
3278
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3273
3279
|
*/
|
|
3274
3280
|
startOfDay() {
|
|
3275
3281
|
return this.withHours(0, 0, 0, 0);
|
|
@@ -3277,7 +3283,7 @@
|
|
|
3277
3283
|
|
|
3278
3284
|
/**
|
|
3279
3285
|
* Sets the DateTime to the start of the hour.
|
|
3280
|
-
* @
|
|
3286
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3281
3287
|
*/
|
|
3282
3288
|
startOfHour() {
|
|
3283
3289
|
return this.withMinutes(0, 0, 0);
|
|
@@ -3285,7 +3291,7 @@
|
|
|
3285
3291
|
|
|
3286
3292
|
/**
|
|
3287
3293
|
* Sets the DateTime to the start of the minute.
|
|
3288
|
-
* @
|
|
3294
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3289
3295
|
*/
|
|
3290
3296
|
startOfMinute() {
|
|
3291
3297
|
return this.withSeconds(0, 0);
|
|
@@ -3293,7 +3299,7 @@
|
|
|
3293
3299
|
|
|
3294
3300
|
/**
|
|
3295
3301
|
* Sets the DateTime to the start of the month.
|
|
3296
|
-
* @
|
|
3302
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3297
3303
|
*/
|
|
3298
3304
|
startOfMonth() {
|
|
3299
3305
|
return this.withDate(1)
|
|
@@ -3302,7 +3308,7 @@
|
|
|
3302
3308
|
|
|
3303
3309
|
/**
|
|
3304
3310
|
* Sets the DateTime to the start of the quarter.
|
|
3305
|
-
* @
|
|
3311
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3306
3312
|
*/
|
|
3307
3313
|
startOfQuarter() {
|
|
3308
3314
|
const month = this.getQuarter() * 3 - 2;
|
|
@@ -3312,7 +3318,7 @@
|
|
|
3312
3318
|
|
|
3313
3319
|
/**
|
|
3314
3320
|
* Sets the DateTime to the start of the second.
|
|
3315
|
-
* @
|
|
3321
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3316
3322
|
*/
|
|
3317
3323
|
startOfSecond() {
|
|
3318
3324
|
return this.withMilliseconds(0);
|
|
@@ -3320,7 +3326,7 @@
|
|
|
3320
3326
|
|
|
3321
3327
|
/**
|
|
3322
3328
|
* Sets the DateTime to the start of the week.
|
|
3323
|
-
* @
|
|
3329
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3324
3330
|
*/
|
|
3325
3331
|
startOfWeek() {
|
|
3326
3332
|
return this.withWeekDay(1)
|
|
@@ -3329,7 +3335,7 @@
|
|
|
3329
3335
|
|
|
3330
3336
|
/**
|
|
3331
3337
|
* Sets the DateTime to the start of the year.
|
|
3332
|
-
* @
|
|
3338
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3333
3339
|
*/
|
|
3334
3340
|
startOfYear() {
|
|
3335
3341
|
return this.withMonth(1, 1)
|
|
@@ -3338,7 +3344,7 @@
|
|
|
3338
3344
|
|
|
3339
3345
|
/**
|
|
3340
3346
|
* Subtracts a day from the current DateTime.
|
|
3341
|
-
* @
|
|
3347
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3342
3348
|
*/
|
|
3343
3349
|
subDay() {
|
|
3344
3350
|
return this.addDays(-1);
|
|
@@ -3347,7 +3353,7 @@
|
|
|
3347
3353
|
/**
|
|
3348
3354
|
* Subtracts days from the current DateTime.
|
|
3349
3355
|
* @param {number} amount The number of days to subtract.
|
|
3350
|
-
* @
|
|
3356
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3351
3357
|
*/
|
|
3352
3358
|
subDays(amount) {
|
|
3353
3359
|
return this.addDays(-amount);
|
|
@@ -3355,7 +3361,7 @@
|
|
|
3355
3361
|
|
|
3356
3362
|
/**
|
|
3357
3363
|
* Subtracts an hour from the current DateTime.
|
|
3358
|
-
* @
|
|
3364
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3359
3365
|
*/
|
|
3360
3366
|
subHour() {
|
|
3361
3367
|
return this.addHours(-1);
|
|
@@ -3364,7 +3370,7 @@
|
|
|
3364
3370
|
/**
|
|
3365
3371
|
* Subtracts hours from the current DateTime.
|
|
3366
3372
|
* @param {number} amount The number of hours to subtract.
|
|
3367
|
-
* @
|
|
3373
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3368
3374
|
*/
|
|
3369
3375
|
subHours(amount) {
|
|
3370
3376
|
return this.addHours(-amount);
|
|
@@ -3372,7 +3378,7 @@
|
|
|
3372
3378
|
|
|
3373
3379
|
/**
|
|
3374
3380
|
* Subtracts a minute from the current DateTime.
|
|
3375
|
-
* @
|
|
3381
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3376
3382
|
*/
|
|
3377
3383
|
subMinute() {
|
|
3378
3384
|
return this.addMinutes(-1);
|
|
@@ -3381,7 +3387,7 @@
|
|
|
3381
3387
|
/**
|
|
3382
3388
|
* Subtracts minutes from the current DateTime.
|
|
3383
3389
|
* @param {number} amount The number of minutes to subtract.
|
|
3384
|
-
* @
|
|
3390
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3385
3391
|
*/
|
|
3386
3392
|
subMinutes(amount) {
|
|
3387
3393
|
return this.addMinutes(-amount);
|
|
@@ -3389,7 +3395,7 @@
|
|
|
3389
3395
|
|
|
3390
3396
|
/**
|
|
3391
3397
|
* Subtracts a month from the current DateTime.
|
|
3392
|
-
* @
|
|
3398
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3393
3399
|
*/
|
|
3394
3400
|
subMonth() {
|
|
3395
3401
|
return this.addMonths(-1);
|
|
@@ -3398,7 +3404,7 @@
|
|
|
3398
3404
|
/**
|
|
3399
3405
|
* Subtracts months from the current DateTime.
|
|
3400
3406
|
* @param {number} amount The number of months to subtract.
|
|
3401
|
-
* @
|
|
3407
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3402
3408
|
*/
|
|
3403
3409
|
subMonths(amount) {
|
|
3404
3410
|
return this.addMonths(-amount);
|
|
@@ -3406,7 +3412,7 @@
|
|
|
3406
3412
|
|
|
3407
3413
|
/**
|
|
3408
3414
|
* Subtracts a second from the current DateTime.
|
|
3409
|
-
* @
|
|
3415
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3410
3416
|
*/
|
|
3411
3417
|
subSecond() {
|
|
3412
3418
|
return this.addSeconds(-1);
|
|
@@ -3415,7 +3421,7 @@
|
|
|
3415
3421
|
/**
|
|
3416
3422
|
* Subtracts seconds from the current DateTime.
|
|
3417
3423
|
* @param {number} amount The number of seconds to subtract.
|
|
3418
|
-
* @
|
|
3424
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3419
3425
|
*/
|
|
3420
3426
|
subSeconds(amount) {
|
|
3421
3427
|
return this.addSeconds(-amount);
|
|
@@ -3423,7 +3429,7 @@
|
|
|
3423
3429
|
|
|
3424
3430
|
/**
|
|
3425
3431
|
* Subtracts a week from the current DateTime.
|
|
3426
|
-
* @
|
|
3432
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3427
3433
|
*/
|
|
3428
3434
|
subWeek() {
|
|
3429
3435
|
return this.addWeeks(-1);
|
|
@@ -3432,7 +3438,7 @@
|
|
|
3432
3438
|
/**
|
|
3433
3439
|
* Subtracts weeks from the current DateTime.
|
|
3434
3440
|
* @param {number} amount The number of weeks to subtract.
|
|
3435
|
-
* @
|
|
3441
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3436
3442
|
*/
|
|
3437
3443
|
subWeeks(amount) {
|
|
3438
3444
|
return this.addWeeks(-amount);
|
|
@@ -3440,7 +3446,7 @@
|
|
|
3440
3446
|
|
|
3441
3447
|
/**
|
|
3442
3448
|
* Subtracts a year from the current DateTime.
|
|
3443
|
-
* @
|
|
3449
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3444
3450
|
*/
|
|
3445
3451
|
subYear() {
|
|
3446
3452
|
return this.addYears(-1);
|
|
@@ -3449,7 +3455,7 @@
|
|
|
3449
3455
|
/**
|
|
3450
3456
|
* Subtracts years from the current DateTime.
|
|
3451
3457
|
* @param {number} amount The number of years to subtract.
|
|
3452
|
-
* @
|
|
3458
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3453
3459
|
*/
|
|
3454
3460
|
subYears(amount) {
|
|
3455
3461
|
return this.addYears(-amount);
|
|
@@ -3458,7 +3464,7 @@
|
|
|
3458
3464
|
/**
|
|
3459
3465
|
* Returns the primitive representation of the DateTime.
|
|
3460
3466
|
* @param {'default'|'number'|'string'} hint The conversion hint.
|
|
3461
|
-
* @
|
|
3467
|
+
* @returns {string|number} A string for default/string coercion or epoch milliseconds for numeric coercion.
|
|
3462
3468
|
*/
|
|
3463
3469
|
[Symbol.toPrimitive](hint) {
|
|
3464
3470
|
return hint === 'number' ?
|
|
@@ -3469,17 +3475,17 @@
|
|
|
3469
3475
|
/**
|
|
3470
3476
|
* Gets the name of the current time zone.
|
|
3471
3477
|
* @param {'long'|'short'} [type='long'] The formatting type.
|
|
3472
|
-
* @
|
|
3478
|
+
* @returns {string} The name of the time zone.
|
|
3473
3479
|
*/
|
|
3474
3480
|
timeZoneName(type = 'long') {
|
|
3475
|
-
return this
|
|
3481
|
+
return this.#dynamicTz ?
|
|
3476
3482
|
formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
|
|
3477
3483
|
'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
|
|
3478
3484
|
}
|
|
3479
3485
|
|
|
3480
3486
|
/**
|
|
3481
3487
|
* Formats the current date using "eee MMM dd yyyy".
|
|
3482
|
-
* @
|
|
3488
|
+
* @returns {string} The formatted date string.
|
|
3483
3489
|
*/
|
|
3484
3490
|
toDateString() {
|
|
3485
3491
|
return this.format(formats.date);
|
|
@@ -3487,7 +3493,7 @@
|
|
|
3487
3493
|
|
|
3488
3494
|
/**
|
|
3489
3495
|
* Formats the current date using "yyyy-MM-dd'T'HH:mm:ss.SSSxxx".
|
|
3490
|
-
* @
|
|
3496
|
+
* @returns {string} The formatted date string.
|
|
3491
3497
|
*/
|
|
3492
3498
|
toIsoString() {
|
|
3493
3499
|
return this
|
|
@@ -3498,7 +3504,7 @@
|
|
|
3498
3504
|
|
|
3499
3505
|
/**
|
|
3500
3506
|
* Returns the JSON representation of the current date.
|
|
3501
|
-
* @
|
|
3507
|
+
* @returns {string|null} The ISO string for valid dates or null for invalid dates.
|
|
3502
3508
|
*/
|
|
3503
3509
|
toJSON() {
|
|
3504
3510
|
return this.isValid ?
|
|
@@ -3508,7 +3514,7 @@
|
|
|
3508
3514
|
|
|
3509
3515
|
/**
|
|
3510
3516
|
* Formats the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
3511
|
-
* @
|
|
3517
|
+
* @returns {string} The formatted date string.
|
|
3512
3518
|
*/
|
|
3513
3519
|
toString() {
|
|
3514
3520
|
return this.format(formats.string);
|
|
@@ -3516,7 +3522,7 @@
|
|
|
3516
3522
|
|
|
3517
3523
|
/**
|
|
3518
3524
|
* Formats the current date using "HH:mm:ss xx (VV)".
|
|
3519
|
-
* @
|
|
3525
|
+
* @returns {string} The formatted date string.
|
|
3520
3526
|
*/
|
|
3521
3527
|
toTimeString() {
|
|
3522
3528
|
return this.format(formats.time);
|
|
@@ -3524,7 +3530,7 @@
|
|
|
3524
3530
|
|
|
3525
3531
|
/**
|
|
3526
3532
|
* Formats the current date in the UTC time zone using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
3527
|
-
* @
|
|
3533
|
+
* @returns {string} The formatted date string.
|
|
3528
3534
|
*/
|
|
3529
3535
|
toUTCString() {
|
|
3530
3536
|
return this
|
|
@@ -3535,7 +3541,7 @@
|
|
|
3535
3541
|
|
|
3536
3542
|
/**
|
|
3537
3543
|
* Returns the number of milliseconds since the UNIX epoch.
|
|
3538
|
-
* @
|
|
3544
|
+
* @returns {number} The number of milliseconds since the UNIX epoch.
|
|
3539
3545
|
*/
|
|
3540
3546
|
valueOf() {
|
|
3541
3547
|
return this.getTime();
|
|
@@ -3543,7 +3549,7 @@
|
|
|
3543
3549
|
|
|
3544
3550
|
/**
|
|
3545
3551
|
* Gets the number of weeks in the current year.
|
|
3546
|
-
* @
|
|
3552
|
+
* @returns {number} The number of weeks in the current year.
|
|
3547
3553
|
*/
|
|
3548
3554
|
weeksInYear() {
|
|
3549
3555
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -3553,7 +3559,7 @@
|
|
|
3553
3559
|
/**
|
|
3554
3560
|
* Returns a copy with the date of the month changed in the current time zone.
|
|
3555
3561
|
* @param {number} date The date of the month.
|
|
3556
|
-
* @
|
|
3562
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3557
3563
|
*/
|
|
3558
3564
|
withDate(date) {
|
|
3559
3565
|
return setOffsetTime(
|
|
@@ -3565,7 +3571,7 @@
|
|
|
3565
3571
|
/**
|
|
3566
3572
|
* Returns a copy with the day of the week changed in the current time zone.
|
|
3567
3573
|
* @param {number} day The day of the week. (0 = Sunday, 6 = Saturday)
|
|
3568
|
-
* @
|
|
3574
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3569
3575
|
*/
|
|
3570
3576
|
withDay(day) {
|
|
3571
3577
|
return setOffsetTime(
|
|
@@ -3581,7 +3587,7 @@
|
|
|
3581
3587
|
/**
|
|
3582
3588
|
* Returns a copy with the day of the year changed in the current time zone.
|
|
3583
3589
|
* @param {number} day The day of the year. (1-366)
|
|
3584
|
-
* @
|
|
3590
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3585
3591
|
*/
|
|
3586
3592
|
withDayOfYear(day) {
|
|
3587
3593
|
return setOffsetTime(
|
|
@@ -3599,7 +3605,7 @@
|
|
|
3599
3605
|
* @param {number} [minutes] The minutes. (0-59)
|
|
3600
3606
|
* @param {number} [seconds] The seconds. (0-59)
|
|
3601
3607
|
* @param {number} [milliseconds] The milliseconds.
|
|
3602
|
-
* @
|
|
3608
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3603
3609
|
*/
|
|
3604
3610
|
withHours(...args) {
|
|
3605
3611
|
return setOffsetTime(
|
|
@@ -3611,19 +3617,19 @@
|
|
|
3611
3617
|
/**
|
|
3612
3618
|
* Returns a copy with a different locale.
|
|
3613
3619
|
* @param {string} locale The locale to use.
|
|
3614
|
-
* @
|
|
3620
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3615
3621
|
*/
|
|
3616
3622
|
withLocale(locale) {
|
|
3617
3623
|
return new this.constructor(this.getTime(), {
|
|
3618
3624
|
locale,
|
|
3619
|
-
timeZone: this
|
|
3625
|
+
timeZone: this.#timeZone,
|
|
3620
3626
|
});
|
|
3621
3627
|
}
|
|
3622
3628
|
|
|
3623
3629
|
/**
|
|
3624
3630
|
* Returns a copy with the milliseconds changed in the current time zone.
|
|
3625
3631
|
* @param {number} milliseconds The milliseconds.
|
|
3626
|
-
* @
|
|
3632
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3627
3633
|
*/
|
|
3628
3634
|
withMilliseconds(milliseconds) {
|
|
3629
3635
|
return setOffsetTime(
|
|
@@ -3637,7 +3643,7 @@
|
|
|
3637
3643
|
* @param {number} minutes The minutes. (0-59)
|
|
3638
3644
|
* @param {number} [seconds] The seconds. (0-59)
|
|
3639
3645
|
* @param {number} [milliseconds] The milliseconds.
|
|
3640
|
-
* @
|
|
3646
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3641
3647
|
*/
|
|
3642
3648
|
withMinutes(...args) {
|
|
3643
3649
|
return setOffsetTime(
|
|
@@ -3650,7 +3656,7 @@
|
|
|
3650
3656
|
* Returns a copy with the month changed in the current time zone.
|
|
3651
3657
|
* @param {number} month The month. (1-12)
|
|
3652
3658
|
* @param {number|null} [date] The date of the month.
|
|
3653
|
-
* @
|
|
3659
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3654
3660
|
*/
|
|
3655
3661
|
withMonth(month, date = null) {
|
|
3656
3662
|
if (date === null) {
|
|
@@ -3679,7 +3685,7 @@
|
|
|
3679
3685
|
/**
|
|
3680
3686
|
* Returns a copy with the quarter of the year changed in the current time zone.
|
|
3681
3687
|
* @param {number} quarter The quarter of the year. (1-4)
|
|
3682
|
-
* @
|
|
3688
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3683
3689
|
*/
|
|
3684
3690
|
withQuarter(quarter) {
|
|
3685
3691
|
return setOffsetTime(
|
|
@@ -3695,7 +3701,7 @@
|
|
|
3695
3701
|
* Returns a copy with the seconds changed in the current time zone.
|
|
3696
3702
|
* @param {number} seconds The seconds. (0-59)
|
|
3697
3703
|
* @param {number} [milliseconds] The milliseconds.
|
|
3698
|
-
* @
|
|
3704
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3699
3705
|
*/
|
|
3700
3706
|
withSeconds(...args) {
|
|
3701
3707
|
return setOffsetTime(
|
|
@@ -3707,19 +3713,19 @@
|
|
|
3707
3713
|
/**
|
|
3708
3714
|
* Returns a copy with a different epoch-millisecond value.
|
|
3709
3715
|
* @param {number} time The number of milliseconds since the UNIX epoch.
|
|
3710
|
-
* @
|
|
3716
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3711
3717
|
*/
|
|
3712
3718
|
withTime(time) {
|
|
3713
3719
|
return new this.constructor(time, {
|
|
3714
|
-
locale: this
|
|
3715
|
-
timeZone: this
|
|
3720
|
+
locale: this.#locale,
|
|
3721
|
+
timeZone: this.#timeZone,
|
|
3716
3722
|
});
|
|
3717
3723
|
}
|
|
3718
3724
|
|
|
3719
3725
|
/**
|
|
3720
3726
|
* Returns a copy with a different number of seconds since the UNIX epoch.
|
|
3721
3727
|
* @param {number} timestamp The number of seconds since the UNIX epoch.
|
|
3722
|
-
* @
|
|
3728
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3723
3729
|
*/
|
|
3724
3730
|
withTimestamp(timestamp) {
|
|
3725
3731
|
return this.withTime(timestamp * 1000);
|
|
@@ -3728,11 +3734,11 @@
|
|
|
3728
3734
|
/**
|
|
3729
3735
|
* Returns a copy in a different time zone.
|
|
3730
3736
|
* @param {string} timeZone The time zone to use.
|
|
3731
|
-
* @
|
|
3737
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3732
3738
|
*/
|
|
3733
3739
|
withTimeZone(timeZone) {
|
|
3734
3740
|
return new this.constructor(this.getTime(), {
|
|
3735
|
-
locale: this
|
|
3741
|
+
locale: this.#locale,
|
|
3736
3742
|
timeZone,
|
|
3737
3743
|
});
|
|
3738
3744
|
}
|
|
@@ -3740,11 +3746,11 @@
|
|
|
3740
3746
|
/**
|
|
3741
3747
|
* Returns a copy with a fixed numeric UTC offset.
|
|
3742
3748
|
* @param {number} offset The UTC offset in minutes.
|
|
3743
|
-
* @
|
|
3749
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3744
3750
|
*/
|
|
3745
3751
|
withTimeZoneOffset(offset) {
|
|
3746
3752
|
return new this.constructor(this.getTime(), {
|
|
3747
|
-
locale: this
|
|
3753
|
+
locale: this.#locale,
|
|
3748
3754
|
timeZone: formatOffset(offset),
|
|
3749
3755
|
});
|
|
3750
3756
|
}
|
|
@@ -3753,7 +3759,7 @@
|
|
|
3753
3759
|
* Returns a copy with the local week changed in the current time zone.
|
|
3754
3760
|
* @param {number} week The local week.
|
|
3755
3761
|
* @param {number|null} [day] The local day of the week. (1-7)
|
|
3756
|
-
* @
|
|
3762
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3757
3763
|
*/
|
|
3758
3764
|
withWeek(week, day = null) {
|
|
3759
3765
|
if (day === null) {
|
|
@@ -3767,7 +3773,7 @@
|
|
|
3767
3773
|
/**
|
|
3768
3774
|
* Returns a copy with the local day of the week changed in the current time zone.
|
|
3769
3775
|
* @param {number} day The local day of the week. (1-7)
|
|
3770
|
-
* @
|
|
3776
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3771
3777
|
*/
|
|
3772
3778
|
withWeekDay(day) {
|
|
3773
3779
|
return setOffsetTime(
|
|
@@ -3783,7 +3789,7 @@
|
|
|
3783
3789
|
/**
|
|
3784
3790
|
* Returns a copy with the week day in month changed in the current time zone.
|
|
3785
3791
|
* @param {number} week The week day in month.
|
|
3786
|
-
* @
|
|
3792
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3787
3793
|
*/
|
|
3788
3794
|
withWeekDayInMonth(week) {
|
|
3789
3795
|
return this.withDate(
|
|
@@ -3798,7 +3804,7 @@
|
|
|
3798
3804
|
/**
|
|
3799
3805
|
* Returns a copy with the week of month changed in the current time zone.
|
|
3800
3806
|
* @param {number} week The week of month.
|
|
3801
|
-
* @
|
|
3807
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3802
3808
|
*/
|
|
3803
3809
|
withWeekOfMonth(week) {
|
|
3804
3810
|
return this.withDate(
|
|
@@ -3815,7 +3821,7 @@
|
|
|
3815
3821
|
* @param {number} year The local week year.
|
|
3816
3822
|
* @param {number|null} [week] The local week.
|
|
3817
3823
|
* @param {number|null} [day] The local day of the week. (1-7)
|
|
3818
|
-
* @
|
|
3824
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3819
3825
|
*/
|
|
3820
3826
|
withWeekYear(year, week = null, day = null) {
|
|
3821
3827
|
const minDays = minimumDays(this.getLocale());
|
|
@@ -3843,7 +3849,7 @@
|
|
|
3843
3849
|
* @param {number} year The year.
|
|
3844
3850
|
* @param {number|null} [month] The month. (1-12)
|
|
3845
3851
|
* @param {number|null} [date] The date of the month.
|
|
3846
|
-
* @
|
|
3852
|
+
* @returns {DateTime} A new DateTime instance.
|
|
3847
3853
|
*/
|
|
3848
3854
|
withYear(year, month = null, date = null) {
|
|
3849
3855
|
if (month === null) {
|