@internationalized/date 3.11.0 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +113 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +45 -0
- package/dist/index.mjs.map +1 -0
- package/dist/{CalendarDate.main.js → private/CalendarDate.cjs} +102 -120
- package/dist/private/CalendarDate.cjs.map +1 -0
- package/dist/{CalendarDate.mjs → private/CalendarDate.js} +65 -65
- package/dist/private/CalendarDate.js.map +1 -0
- package/dist/{CalendarDate.module.js → private/CalendarDate.mjs} +99 -117
- package/dist/private/CalendarDate.mjs.map +1 -0
- package/dist/{DateFormatter.main.js → private/DateFormatter.cjs} +27 -27
- package/dist/private/DateFormatter.cjs.map +1 -0
- package/dist/{DateFormatter.module.js → private/DateFormatter.js} +23 -23
- package/dist/{DateFormatter.module.js.map → private/DateFormatter.js.map} +1 -1
- package/dist/{DateFormatter.mjs → private/DateFormatter.mjs} +27 -27
- package/dist/private/DateFormatter.mjs.map +1 -0
- package/dist/{BuddhistCalendar.main.js → private/calendars/BuddhistCalendar.cjs} +13 -13
- package/dist/{BuddhistCalendar.main.js.map → private/calendars/BuddhistCalendar.cjs.map} +1 -1
- package/dist/{BuddhistCalendar.module.js → private/calendars/BuddhistCalendar.js} +13 -13
- package/dist/{BuddhistCalendar.module.js.map → private/calendars/BuddhistCalendar.js.map} +1 -1
- package/dist/{BuddhistCalendar.mjs → private/calendars/BuddhistCalendar.mjs} +13 -13
- package/dist/private/calendars/BuddhistCalendar.mjs.map +1 -0
- package/dist/{EthiopicCalendar.main.js → private/calendars/EthiopicCalendar.cjs} +32 -32
- package/dist/{EthiopicCalendar.main.js.map → private/calendars/EthiopicCalendar.cjs.map} +1 -1
- package/dist/{EthiopicCalendar.module.js → private/calendars/EthiopicCalendar.js} +30 -30
- package/dist/{EthiopicCalendar.module.js.map → private/calendars/EthiopicCalendar.js.map} +1 -1
- package/dist/{EthiopicCalendar.mjs → private/calendars/EthiopicCalendar.mjs} +30 -30
- package/dist/private/calendars/EthiopicCalendar.mjs.map +1 -0
- package/dist/{GregorianCalendar.main.js → private/calendars/GregorianCalendar.cjs} +31 -31
- package/dist/{GregorianCalendar.main.js.map → private/calendars/GregorianCalendar.cjs.map} +1 -1
- package/dist/{GregorianCalendar.module.js → private/calendars/GregorianCalendar.js} +27 -27
- package/dist/{GregorianCalendar.module.js.map → private/calendars/GregorianCalendar.js.map} +1 -1
- package/dist/{GregorianCalendar.mjs → private/calendars/GregorianCalendar.mjs} +27 -27
- package/dist/private/calendars/GregorianCalendar.mjs.map +1 -0
- package/dist/{HebrewCalendar.main.js → private/calendars/HebrewCalendar.cjs} +44 -44
- package/dist/{HebrewCalendar.main.js.map → private/calendars/HebrewCalendar.cjs.map} +1 -1
- package/dist/{HebrewCalendar.module.js → private/calendars/HebrewCalendar.js} +44 -44
- package/dist/{HebrewCalendar.module.js.map → private/calendars/HebrewCalendar.js.map} +1 -1
- package/dist/{HebrewCalendar.mjs → private/calendars/HebrewCalendar.mjs} +44 -44
- package/dist/private/calendars/HebrewCalendar.mjs.map +1 -0
- package/dist/{IndianCalendar.main.js → private/calendars/IndianCalendar.cjs} +20 -20
- package/dist/{IndianCalendar.main.js.map → private/calendars/IndianCalendar.cjs.map} +1 -1
- package/dist/{IndianCalendar.module.js → private/calendars/IndianCalendar.js} +20 -20
- package/dist/{IndianCalendar.module.js.map → private/calendars/IndianCalendar.js.map} +1 -1
- package/dist/{IndianCalendar.mjs → private/calendars/IndianCalendar.mjs} +20 -20
- package/dist/private/calendars/IndianCalendar.mjs.map +1 -0
- package/dist/private/calendars/IslamicCalendar.cjs +168 -0
- package/dist/private/calendars/IslamicCalendar.cjs.map +1 -0
- package/dist/private/calendars/IslamicCalendar.js +161 -0
- package/dist/{IslamicCalendar.module.js.map → private/calendars/IslamicCalendar.js.map} +1 -1
- package/dist/private/calendars/IslamicCalendar.mjs +161 -0
- package/dist/private/calendars/IslamicCalendar.mjs.map +1 -0
- package/dist/{JapaneseCalendar.main.js → private/calendars/JapaneseCalendar.cjs} +37 -37
- package/dist/{JapaneseCalendar.main.js.map → private/calendars/JapaneseCalendar.cjs.map} +1 -1
- package/dist/{JapaneseCalendar.module.js → private/calendars/JapaneseCalendar.js} +37 -37
- package/dist/{JapaneseCalendar.module.js.map → private/calendars/JapaneseCalendar.js.map} +1 -1
- package/dist/{JapaneseCalendar.mjs → private/calendars/JapaneseCalendar.mjs} +37 -37
- package/dist/private/calendars/JapaneseCalendar.mjs.map +1 -0
- package/dist/{PersianCalendar.main.js → private/calendars/PersianCalendar.cjs} +13 -13
- package/dist/{PersianCalendar.main.js.map → private/calendars/PersianCalendar.cjs.map} +1 -1
- package/dist/{PersianCalendar.module.js → private/calendars/PersianCalendar.js} +13 -13
- package/dist/{PersianCalendar.module.js.map → private/calendars/PersianCalendar.js.map} +1 -1
- package/dist/{PersianCalendar.mjs → private/calendars/PersianCalendar.mjs} +13 -13
- package/dist/private/calendars/PersianCalendar.mjs.map +1 -0
- package/dist/{TaiwanCalendar.main.js → private/calendars/TaiwanCalendar.cjs} +20 -20
- package/dist/{TaiwanCalendar.main.js.map → private/calendars/TaiwanCalendar.cjs.map} +1 -1
- package/dist/private/calendars/TaiwanCalendar.js +75 -0
- package/dist/{TaiwanCalendar.module.js.map → private/calendars/TaiwanCalendar.js.map} +1 -1
- package/dist/{TaiwanCalendar.mjs → private/calendars/TaiwanCalendar.mjs} +20 -20
- package/dist/private/calendars/TaiwanCalendar.mjs.map +1 -0
- package/dist/private/conversion.cjs +241 -0
- package/dist/private/conversion.cjs.map +1 -0
- package/dist/private/conversion.js +222 -0
- package/dist/private/conversion.js.map +1 -0
- package/dist/private/conversion.mjs +222 -0
- package/dist/private/conversion.mjs.map +1 -0
- package/dist/private/createCalendar.cjs +69 -0
- package/dist/{createCalendar.main.js.map → private/createCalendar.cjs.map} +1 -1
- package/dist/private/createCalendar.js +64 -0
- package/dist/{createCalendar.module.js.map → private/createCalendar.js.map} +1 -1
- package/dist/private/createCalendar.mjs +64 -0
- package/dist/private/createCalendar.mjs.map +1 -0
- package/dist/{manipulation.main.js → private/manipulation.cjs} +106 -109
- package/dist/private/manipulation.cjs.map +1 -0
- package/dist/{manipulation.mjs → private/manipulation.js} +88 -88
- package/dist/{manipulation.module.js.map → private/manipulation.js.map} +1 -1
- package/dist/{manipulation.module.js → private/manipulation.mjs} +93 -96
- package/dist/private/manipulation.mjs.map +1 -0
- package/dist/private/queries.cjs +359 -0
- package/dist/private/queries.cjs.map +1 -0
- package/dist/private/queries.js +326 -0
- package/dist/private/queries.js.map +1 -0
- package/dist/private/queries.mjs +324 -0
- package/dist/private/queries.mjs.map +1 -0
- package/dist/private/string.cjs +181 -0
- package/dist/private/string.cjs.map +1 -0
- package/dist/{string.mjs → private/string.js} +64 -64
- package/dist/{string.module.js.map → private/string.js.map} +1 -1
- package/dist/private/string.mjs +166 -0
- package/dist/private/string.mjs.map +1 -0
- package/dist/{utils.main.js → private/utils.cjs} +3 -3
- package/dist/{utils.main.js.map → private/utils.cjs.map} +1 -1
- package/dist/{utils.module.js → private/utils.js} +3 -3
- package/dist/{utils.module.js.map → private/utils.js.map} +1 -1
- package/dist/{utils.mjs → private/utils.mjs} +3 -3
- package/dist/private/utils.mjs.map +1 -0
- package/dist/{weekStartData.main.js → private/weekStartData.cjs} +3 -3
- package/dist/{weekStartData.main.js.map → private/weekStartData.cjs.map} +1 -1
- package/dist/{weekStartData.module.js → private/weekStartData.js} +3 -3
- package/dist/{weekStartData.module.js.map → private/weekStartData.js.map} +1 -1
- package/dist/{weekStartData.mjs → private/weekStartData.mjs} +3 -3
- package/dist/private/weekStartData.mjs.map +1 -0
- package/dist/types/src/CalendarDate.d.ts +177 -0
- package/dist/types/src/DateFormatter.d.ts +21 -0
- package/dist/types/src/calendars/BuddhistCalendar.d.ts +16 -0
- package/dist/types/src/calendars/EthiopicCalendar.d.ts +45 -0
- package/dist/types/src/calendars/GregorianCalendar.d.ts +25 -0
- package/dist/types/src/calendars/HebrewCalendar.d.ts +21 -0
- package/dist/types/src/calendars/IndianCalendar.d.ts +17 -0
- package/dist/types/src/calendars/IslamicCalendar.d.ts +48 -0
- package/dist/types/src/calendars/JapaneseCalendar.d.ts +21 -0
- package/dist/types/src/calendars/PersianCalendar.d.ts +19 -0
- package/dist/types/src/calendars/TaiwanCalendar.d.ts +19 -0
- package/dist/types/src/conversion.d.ts +42 -0
- package/dist/types/src/createCalendar.d.ts +3 -0
- package/dist/types/src/index.d.ts +17 -0
- package/dist/types/src/manipulation.d.ts +25 -0
- package/dist/types/src/queries.d.ts +87 -0
- package/dist/types/src/string.d.ts +35 -0
- package/dist/types/src/types.d.ts +132 -0
- package/dist/types/src/utils.d.ts +4 -0
- package/dist/types/src/weekStartData.d.ts +97 -0
- package/package.json +26 -11
- package/src/CalendarDate.ts +2 -0
- package/src/conversion.ts +10 -3
- package/src/index.ts +2 -0
- package/src/queries.ts +9 -3
- package/dist/CalendarDate.main.js.map +0 -1
- package/dist/CalendarDate.module.js.map +0 -1
- package/dist/DateFormatter.main.js.map +0 -1
- package/dist/IslamicCalendar.main.js +0 -168
- package/dist/IslamicCalendar.main.js.map +0 -1
- package/dist/IslamicCalendar.mjs +0 -161
- package/dist/IslamicCalendar.module.js +0 -161
- package/dist/TaiwanCalendar.module.js +0 -75
- package/dist/conversion.main.js +0 -236
- package/dist/conversion.main.js.map +0 -1
- package/dist/conversion.mjs +0 -218
- package/dist/conversion.module.js +0 -218
- package/dist/conversion.module.js.map +0 -1
- package/dist/createCalendar.main.js +0 -69
- package/dist/createCalendar.mjs +0 -64
- package/dist/createCalendar.module.js +0 -64
- package/dist/import.mjs +0 -45
- package/dist/main.js +0 -112
- package/dist/main.js.map +0 -1
- package/dist/manipulation.main.js.map +0 -1
- package/dist/module.js +0 -45
- package/dist/module.js.map +0 -1
- package/dist/queries.main.js +0 -354
- package/dist/queries.main.js.map +0 -1
- package/dist/queries.mjs +0 -320
- package/dist/queries.module.js +0 -320
- package/dist/queries.module.js.map +0 -1
- package/dist/string.main.js +0 -190
- package/dist/string.main.js.map +0 -1
- package/dist/string.module.js +0 -175
- package/dist/types.d.ts +0 -668
- package/dist/types.d.ts.map +0 -1
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
1
|
+
var $e13115b3b86b9007$exports = require("./conversion.cjs");
|
|
2
|
+
var $05031860ba2f881f$exports = require("./calendars/GregorianCalendar.cjs");
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
$parcel$export(module.exports, "add", ()
|
|
10
|
-
$parcel$export(module.exports, "constrain", ()
|
|
11
|
-
$parcel$export(module.exports, "subtract", ()
|
|
12
|
-
$parcel$export(module.exports, "set", ()
|
|
13
|
-
$parcel$export(module.exports, "setTime", ()
|
|
14
|
-
$parcel$export(module.exports, "constrainTime", ()
|
|
15
|
-
$parcel$export(module.exports, "addTime", ()
|
|
16
|
-
$parcel$export(module.exports, "subtractTime", ()
|
|
17
|
-
$parcel$export(module.exports, "cycleDate", ()
|
|
18
|
-
$parcel$export(module.exports, "cycleTime", ()
|
|
19
|
-
$parcel$export(module.exports, "addZoned", ()
|
|
20
|
-
$parcel$export(module.exports, "subtractZoned", ()
|
|
21
|
-
$parcel$export(module.exports, "cycleZoned", ()
|
|
22
|
-
$parcel$export(module.exports, "setZoned", ()
|
|
9
|
+
$parcel$export(module.exports, "add", function () { return $19485913bea41f19$export$e16d8520af44a096; });
|
|
10
|
+
$parcel$export(module.exports, "constrain", function () { return $19485913bea41f19$export$c4e2ecac49351ef2; });
|
|
11
|
+
$parcel$export(module.exports, "subtract", function () { return $19485913bea41f19$export$4e2d2ead65e5f7e3; });
|
|
12
|
+
$parcel$export(module.exports, "set", function () { return $19485913bea41f19$export$adaa4cf7ef1b65be; });
|
|
13
|
+
$parcel$export(module.exports, "setTime", function () { return $19485913bea41f19$export$e5d5e1c1822b6e56; });
|
|
14
|
+
$parcel$export(module.exports, "constrainTime", function () { return $19485913bea41f19$export$7555de1e070510cb; });
|
|
15
|
+
$parcel$export(module.exports, "addTime", function () { return $19485913bea41f19$export$7ed87b6bc2506470; });
|
|
16
|
+
$parcel$export(module.exports, "subtractTime", function () { return $19485913bea41f19$export$fe34d3a381cd7501; });
|
|
17
|
+
$parcel$export(module.exports, "cycleDate", function () { return $19485913bea41f19$export$d52ced6badfb9a4c; });
|
|
18
|
+
$parcel$export(module.exports, "cycleTime", function () { return $19485913bea41f19$export$dd02b3e0007dfe28; });
|
|
19
|
+
$parcel$export(module.exports, "addZoned", function () { return $19485913bea41f19$export$96b1d28349274637; });
|
|
20
|
+
$parcel$export(module.exports, "subtractZoned", function () { return $19485913bea41f19$export$6814caac34ca03c7; });
|
|
21
|
+
$parcel$export(module.exports, "cycleZoned", function () { return $19485913bea41f19$export$9a297d111fc86b79; });
|
|
22
|
+
$parcel$export(module.exports, "setZoned", function () { return $19485913bea41f19$export$31b5430eb18be4f8; });
|
|
23
23
|
/*
|
|
24
24
|
* Copyright 2020 Adobe. All rights reserved.
|
|
25
25
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
@@ -32,19 +32,19 @@ $parcel$export(module.exports, "setZoned", () => $5c0571aa5b6fb5da$export$31b543
|
|
|
32
32
|
* governing permissions and limitations under the License.
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
const $
|
|
36
|
-
function $
|
|
35
|
+
const $19485913bea41f19$var$ONE_HOUR = 3600000;
|
|
36
|
+
function $19485913bea41f19$export$e16d8520af44a096(date, duration) {
|
|
37
37
|
let mutableDate = date.copy();
|
|
38
|
-
let days = 'hour' in mutableDate ? $
|
|
39
|
-
$
|
|
38
|
+
let days = 'hour' in mutableDate ? $19485913bea41f19$var$addTimeFields(mutableDate, duration) : 0;
|
|
39
|
+
$19485913bea41f19$var$addYears(mutableDate, duration.years || 0);
|
|
40
40
|
if (mutableDate.calendar.balanceYearMonth) mutableDate.calendar.balanceYearMonth(mutableDate, date);
|
|
41
41
|
mutableDate.month += duration.months || 0;
|
|
42
|
-
$
|
|
43
|
-
$
|
|
42
|
+
$19485913bea41f19$var$balanceYearMonth(mutableDate);
|
|
43
|
+
$19485913bea41f19$var$constrainMonthDay(mutableDate);
|
|
44
44
|
mutableDate.day += (duration.weeks || 0) * 7;
|
|
45
45
|
mutableDate.day += duration.days || 0;
|
|
46
46
|
mutableDate.day += days;
|
|
47
|
-
$
|
|
47
|
+
$19485913bea41f19$var$balanceDay(mutableDate);
|
|
48
48
|
if (mutableDate.calendar.balanceDate) mutableDate.calendar.balanceDate(mutableDate);
|
|
49
49
|
// Constrain in case adding ended up with a date outside the valid range for the calendar system.
|
|
50
50
|
// The behavior here is slightly different than when constraining in the `set` function in that
|
|
@@ -57,8 +57,7 @@ function $5c0571aa5b6fb5da$export$e16d8520af44a096(date, duration) {
|
|
|
57
57
|
}
|
|
58
58
|
let maxYear = mutableDate.calendar.getYearsInEra(mutableDate);
|
|
59
59
|
if (mutableDate.year > maxYear) {
|
|
60
|
-
|
|
61
|
-
let isInverseEra = (_mutableDate_calendar_isInverseEra = (_mutableDate_calendar = mutableDate.calendar).isInverseEra) === null || _mutableDate_calendar_isInverseEra === void 0 ? void 0 : _mutableDate_calendar_isInverseEra.call(_mutableDate_calendar, mutableDate);
|
|
60
|
+
let isInverseEra = mutableDate.calendar.isInverseEra?.(mutableDate);
|
|
62
61
|
mutableDate.year = maxYear;
|
|
63
62
|
mutableDate.month = isInverseEra ? 1 : mutableDate.calendar.getMonthsInYear(mutableDate);
|
|
64
63
|
mutableDate.day = isInverseEra ? 1 : mutableDate.calendar.getDaysInMonth(mutableDate);
|
|
@@ -75,107 +74,106 @@ function $5c0571aa5b6fb5da$export$e16d8520af44a096(date, duration) {
|
|
|
75
74
|
mutableDate.day = Math.max(1, Math.min(mutableDate.calendar.getDaysInMonth(mutableDate), mutableDate.day));
|
|
76
75
|
return mutableDate;
|
|
77
76
|
}
|
|
78
|
-
function $
|
|
79
|
-
|
|
80
|
-
if ((_date_calendar_isInverseEra = (_date_calendar = date.calendar).isInverseEra) === null || _date_calendar_isInverseEra === void 0 ? void 0 : _date_calendar_isInverseEra.call(_date_calendar, date)) years = -years;
|
|
77
|
+
function $19485913bea41f19$var$addYears(date, years) {
|
|
78
|
+
if (date.calendar.isInverseEra?.(date)) years = -years;
|
|
81
79
|
date.year += years;
|
|
82
80
|
}
|
|
83
|
-
function $
|
|
81
|
+
function $19485913bea41f19$var$balanceYearMonth(date) {
|
|
84
82
|
while(date.month < 1){
|
|
85
|
-
$
|
|
83
|
+
$19485913bea41f19$var$addYears(date, -1);
|
|
86
84
|
date.month += date.calendar.getMonthsInYear(date);
|
|
87
85
|
}
|
|
88
86
|
let monthsInYear = 0;
|
|
89
87
|
while(date.month > (monthsInYear = date.calendar.getMonthsInYear(date))){
|
|
90
88
|
date.month -= monthsInYear;
|
|
91
|
-
$
|
|
89
|
+
$19485913bea41f19$var$addYears(date, 1);
|
|
92
90
|
}
|
|
93
91
|
}
|
|
94
|
-
function $
|
|
92
|
+
function $19485913bea41f19$var$balanceDay(date) {
|
|
95
93
|
while(date.day < 1){
|
|
96
94
|
date.month--;
|
|
97
|
-
$
|
|
95
|
+
$19485913bea41f19$var$balanceYearMonth(date);
|
|
98
96
|
date.day += date.calendar.getDaysInMonth(date);
|
|
99
97
|
}
|
|
100
98
|
while(date.day > date.calendar.getDaysInMonth(date)){
|
|
101
99
|
date.day -= date.calendar.getDaysInMonth(date);
|
|
102
100
|
date.month++;
|
|
103
|
-
$
|
|
101
|
+
$19485913bea41f19$var$balanceYearMonth(date);
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
|
-
function $
|
|
104
|
+
function $19485913bea41f19$var$constrainMonthDay(date) {
|
|
107
105
|
date.month = Math.max(1, Math.min(date.calendar.getMonthsInYear(date), date.month));
|
|
108
106
|
date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));
|
|
109
107
|
}
|
|
110
|
-
function $
|
|
108
|
+
function $19485913bea41f19$export$c4e2ecac49351ef2(date) {
|
|
111
109
|
if (date.calendar.constrainDate) date.calendar.constrainDate(date);
|
|
112
110
|
date.year = Math.max(1, Math.min(date.calendar.getYearsInEra(date), date.year));
|
|
113
|
-
$
|
|
111
|
+
$19485913bea41f19$var$constrainMonthDay(date);
|
|
114
112
|
}
|
|
115
|
-
function $
|
|
113
|
+
function $19485913bea41f19$export$3e2544e88a25bff8(duration) {
|
|
116
114
|
let inverseDuration = {};
|
|
117
115
|
for(let key in duration)if (typeof duration[key] === 'number') inverseDuration[key] = -duration[key];
|
|
118
116
|
return inverseDuration;
|
|
119
117
|
}
|
|
120
|
-
function $
|
|
121
|
-
return $
|
|
118
|
+
function $19485913bea41f19$export$4e2d2ead65e5f7e3(date, duration) {
|
|
119
|
+
return $19485913bea41f19$export$e16d8520af44a096(date, $19485913bea41f19$export$3e2544e88a25bff8(duration));
|
|
122
120
|
}
|
|
123
|
-
function $
|
|
121
|
+
function $19485913bea41f19$export$adaa4cf7ef1b65be(date, fields) {
|
|
124
122
|
let mutableDate = date.copy();
|
|
125
123
|
if (fields.era != null) mutableDate.era = fields.era;
|
|
126
124
|
if (fields.year != null) mutableDate.year = fields.year;
|
|
127
125
|
if (fields.month != null) mutableDate.month = fields.month;
|
|
128
126
|
if (fields.day != null) mutableDate.day = fields.day;
|
|
129
|
-
$
|
|
127
|
+
$19485913bea41f19$export$c4e2ecac49351ef2(mutableDate);
|
|
130
128
|
return mutableDate;
|
|
131
129
|
}
|
|
132
|
-
function $
|
|
130
|
+
function $19485913bea41f19$export$e5d5e1c1822b6e56(value, fields) {
|
|
133
131
|
let mutableValue = value.copy();
|
|
134
132
|
if (fields.hour != null) mutableValue.hour = fields.hour;
|
|
135
133
|
if (fields.minute != null) mutableValue.minute = fields.minute;
|
|
136
134
|
if (fields.second != null) mutableValue.second = fields.second;
|
|
137
135
|
if (fields.millisecond != null) mutableValue.millisecond = fields.millisecond;
|
|
138
|
-
$
|
|
136
|
+
$19485913bea41f19$export$7555de1e070510cb(mutableValue);
|
|
139
137
|
return mutableValue;
|
|
140
138
|
}
|
|
141
|
-
function $
|
|
139
|
+
function $19485913bea41f19$var$balanceTime(time) {
|
|
142
140
|
time.second += Math.floor(time.millisecond / 1000);
|
|
143
|
-
time.millisecond = $
|
|
141
|
+
time.millisecond = $19485913bea41f19$var$nonNegativeMod(time.millisecond, 1000);
|
|
144
142
|
time.minute += Math.floor(time.second / 60);
|
|
145
|
-
time.second = $
|
|
143
|
+
time.second = $19485913bea41f19$var$nonNegativeMod(time.second, 60);
|
|
146
144
|
time.hour += Math.floor(time.minute / 60);
|
|
147
|
-
time.minute = $
|
|
145
|
+
time.minute = $19485913bea41f19$var$nonNegativeMod(time.minute, 60);
|
|
148
146
|
let days = Math.floor(time.hour / 24);
|
|
149
|
-
time.hour = $
|
|
147
|
+
time.hour = $19485913bea41f19$var$nonNegativeMod(time.hour, 24);
|
|
150
148
|
return days;
|
|
151
149
|
}
|
|
152
|
-
function $
|
|
150
|
+
function $19485913bea41f19$export$7555de1e070510cb(time) {
|
|
153
151
|
time.millisecond = Math.max(0, Math.min(time.millisecond, 1000));
|
|
154
152
|
time.second = Math.max(0, Math.min(time.second, 59));
|
|
155
153
|
time.minute = Math.max(0, Math.min(time.minute, 59));
|
|
156
154
|
time.hour = Math.max(0, Math.min(time.hour, 23));
|
|
157
155
|
}
|
|
158
|
-
function $
|
|
156
|
+
function $19485913bea41f19$var$nonNegativeMod(a, b) {
|
|
159
157
|
let result = a % b;
|
|
160
158
|
if (result < 0) result += b;
|
|
161
159
|
return result;
|
|
162
160
|
}
|
|
163
|
-
function $
|
|
161
|
+
function $19485913bea41f19$var$addTimeFields(time, duration) {
|
|
164
162
|
time.hour += duration.hours || 0;
|
|
165
163
|
time.minute += duration.minutes || 0;
|
|
166
164
|
time.second += duration.seconds || 0;
|
|
167
165
|
time.millisecond += duration.milliseconds || 0;
|
|
168
|
-
return $
|
|
166
|
+
return $19485913bea41f19$var$balanceTime(time);
|
|
169
167
|
}
|
|
170
|
-
function $
|
|
168
|
+
function $19485913bea41f19$export$7ed87b6bc2506470(time, duration) {
|
|
171
169
|
let res = time.copy();
|
|
172
|
-
$
|
|
170
|
+
$19485913bea41f19$var$addTimeFields(res, duration);
|
|
173
171
|
return res;
|
|
174
172
|
}
|
|
175
|
-
function $
|
|
176
|
-
return $
|
|
173
|
+
function $19485913bea41f19$export$fe34d3a381cd7501(time, duration) {
|
|
174
|
+
return $19485913bea41f19$export$7ed87b6bc2506470(time, $19485913bea41f19$export$3e2544e88a25bff8(duration));
|
|
177
175
|
}
|
|
178
|
-
function $
|
|
176
|
+
function $19485913bea41f19$export$d52ced6badfb9a4c(value, field, amount, options) {
|
|
179
177
|
let mutable = value.copy();
|
|
180
178
|
switch(field){
|
|
181
179
|
case 'era':
|
|
@@ -183,36 +181,35 @@ function $5c0571aa5b6fb5da$export$d52ced6badfb9a4c(value, field, amount, options
|
|
|
183
181
|
let eras = value.calendar.getEras();
|
|
184
182
|
let eraIndex = eras.indexOf(value.era);
|
|
185
183
|
if (eraIndex < 0) throw new Error('Invalid era: ' + value.era);
|
|
186
|
-
eraIndex = $
|
|
184
|
+
eraIndex = $19485913bea41f19$var$cycleValue(eraIndex, amount, 0, eras.length - 1, options?.round);
|
|
187
185
|
mutable.era = eras[eraIndex];
|
|
188
186
|
// Constrain the year and other fields within the era, so the era doesn't change when we balance below.
|
|
189
|
-
$
|
|
187
|
+
$19485913bea41f19$export$c4e2ecac49351ef2(mutable);
|
|
190
188
|
break;
|
|
191
189
|
}
|
|
192
190
|
case 'year':
|
|
193
|
-
|
|
194
|
-
if ((_mutable_calendar_isInverseEra = (_mutable_calendar = mutable.calendar).isInverseEra) === null || _mutable_calendar_isInverseEra === void 0 ? void 0 : _mutable_calendar_isInverseEra.call(_mutable_calendar, mutable)) amount = -amount;
|
|
191
|
+
if (mutable.calendar.isInverseEra?.(mutable)) amount = -amount;
|
|
195
192
|
// The year field should not cycle within the era as that can cause weird behavior affecting other fields.
|
|
196
193
|
// We need to also allow values < 1 so that decrementing goes to the previous era. If we get -Infinity back
|
|
197
194
|
// we know we wrapped around after reaching 9999 (the maximum), so set the year back to 1.
|
|
198
|
-
mutable.year = $
|
|
195
|
+
mutable.year = $19485913bea41f19$var$cycleValue(value.year, amount, -Infinity, 9999, options?.round);
|
|
199
196
|
if (mutable.year === -Infinity) mutable.year = 1;
|
|
200
197
|
if (mutable.calendar.balanceYearMonth) mutable.calendar.balanceYearMonth(mutable, value);
|
|
201
198
|
break;
|
|
202
199
|
case 'month':
|
|
203
|
-
mutable.month = $
|
|
200
|
+
mutable.month = $19485913bea41f19$var$cycleValue(value.month, amount, 1, value.calendar.getMonthsInYear(value), options?.round);
|
|
204
201
|
break;
|
|
205
202
|
case 'day':
|
|
206
|
-
mutable.day = $
|
|
203
|
+
mutable.day = $19485913bea41f19$var$cycleValue(value.day, amount, 1, value.calendar.getDaysInMonth(value), options?.round);
|
|
207
204
|
break;
|
|
208
205
|
default:
|
|
209
206
|
throw new Error('Unsupported field ' + field);
|
|
210
207
|
}
|
|
211
208
|
if (value.calendar.balanceDate) value.calendar.balanceDate(mutable);
|
|
212
|
-
$
|
|
209
|
+
$19485913bea41f19$export$c4e2ecac49351ef2(mutable);
|
|
213
210
|
return mutable;
|
|
214
211
|
}
|
|
215
|
-
function $
|
|
212
|
+
function $19485913bea41f19$export$dd02b3e0007dfe28(value, field, amount, options) {
|
|
216
213
|
let mutable = value.copy();
|
|
217
214
|
switch(field){
|
|
218
215
|
case 'hour':
|
|
@@ -220,29 +217,29 @@ function $5c0571aa5b6fb5da$export$dd02b3e0007dfe28(value, field, amount, options
|
|
|
220
217
|
let hours = value.hour;
|
|
221
218
|
let min = 0;
|
|
222
219
|
let max = 23;
|
|
223
|
-
if (
|
|
220
|
+
if (options?.hourCycle === 12) {
|
|
224
221
|
let isPM = hours >= 12;
|
|
225
222
|
min = isPM ? 12 : 0;
|
|
226
223
|
max = isPM ? 23 : 11;
|
|
227
224
|
}
|
|
228
|
-
mutable.hour = $
|
|
225
|
+
mutable.hour = $19485913bea41f19$var$cycleValue(hours, amount, min, max, options?.round);
|
|
229
226
|
break;
|
|
230
227
|
}
|
|
231
228
|
case 'minute':
|
|
232
|
-
mutable.minute = $
|
|
229
|
+
mutable.minute = $19485913bea41f19$var$cycleValue(value.minute, amount, 0, 59, options?.round);
|
|
233
230
|
break;
|
|
234
231
|
case 'second':
|
|
235
|
-
mutable.second = $
|
|
232
|
+
mutable.second = $19485913bea41f19$var$cycleValue(value.second, amount, 0, 59, options?.round);
|
|
236
233
|
break;
|
|
237
234
|
case 'millisecond':
|
|
238
|
-
mutable.millisecond = $
|
|
235
|
+
mutable.millisecond = $19485913bea41f19$var$cycleValue(value.millisecond, amount, 0, 999, options?.round);
|
|
239
236
|
break;
|
|
240
237
|
default:
|
|
241
238
|
throw new Error('Unsupported field ' + field);
|
|
242
239
|
}
|
|
243
240
|
return mutable;
|
|
244
241
|
}
|
|
245
|
-
function $
|
|
242
|
+
function $19485913bea41f19$var$cycleValue(value, amount, min, max, round = false) {
|
|
246
243
|
if (round) {
|
|
247
244
|
value += Math.sign(amount);
|
|
248
245
|
if (value < min) value = max;
|
|
@@ -257,10 +254,10 @@ function $5c0571aa5b6fb5da$var$cycleValue(value, amount, min, max, round = false
|
|
|
257
254
|
}
|
|
258
255
|
return value;
|
|
259
256
|
}
|
|
260
|
-
function $
|
|
257
|
+
function $19485913bea41f19$export$96b1d28349274637(dateTime, duration) {
|
|
261
258
|
let ms;
|
|
262
259
|
if (duration.years != null && duration.years !== 0 || duration.months != null && duration.months !== 0 || duration.weeks != null && duration.weeks !== 0 || duration.days != null && duration.days !== 0) {
|
|
263
|
-
let res = $
|
|
260
|
+
let res = $19485913bea41f19$export$e16d8520af44a096((0, $e13115b3b86b9007$exports.toCalendarDateTime)(dateTime), {
|
|
264
261
|
years: duration.years,
|
|
265
262
|
months: duration.months,
|
|
266
263
|
weeks: duration.weeks,
|
|
@@ -268,9 +265,9 @@ function $5c0571aa5b6fb5da$export$96b1d28349274637(dateTime, duration) {
|
|
|
268
265
|
});
|
|
269
266
|
// Changing the date may change the timezone offset, so we need to recompute
|
|
270
267
|
// using the 'compatible' disambiguation.
|
|
271
|
-
ms = (0, $
|
|
268
|
+
ms = (0, $e13115b3b86b9007$exports.toAbsolute)(res, dateTime.timeZone);
|
|
272
269
|
} else // Otherwise, preserve the offset of the original date.
|
|
273
|
-
ms = (0, $
|
|
270
|
+
ms = (0, $e13115b3b86b9007$exports.epochFromDate)(dateTime) - dateTime.offset;
|
|
274
271
|
// Perform time manipulation in milliseconds rather than on the original time fields to account for DST.
|
|
275
272
|
// For example, adding one hour during a DST transition may result in the hour field staying the same or
|
|
276
273
|
// skipping an hour. This results in the offset field changing value instead of the specified field.
|
|
@@ -278,13 +275,13 @@ function $5c0571aa5b6fb5da$export$96b1d28349274637(dateTime, duration) {
|
|
|
278
275
|
ms += (duration.seconds || 0) * 1000;
|
|
279
276
|
ms += (duration.minutes || 0) * 60000;
|
|
280
277
|
ms += (duration.hours || 0) * 3600000;
|
|
281
|
-
let res = (0, $
|
|
282
|
-
return (0, $
|
|
278
|
+
let res = (0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone);
|
|
279
|
+
return (0, $e13115b3b86b9007$exports.toCalendar)(res, dateTime.calendar);
|
|
283
280
|
}
|
|
284
|
-
function $
|
|
285
|
-
return $
|
|
281
|
+
function $19485913bea41f19$export$6814caac34ca03c7(dateTime, duration) {
|
|
282
|
+
return $19485913bea41f19$export$96b1d28349274637(dateTime, $19485913bea41f19$export$3e2544e88a25bff8(duration));
|
|
286
283
|
}
|
|
287
|
-
function $
|
|
284
|
+
function $19485913bea41f19$export$9a297d111fc86b79(dateTime, field, amount, options) {
|
|
288
285
|
// For date fields, we want the time to remain consistent and the UTC offset to potentially change to account for DST changes.
|
|
289
286
|
// For time fields, we want the time to change by the amount given. This may result in the hour field staying the same, but the UTC
|
|
290
287
|
// offset changing in the case of a backward DST transition, or skipping an hour in the case of a forward DST transition.
|
|
@@ -293,7 +290,7 @@ function $5c0571aa5b6fb5da$export$9a297d111fc86b79(dateTime, field, amount, opti
|
|
|
293
290
|
{
|
|
294
291
|
let min = 0;
|
|
295
292
|
let max = 23;
|
|
296
|
-
if (
|
|
293
|
+
if (options?.hourCycle === 12) {
|
|
297
294
|
let isPM = dateTime.hour >= 12;
|
|
298
295
|
min = isPM ? 12 : 0;
|
|
299
296
|
max = isPM ? 23 : 11;
|
|
@@ -303,60 +300,60 @@ function $5c0571aa5b6fb5da$export$9a297d111fc86b79(dateTime, field, amount, opti
|
|
|
303
300
|
// Or it might end at midnight and repeat the 11pm hour. To handle this, we get
|
|
304
301
|
// the possible absolute times for the min and max, and find the maximum range
|
|
305
302
|
// that is within the current day.
|
|
306
|
-
let plainDateTime = (0, $
|
|
307
|
-
let minDate = (0, $
|
|
303
|
+
let plainDateTime = (0, $e13115b3b86b9007$exports.toCalendarDateTime)(dateTime);
|
|
304
|
+
let minDate = (0, $e13115b3b86b9007$exports.toCalendar)($19485913bea41f19$export$e5d5e1c1822b6e56(plainDateTime, {
|
|
308
305
|
hour: min
|
|
309
|
-
}), new (0, $
|
|
306
|
+
}), new (0, $05031860ba2f881f$exports.GregorianCalendar)());
|
|
310
307
|
let minAbsolute = [
|
|
311
|
-
(0, $
|
|
312
|
-
(0, $
|
|
313
|
-
].filter((ms)=>(0, $
|
|
314
|
-
let maxDate = (0, $
|
|
308
|
+
(0, $e13115b3b86b9007$exports.toAbsolute)(minDate, dateTime.timeZone, 'earlier'),
|
|
309
|
+
(0, $e13115b3b86b9007$exports.toAbsolute)(minDate, dateTime.timeZone, 'later')
|
|
310
|
+
].filter((ms)=>(0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone).day === minDate.day)[0];
|
|
311
|
+
let maxDate = (0, $e13115b3b86b9007$exports.toCalendar)($19485913bea41f19$export$e5d5e1c1822b6e56(plainDateTime, {
|
|
315
312
|
hour: max
|
|
316
|
-
}), new (0, $
|
|
313
|
+
}), new (0, $05031860ba2f881f$exports.GregorianCalendar)());
|
|
317
314
|
let maxAbsolute = [
|
|
318
|
-
(0, $
|
|
319
|
-
(0, $
|
|
320
|
-
].filter((ms)=>(0, $
|
|
315
|
+
(0, $e13115b3b86b9007$exports.toAbsolute)(maxDate, dateTime.timeZone, 'earlier'),
|
|
316
|
+
(0, $e13115b3b86b9007$exports.toAbsolute)(maxDate, dateTime.timeZone, 'later')
|
|
317
|
+
].filter((ms)=>(0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone).day === maxDate.day).pop();
|
|
321
318
|
// Since hours may repeat, we need to operate on the absolute time in milliseconds.
|
|
322
319
|
// This is done in hours from the Unix epoch so that cycleValue works correctly,
|
|
323
320
|
// and then converted back to milliseconds.
|
|
324
|
-
let ms = (0, $
|
|
325
|
-
let hours = Math.floor(ms / $
|
|
326
|
-
let remainder = ms % $
|
|
327
|
-
ms = $
|
|
321
|
+
let ms = (0, $e13115b3b86b9007$exports.epochFromDate)(dateTime) - dateTime.offset;
|
|
322
|
+
let hours = Math.floor(ms / $19485913bea41f19$var$ONE_HOUR);
|
|
323
|
+
let remainder = ms % $19485913bea41f19$var$ONE_HOUR;
|
|
324
|
+
ms = $19485913bea41f19$var$cycleValue(hours, amount, Math.floor(minAbsolute / $19485913bea41f19$var$ONE_HOUR), Math.floor(maxAbsolute / $19485913bea41f19$var$ONE_HOUR), options?.round) * $19485913bea41f19$var$ONE_HOUR + remainder;
|
|
328
325
|
// Now compute the new timezone offset, and convert the absolute time back to local time.
|
|
329
|
-
return (0, $
|
|
326
|
+
return (0, $e13115b3b86b9007$exports.toCalendar)((0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone), dateTime.calendar);
|
|
330
327
|
}
|
|
331
328
|
case 'minute':
|
|
332
329
|
case 'second':
|
|
333
330
|
case 'millisecond':
|
|
334
331
|
// @ts-ignore
|
|
335
|
-
return $
|
|
332
|
+
return $19485913bea41f19$export$dd02b3e0007dfe28(dateTime, field, amount, options);
|
|
336
333
|
case 'era':
|
|
337
334
|
case 'year':
|
|
338
335
|
case 'month':
|
|
339
336
|
case 'day':
|
|
340
337
|
{
|
|
341
|
-
let res = $
|
|
342
|
-
let ms = (0, $
|
|
343
|
-
return (0, $
|
|
338
|
+
let res = $19485913bea41f19$export$d52ced6badfb9a4c((0, $e13115b3b86b9007$exports.toCalendarDateTime)(dateTime), field, amount, options);
|
|
339
|
+
let ms = (0, $e13115b3b86b9007$exports.toAbsolute)(res, dateTime.timeZone);
|
|
340
|
+
return (0, $e13115b3b86b9007$exports.toCalendar)((0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone), dateTime.calendar);
|
|
344
341
|
}
|
|
345
342
|
default:
|
|
346
343
|
throw new Error('Unsupported field ' + field);
|
|
347
344
|
}
|
|
348
345
|
}
|
|
349
|
-
function $
|
|
346
|
+
function $19485913bea41f19$export$31b5430eb18be4f8(dateTime, fields, disambiguation) {
|
|
350
347
|
// Set the date/time fields, and recompute the UTC offset to account for DST changes.
|
|
351
348
|
// We also need to validate by converting back to a local time in case hours are skipped during forward DST transitions.
|
|
352
|
-
let plainDateTime = (0, $
|
|
353
|
-
let res = $
|
|
349
|
+
let plainDateTime = (0, $e13115b3b86b9007$exports.toCalendarDateTime)(dateTime);
|
|
350
|
+
let res = $19485913bea41f19$export$e5d5e1c1822b6e56($19485913bea41f19$export$adaa4cf7ef1b65be(plainDateTime, fields), fields);
|
|
354
351
|
// If the resulting plain date time values are equal, return the original time.
|
|
355
352
|
// We don't want to change the offset when setting the time to the same value.
|
|
356
353
|
if (res.compare(plainDateTime) === 0) return dateTime;
|
|
357
|
-
let ms = (0, $
|
|
358
|
-
return (0, $
|
|
354
|
+
let ms = (0, $e13115b3b86b9007$exports.toAbsolute)(res, dateTime.timeZone, disambiguation);
|
|
355
|
+
return (0, $e13115b3b86b9007$exports.toCalendar)((0, $e13115b3b86b9007$exports.fromAbsolute)(ms, dateTime.timeZone), dateTime.calendar);
|
|
359
356
|
}
|
|
360
357
|
|
|
361
358
|
|
|
362
|
-
//# sourceMappingURL=manipulation.
|
|
359
|
+
//# sourceMappingURL=manipulation.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAQD,MAAM,iCAAW;AAKV,SAAS,0CAAI,IAAqC,EAAE,QAA0B;IACnF,IAAI,cAAsD,KAAK,IAAI;IACnE,IAAI,OAAO,UAAU,cAAc,oCAAc,aAAa,YAAY;IAE1E,+BAAS,aAAa,SAAS,KAAK,IAAI;IACxC,IAAI,YAAY,QAAQ,CAAC,gBAAgB,EACvC,YAAY,QAAQ,CAAC,gBAAgB,CAAC,aAAa;IAGrD,YAAY,KAAK,IAAI,SAAS,MAAM,IAAI;IAExC,uCAAiB;IACjB,wCAAkB;IAElB,YAAY,GAAG,IAAI,AAAC,CAAA,SAAS,KAAK,IAAI,CAAA,IAAK;IAC3C,YAAY,GAAG,IAAI,SAAS,IAAI,IAAI;IACpC,YAAY,GAAG,IAAI;IAEnB,iCAAW;IAEX,IAAI,YAAY,QAAQ,CAAC,WAAW,EAClC,YAAY,QAAQ,CAAC,WAAW,CAAC;IAGnC,iGAAiG;IACjG,+FAA+F;IAC/F,+FAA+F;IAC/F,uGAAuG;IACvG,IAAI,YAAY,IAAI,GAAG,GAAG;QACxB,YAAY,IAAI,GAAG;QACnB,YAAY,KAAK,GAAG;QACpB,YAAY,GAAG,GAAG;IACpB;IAEA,IAAI,UAAU,YAAY,QAAQ,CAAC,aAAa,CAAC;IACjD,IAAI,YAAY,IAAI,GAAG,SAAS;QAC9B,IAAI,eAAe,YAAY,QAAQ,CAAC,YAAY,GAAG;QACvD,YA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,0CAAQ,0CAAI,eAAe,SAAS;IAE9C,+EAA+E;IAC/E,8EAA8E;IAC9E,IAAI,IAAI,OAAO,CAAC,mBAAmB,GACjC,OAAO;IAGT,IAAI,KAAK,CAAA,GAAA,oCAAS,EAAE,KAAK,SAAS,QAAQ,EAAE;IAC5C,OAAO,CAAA,GAAA,oCAAS,EAAE,CAAA,GAAA,sCAAW,EAAE,IAAI,SAAS,QAAQ,GAAG,SAAS,QAAQ;AAC1E","sources":["packages/@internationalized/date/src/manipulation.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AnyCalendarDate, AnyDateTime, AnyTime, CycleOptions, CycleTimeOptions, DateDuration, DateField, DateFields, DateTimeDuration, Disambiguation, TimeDuration, TimeField, TimeFields} from './types';\nimport {CalendarDate, CalendarDateTime, Time, ZonedDateTime} from './CalendarDate';\nimport {epochFromDate, fromAbsolute, toAbsolute, toCalendar, toCalendarDateTime} from './conversion';\nimport {GregorianCalendar} from './calendars/GregorianCalendar';\nimport {Mutable} from './utils';\n\nconst ONE_HOUR = 3600000;\n\nexport function add(date: CalendarDateTime, duration: DateTimeDuration): CalendarDateTime;\nexport function add(date: CalendarDate, duration: DateDuration): CalendarDate;\nexport function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): CalendarDate | CalendarDateTime;\nexport function add(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): Mutable<AnyCalendarDate | AnyDateTime> {\n let mutableDate: Mutable<AnyCalendarDate | AnyDateTime> = date.copy();\n let days = 'hour' in mutableDate ? addTimeFields(mutableDate, duration) : 0;\n\n addYears(mutableDate, duration.years || 0);\n if (mutableDate.calendar.balanceYearMonth) {\n mutableDate.calendar.balanceYearMonth(mutableDate, date);\n }\n\n mutableDate.month += duration.months || 0;\n\n balanceYearMonth(mutableDate);\n constrainMonthDay(mutableDate);\n\n mutableDate.day += (duration.weeks || 0) * 7;\n mutableDate.day += duration.days || 0;\n mutableDate.day += days;\n\n balanceDay(mutableDate);\n\n if (mutableDate.calendar.balanceDate) {\n mutableDate.calendar.balanceDate(mutableDate);\n }\n\n // Constrain in case adding ended up with a date outside the valid range for the calendar system.\n // The behavior here is slightly different than when constraining in the `set` function in that\n // we adjust smaller fields to their minimum/maximum values rather than constraining each field\n // individually. This matches the general behavior of `add` vs `set` regarding how fields are balanced.\n if (mutableDate.year < 1) {\n mutableDate.year = 1;\n mutableDate.month = 1;\n mutableDate.day = 1;\n }\n\n let maxYear = mutableDate.calendar.getYearsInEra(mutableDate);\n if (mutableDate.year > maxYear) {\n let isInverseEra = mutableDate.calendar.isInverseEra?.(mutableDate);\n mutableDate.year = maxYear;\n mutableDate.month = isInverseEra ? 1 : mutableDate.calendar.getMonthsInYear(mutableDate);\n mutableDate.day = isInverseEra ? 1 : mutableDate.calendar.getDaysInMonth(mutableDate);\n }\n\n if (mutableDate.month < 1) {\n mutableDate.month = 1;\n mutableDate.day = 1;\n }\n\n let maxMonth = mutableDate.calendar.getMonthsInYear(mutableDate);\n if (mutableDate.month > maxMonth) {\n mutableDate.month = maxMonth;\n mutableDate.day = mutableDate.calendar.getDaysInMonth(mutableDate);\n }\n\n mutableDate.day = Math.max(1, Math.min(mutableDate.calendar.getDaysInMonth(mutableDate), mutableDate.day));\n return mutableDate;\n}\n\nfunction addYears(date: Mutable<AnyCalendarDate>, years: number) {\n if (date.calendar.isInverseEra?.(date)) {\n years = -years;\n }\n\n date.year += years;\n}\n\nfunction balanceYearMonth(date: Mutable<AnyCalendarDate>) {\n while (date.month < 1) {\n addYears(date, -1);\n date.month += date.calendar.getMonthsInYear(date);\n }\n\n let monthsInYear = 0;\n while (date.month > (monthsInYear = date.calendar.getMonthsInYear(date))) {\n date.month -= monthsInYear;\n addYears(date, 1);\n }\n}\n\nfunction balanceDay(date: Mutable<AnyCalendarDate>) {\n while (date.day < 1) {\n date.month--;\n balanceYearMonth(date);\n date.day += date.calendar.getDaysInMonth(date);\n }\n\n while (date.day > date.calendar.getDaysInMonth(date)) {\n date.day -= date.calendar.getDaysInMonth(date);\n date.month++;\n balanceYearMonth(date);\n }\n}\n\nfunction constrainMonthDay(date: Mutable<AnyCalendarDate>) {\n date.month = Math.max(1, Math.min(date.calendar.getMonthsInYear(date), date.month));\n date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));\n}\n\nexport function constrain(date: Mutable<AnyCalendarDate>): void {\n if (date.calendar.constrainDate) {\n date.calendar.constrainDate(date);\n }\n\n date.year = Math.max(1, Math.min(date.calendar.getYearsInEra(date), date.year));\n constrainMonthDay(date);\n}\n\nexport function invertDuration(duration: DateTimeDuration): DateTimeDuration {\n let inverseDuration = {};\n for (let key in duration) {\n if (typeof duration[key] === 'number') {\n inverseDuration[key] = -duration[key];\n }\n }\n\n return inverseDuration;\n}\n\nexport function subtract(date: CalendarDateTime, duration: DateTimeDuration): CalendarDateTime;\nexport function subtract(date: CalendarDate, duration: DateDuration): CalendarDate;\nexport function subtract(date: CalendarDate | CalendarDateTime, duration: DateTimeDuration): CalendarDate | CalendarDateTime {\n return add(date, invertDuration(duration));\n}\n\nexport function set(date: CalendarDateTime, fields: DateFields): CalendarDateTime;\nexport function set(date: CalendarDate, fields: DateFields): CalendarDate;\nexport function set(date: CalendarDate | CalendarDateTime, fields: DateFields): Mutable<AnyCalendarDate> {\n let mutableDate: Mutable<AnyCalendarDate> = date.copy();\n\n if (fields.era != null) {\n mutableDate.era = fields.era;\n }\n\n if (fields.year != null) {\n mutableDate.year = fields.year;\n }\n\n if (fields.month != null) {\n mutableDate.month = fields.month;\n }\n\n if (fields.day != null) {\n mutableDate.day = fields.day;\n }\n\n constrain(mutableDate);\n return mutableDate;\n}\n\nexport function setTime(value: CalendarDateTime, fields: TimeFields): CalendarDateTime;\nexport function setTime(value: Time, fields: TimeFields): Time;\nexport function setTime(value: Time | CalendarDateTime, fields: TimeFields): Mutable<Time | CalendarDateTime> {\n let mutableValue: Mutable<Time | CalendarDateTime> = value.copy();\n\n if (fields.hour != null) {\n mutableValue.hour = fields.hour;\n }\n\n if (fields.minute != null) {\n mutableValue.minute = fields.minute;\n }\n\n if (fields.second != null) {\n mutableValue.second = fields.second;\n }\n\n if (fields.millisecond != null) {\n mutableValue.millisecond = fields.millisecond;\n }\n\n constrainTime(mutableValue);\n return mutableValue;\n}\n\nfunction balanceTime(time: Mutable<AnyTime>): number {\n time.second += Math.floor(time.millisecond / 1000);\n time.millisecond = nonNegativeMod(time.millisecond, 1000);\n\n time.minute += Math.floor(time.second / 60);\n time.second = nonNegativeMod(time.second, 60);\n\n time.hour += Math.floor(time.minute / 60);\n time.minute = nonNegativeMod(time.minute, 60);\n\n let days = Math.floor(time.hour / 24);\n time.hour = nonNegativeMod(time.hour, 24);\n\n return days;\n}\n\nexport function constrainTime(time: Mutable<AnyTime>): void {\n time.millisecond = Math.max(0, Math.min(time.millisecond, 1000));\n time.second = Math.max(0, Math.min(time.second, 59));\n time.minute = Math.max(0, Math.min(time.minute, 59));\n time.hour = Math.max(0, Math.min(time.hour, 23));\n}\n\nfunction nonNegativeMod(a: number, b: number) {\n let result = a % b;\n if (result < 0) {\n result += b;\n }\n return result;\n}\n\nfunction addTimeFields(time: Mutable<AnyTime>, duration: TimeDuration): number {\n time.hour += duration.hours || 0;\n time.minute += duration.minutes || 0;\n time.second += duration.seconds || 0;\n time.millisecond += duration.milliseconds || 0;\n return balanceTime(time);\n}\n\nexport function addTime(time: Time, duration: TimeDuration): Time {\n let res = time.copy();\n addTimeFields(res, duration);\n return res;\n}\n\nexport function subtractTime(time: Time, duration: TimeDuration): Time {\n return addTime(time, invertDuration(duration));\n}\n\nexport function cycleDate(value: CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): CalendarDateTime;\nexport function cycleDate(value: CalendarDate, field: DateField, amount: number, options?: CycleOptions): CalendarDate;\nexport function cycleDate(value: CalendarDate | CalendarDateTime, field: DateField, amount: number, options?: CycleOptions): Mutable<CalendarDate | CalendarDateTime> {\n let mutable: Mutable<CalendarDate | CalendarDateTime> = value.copy();\n\n switch (field) {\n case 'era': {\n let eras = value.calendar.getEras();\n let eraIndex = eras.indexOf(value.era);\n if (eraIndex < 0) {\n throw new Error('Invalid era: ' + value.era);\n }\n eraIndex = cycleValue(eraIndex, amount, 0, eras.length - 1, options?.round);\n mutable.era = eras[eraIndex];\n\n // Constrain the year and other fields within the era, so the era doesn't change when we balance below.\n constrain(mutable);\n break;\n }\n case 'year': {\n if (mutable.calendar.isInverseEra?.(mutable)) {\n amount = -amount;\n }\n\n // The year field should not cycle within the era as that can cause weird behavior affecting other fields.\n // We need to also allow values < 1 so that decrementing goes to the previous era. If we get -Infinity back\n // we know we wrapped around after reaching 9999 (the maximum), so set the year back to 1.\n mutable.year = cycleValue(value.year, amount, -Infinity, 9999, options?.round);\n if (mutable.year === -Infinity) {\n mutable.year = 1;\n }\n\n if (mutable.calendar.balanceYearMonth) {\n mutable.calendar.balanceYearMonth(mutable, value);\n }\n break;\n }\n case 'month':\n mutable.month = cycleValue(value.month, amount, 1, value.calendar.getMonthsInYear(value), options?.round);\n break;\n case 'day':\n mutable.day = cycleValue(value.day, amount, 1, value.calendar.getDaysInMonth(value), options?.round);\n break;\n default:\n throw new Error('Unsupported field ' + field);\n }\n\n if (value.calendar.balanceDate) {\n value.calendar.balanceDate(mutable);\n }\n\n constrain(mutable);\n return mutable;\n}\n\nexport function cycleTime(value: CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): CalendarDateTime;\nexport function cycleTime(value: Time, field: TimeField, amount: number, options?: CycleTimeOptions): Time;\nexport function cycleTime(value: Time | CalendarDateTime, field: TimeField, amount: number, options?: CycleTimeOptions): Mutable<Time | CalendarDateTime> {\n let mutable: Mutable<Time | CalendarDateTime> = value.copy();\n\n switch (field) {\n case 'hour': {\n let hours = value.hour;\n let min = 0;\n let max = 23;\n if (options?.hourCycle === 12) {\n let isPM = hours >= 12;\n min = isPM ? 12 : 0;\n max = isPM ? 23 : 11;\n }\n mutable.hour = cycleValue(hours, amount, min, max, options?.round);\n break;\n }\n case 'minute':\n mutable.minute = cycleValue(value.minute, amount, 0, 59, options?.round);\n break;\n case 'second':\n mutable.second = cycleValue(value.second, amount, 0, 59, options?.round);\n break;\n case 'millisecond':\n mutable.millisecond = cycleValue(value.millisecond, amount, 0, 999, options?.round);\n break;\n default:\n throw new Error('Unsupported field ' + field);\n }\n\n return mutable;\n}\n\nfunction cycleValue(value: number, amount: number, min: number, max: number, round = false) {\n if (round) {\n value += Math.sign(amount);\n\n if (value < min) {\n value = max;\n }\n\n let div = Math.abs(amount);\n if (amount > 0) {\n value = Math.ceil(value / div) * div;\n } else {\n value = Math.floor(value / div) * div;\n }\n\n if (value > max) {\n value = min;\n }\n } else {\n value += amount;\n if (value < min) {\n value = max - (min - value - 1);\n } else if (value > max) {\n value = min + (value - max - 1);\n }\n }\n\n return value;\n}\n\nexport function addZoned(dateTime: ZonedDateTime, duration: DateTimeDuration): ZonedDateTime {\n let ms: number;\n if ((duration.years != null && duration.years !== 0) || (duration.months != null && duration.months !== 0) || (duration.weeks != null && duration.weeks !== 0) || (duration.days != null && duration.days !== 0)) {\n let res = add(toCalendarDateTime(dateTime), {\n years: duration.years,\n months: duration.months,\n weeks: duration.weeks,\n days: duration.days\n });\n\n // Changing the date may change the timezone offset, so we need to recompute\n // using the 'compatible' disambiguation.\n ms = toAbsolute(res, dateTime.timeZone);\n } else {\n // Otherwise, preserve the offset of the original date.\n ms = epochFromDate(dateTime) - dateTime.offset;\n }\n\n // Perform time manipulation in milliseconds rather than on the original time fields to account for DST.\n // For example, adding one hour during a DST transition may result in the hour field staying the same or\n // skipping an hour. This results in the offset field changing value instead of the specified field.\n ms += duration.milliseconds || 0;\n ms += (duration.seconds || 0) * 1000;\n ms += (duration.minutes || 0) * 60 * 1000;\n ms += (duration.hours || 0) * 60 * 60 * 1000;\n\n let res = fromAbsolute(ms, dateTime.timeZone);\n return toCalendar(res, dateTime.calendar);\n}\n\nexport function subtractZoned(dateTime: ZonedDateTime, duration: DateTimeDuration): ZonedDateTime {\n return addZoned(dateTime, invertDuration(duration));\n}\n\nexport function cycleZoned(dateTime: ZonedDateTime, field: DateField | TimeField, amount: number, options?: CycleTimeOptions): ZonedDateTime {\n // For date fields, we want the time to remain consistent and the UTC offset to potentially change to account for DST changes.\n // For time fields, we want the time to change by the amount given. This may result in the hour field staying the same, but the UTC\n // offset changing in the case of a backward DST transition, or skipping an hour in the case of a forward DST transition.\n switch (field) {\n case 'hour': {\n let min = 0;\n let max = 23;\n if (options?.hourCycle === 12) {\n let isPM = dateTime.hour >= 12;\n min = isPM ? 12 : 0;\n max = isPM ? 23 : 11;\n }\n\n // The minimum and maximum hour may be affected by daylight saving time.\n // For example, it might jump forward at midnight, and skip 1am.\n // Or it might end at midnight and repeat the 11pm hour. To handle this, we get\n // the possible absolute times for the min and max, and find the maximum range\n // that is within the current day.\n let plainDateTime = toCalendarDateTime(dateTime);\n let minDate = toCalendar(setTime(plainDateTime, {hour: min}), new GregorianCalendar());\n let minAbsolute = [toAbsolute(minDate, dateTime.timeZone, 'earlier'), toAbsolute(minDate, dateTime.timeZone, 'later')]\n .filter(ms => fromAbsolute(ms, dateTime.timeZone).day === minDate.day)[0];\n\n let maxDate = toCalendar(setTime(plainDateTime, {hour: max}), new GregorianCalendar());\n let maxAbsolute = [toAbsolute(maxDate, dateTime.timeZone, 'earlier'), toAbsolute(maxDate, dateTime.timeZone, 'later')]\n .filter(ms => fromAbsolute(ms, dateTime.timeZone).day === maxDate.day).pop()!;\n\n // Since hours may repeat, we need to operate on the absolute time in milliseconds.\n // This is done in hours from the Unix epoch so that cycleValue works correctly,\n // and then converted back to milliseconds.\n let ms = epochFromDate(dateTime) - dateTime.offset;\n let hours = Math.floor(ms / ONE_HOUR);\n let remainder = ms % ONE_HOUR;\n ms = cycleValue(\n hours,\n amount,\n Math.floor(minAbsolute / ONE_HOUR),\n Math.floor(maxAbsolute / ONE_HOUR),\n options?.round\n ) * ONE_HOUR + remainder;\n\n // Now compute the new timezone offset, and convert the absolute time back to local time.\n return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);\n }\n case 'minute':\n case 'second':\n case 'millisecond':\n // @ts-ignore\n return cycleTime(dateTime, field, amount, options);\n case 'era':\n case 'year':\n case 'month':\n case 'day': {\n let res = cycleDate(toCalendarDateTime(dateTime), field, amount, options);\n let ms = toAbsolute(res, dateTime.timeZone);\n return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);\n }\n default:\n throw new Error('Unsupported field ' + field);\n }\n}\n\nexport function setZoned(dateTime: ZonedDateTime, fields: DateFields & TimeFields, disambiguation?: Disambiguation): ZonedDateTime {\n // Set the date/time fields, and recompute the UTC offset to account for DST changes.\n // We also need to validate by converting back to a local time in case hours are skipped during forward DST transitions.\n let plainDateTime = toCalendarDateTime(dateTime);\n let res = setTime(set(plainDateTime, fields), fields);\n\n // If the resulting plain date time values are equal, return the original time.\n // We don't want to change the offset when setting the time to the same value.\n if (res.compare(plainDateTime) === 0) {\n return dateTime;\n }\n\n let ms = toAbsolute(res, dateTime.timeZone, disambiguation);\n return toCalendar(fromAbsolute(ms, dateTime.timeZone), dateTime.calendar);\n}\n"],"names":[],"version":3,"file":"manipulation.cjs.map"}
|