@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,5 +1,5 @@
|
|
|
1
|
-
import {epochFromDate as $
|
|
2
|
-
import {GregorianCalendar as $
|
|
1
|
+
import {epochFromDate as $e83297bd1a9e3ddc$export$bd4fb2bc8bb06fb, fromAbsolute as $e83297bd1a9e3ddc$export$1b96692a1ba042ac, toAbsolute as $e83297bd1a9e3ddc$export$5107c82f94518f5c, toCalendar as $e83297bd1a9e3ddc$export$b4a036af3fc0b032, toCalendarDateTime as $e83297bd1a9e3ddc$export$b21e0b124e224484} from "./conversion.js";
|
|
2
|
+
import {GregorianCalendar as $f25df78da1f6b40f$export$80ee6245ec4f29ec} from "./calendars/GregorianCalendar.js";
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -13,19 +13,19 @@ import {GregorianCalendar as $3b62074eb05584b2$export$80ee6245ec4f29ec} from "./
|
|
|
13
13
|
* governing permissions and limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
const $
|
|
17
|
-
function $
|
|
16
|
+
const $13bd2ffe0df4e09c$var$ONE_HOUR = 3600000;
|
|
17
|
+
function $13bd2ffe0df4e09c$export$e16d8520af44a096(date, duration) {
|
|
18
18
|
let mutableDate = date.copy();
|
|
19
|
-
let days = 'hour' in mutableDate ? $
|
|
20
|
-
$
|
|
19
|
+
let days = 'hour' in mutableDate ? $13bd2ffe0df4e09c$var$addTimeFields(mutableDate, duration) : 0;
|
|
20
|
+
$13bd2ffe0df4e09c$var$addYears(mutableDate, duration.years || 0);
|
|
21
21
|
if (mutableDate.calendar.balanceYearMonth) mutableDate.calendar.balanceYearMonth(mutableDate, date);
|
|
22
22
|
mutableDate.month += duration.months || 0;
|
|
23
|
-
$
|
|
24
|
-
$
|
|
23
|
+
$13bd2ffe0df4e09c$var$balanceYearMonth(mutableDate);
|
|
24
|
+
$13bd2ffe0df4e09c$var$constrainMonthDay(mutableDate);
|
|
25
25
|
mutableDate.day += (duration.weeks || 0) * 7;
|
|
26
26
|
mutableDate.day += duration.days || 0;
|
|
27
27
|
mutableDate.day += days;
|
|
28
|
-
$
|
|
28
|
+
$13bd2ffe0df4e09c$var$balanceDay(mutableDate);
|
|
29
29
|
if (mutableDate.calendar.balanceDate) mutableDate.calendar.balanceDate(mutableDate);
|
|
30
30
|
// Constrain in case adding ended up with a date outside the valid range for the calendar system.
|
|
31
31
|
// The behavior here is slightly different than when constraining in the `set` function in that
|
|
@@ -56,107 +56,107 @@ function $735220c2d4774dd3$export$e16d8520af44a096(date, duration) {
|
|
|
56
56
|
mutableDate.day = Math.max(1, Math.min(mutableDate.calendar.getDaysInMonth(mutableDate), mutableDate.day));
|
|
57
57
|
return mutableDate;
|
|
58
58
|
}
|
|
59
|
-
function $
|
|
59
|
+
function $13bd2ffe0df4e09c$var$addYears(date, years) {
|
|
60
60
|
var _date_calendar_isInverseEra, _date_calendar;
|
|
61
61
|
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;
|
|
62
62
|
date.year += years;
|
|
63
63
|
}
|
|
64
|
-
function $
|
|
64
|
+
function $13bd2ffe0df4e09c$var$balanceYearMonth(date) {
|
|
65
65
|
while(date.month < 1){
|
|
66
|
-
$
|
|
66
|
+
$13bd2ffe0df4e09c$var$addYears(date, -1);
|
|
67
67
|
date.month += date.calendar.getMonthsInYear(date);
|
|
68
68
|
}
|
|
69
69
|
let monthsInYear = 0;
|
|
70
70
|
while(date.month > (monthsInYear = date.calendar.getMonthsInYear(date))){
|
|
71
71
|
date.month -= monthsInYear;
|
|
72
|
-
$
|
|
72
|
+
$13bd2ffe0df4e09c$var$addYears(date, 1);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function $
|
|
75
|
+
function $13bd2ffe0df4e09c$var$balanceDay(date) {
|
|
76
76
|
while(date.day < 1){
|
|
77
77
|
date.month--;
|
|
78
|
-
$
|
|
78
|
+
$13bd2ffe0df4e09c$var$balanceYearMonth(date);
|
|
79
79
|
date.day += date.calendar.getDaysInMonth(date);
|
|
80
80
|
}
|
|
81
81
|
while(date.day > date.calendar.getDaysInMonth(date)){
|
|
82
82
|
date.day -= date.calendar.getDaysInMonth(date);
|
|
83
83
|
date.month++;
|
|
84
|
-
$
|
|
84
|
+
$13bd2ffe0df4e09c$var$balanceYearMonth(date);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
function $
|
|
87
|
+
function $13bd2ffe0df4e09c$var$constrainMonthDay(date) {
|
|
88
88
|
date.month = Math.max(1, Math.min(date.calendar.getMonthsInYear(date), date.month));
|
|
89
89
|
date.day = Math.max(1, Math.min(date.calendar.getDaysInMonth(date), date.day));
|
|
90
90
|
}
|
|
91
|
-
function $
|
|
91
|
+
function $13bd2ffe0df4e09c$export$c4e2ecac49351ef2(date) {
|
|
92
92
|
if (date.calendar.constrainDate) date.calendar.constrainDate(date);
|
|
93
93
|
date.year = Math.max(1, Math.min(date.calendar.getYearsInEra(date), date.year));
|
|
94
|
-
$
|
|
94
|
+
$13bd2ffe0df4e09c$var$constrainMonthDay(date);
|
|
95
95
|
}
|
|
96
|
-
function $
|
|
96
|
+
function $13bd2ffe0df4e09c$export$3e2544e88a25bff8(duration) {
|
|
97
97
|
let inverseDuration = {};
|
|
98
98
|
for(let key in duration)if (typeof duration[key] === 'number') inverseDuration[key] = -duration[key];
|
|
99
99
|
return inverseDuration;
|
|
100
100
|
}
|
|
101
|
-
function $
|
|
102
|
-
return $
|
|
101
|
+
function $13bd2ffe0df4e09c$export$4e2d2ead65e5f7e3(date, duration) {
|
|
102
|
+
return $13bd2ffe0df4e09c$export$e16d8520af44a096(date, $13bd2ffe0df4e09c$export$3e2544e88a25bff8(duration));
|
|
103
103
|
}
|
|
104
|
-
function $
|
|
104
|
+
function $13bd2ffe0df4e09c$export$adaa4cf7ef1b65be(date, fields) {
|
|
105
105
|
let mutableDate = date.copy();
|
|
106
106
|
if (fields.era != null) mutableDate.era = fields.era;
|
|
107
107
|
if (fields.year != null) mutableDate.year = fields.year;
|
|
108
108
|
if (fields.month != null) mutableDate.month = fields.month;
|
|
109
109
|
if (fields.day != null) mutableDate.day = fields.day;
|
|
110
|
-
$
|
|
110
|
+
$13bd2ffe0df4e09c$export$c4e2ecac49351ef2(mutableDate);
|
|
111
111
|
return mutableDate;
|
|
112
112
|
}
|
|
113
|
-
function $
|
|
113
|
+
function $13bd2ffe0df4e09c$export$e5d5e1c1822b6e56(value, fields) {
|
|
114
114
|
let mutableValue = value.copy();
|
|
115
115
|
if (fields.hour != null) mutableValue.hour = fields.hour;
|
|
116
116
|
if (fields.minute != null) mutableValue.minute = fields.minute;
|
|
117
117
|
if (fields.second != null) mutableValue.second = fields.second;
|
|
118
118
|
if (fields.millisecond != null) mutableValue.millisecond = fields.millisecond;
|
|
119
|
-
$
|
|
119
|
+
$13bd2ffe0df4e09c$export$7555de1e070510cb(mutableValue);
|
|
120
120
|
return mutableValue;
|
|
121
121
|
}
|
|
122
|
-
function $
|
|
122
|
+
function $13bd2ffe0df4e09c$var$balanceTime(time) {
|
|
123
123
|
time.second += Math.floor(time.millisecond / 1000);
|
|
124
|
-
time.millisecond = $
|
|
124
|
+
time.millisecond = $13bd2ffe0df4e09c$var$nonNegativeMod(time.millisecond, 1000);
|
|
125
125
|
time.minute += Math.floor(time.second / 60);
|
|
126
|
-
time.second = $
|
|
126
|
+
time.second = $13bd2ffe0df4e09c$var$nonNegativeMod(time.second, 60);
|
|
127
127
|
time.hour += Math.floor(time.minute / 60);
|
|
128
|
-
time.minute = $
|
|
128
|
+
time.minute = $13bd2ffe0df4e09c$var$nonNegativeMod(time.minute, 60);
|
|
129
129
|
let days = Math.floor(time.hour / 24);
|
|
130
|
-
time.hour = $
|
|
130
|
+
time.hour = $13bd2ffe0df4e09c$var$nonNegativeMod(time.hour, 24);
|
|
131
131
|
return days;
|
|
132
132
|
}
|
|
133
|
-
function $
|
|
133
|
+
function $13bd2ffe0df4e09c$export$7555de1e070510cb(time) {
|
|
134
134
|
time.millisecond = Math.max(0, Math.min(time.millisecond, 1000));
|
|
135
135
|
time.second = Math.max(0, Math.min(time.second, 59));
|
|
136
136
|
time.minute = Math.max(0, Math.min(time.minute, 59));
|
|
137
137
|
time.hour = Math.max(0, Math.min(time.hour, 23));
|
|
138
138
|
}
|
|
139
|
-
function $
|
|
139
|
+
function $13bd2ffe0df4e09c$var$nonNegativeMod(a, b) {
|
|
140
140
|
let result = a % b;
|
|
141
141
|
if (result < 0) result += b;
|
|
142
142
|
return result;
|
|
143
143
|
}
|
|
144
|
-
function $
|
|
144
|
+
function $13bd2ffe0df4e09c$var$addTimeFields(time, duration) {
|
|
145
145
|
time.hour += duration.hours || 0;
|
|
146
146
|
time.minute += duration.minutes || 0;
|
|
147
147
|
time.second += duration.seconds || 0;
|
|
148
148
|
time.millisecond += duration.milliseconds || 0;
|
|
149
|
-
return $
|
|
149
|
+
return $13bd2ffe0df4e09c$var$balanceTime(time);
|
|
150
150
|
}
|
|
151
|
-
function $
|
|
151
|
+
function $13bd2ffe0df4e09c$export$7ed87b6bc2506470(time, duration) {
|
|
152
152
|
let res = time.copy();
|
|
153
|
-
$
|
|
153
|
+
$13bd2ffe0df4e09c$var$addTimeFields(res, duration);
|
|
154
154
|
return res;
|
|
155
155
|
}
|
|
156
|
-
function $
|
|
157
|
-
return $
|
|
156
|
+
function $13bd2ffe0df4e09c$export$fe34d3a381cd7501(time, duration) {
|
|
157
|
+
return $13bd2ffe0df4e09c$export$7ed87b6bc2506470(time, $13bd2ffe0df4e09c$export$3e2544e88a25bff8(duration));
|
|
158
158
|
}
|
|
159
|
-
function $
|
|
159
|
+
function $13bd2ffe0df4e09c$export$d52ced6badfb9a4c(value, field, amount, options) {
|
|
160
160
|
let mutable = value.copy();
|
|
161
161
|
switch(field){
|
|
162
162
|
case 'era':
|
|
@@ -164,10 +164,10 @@ function $735220c2d4774dd3$export$d52ced6badfb9a4c(value, field, amount, options
|
|
|
164
164
|
let eras = value.calendar.getEras();
|
|
165
165
|
let eraIndex = eras.indexOf(value.era);
|
|
166
166
|
if (eraIndex < 0) throw new Error('Invalid era: ' + value.era);
|
|
167
|
-
eraIndex = $
|
|
167
|
+
eraIndex = $13bd2ffe0df4e09c$var$cycleValue(eraIndex, amount, 0, eras.length - 1, options === null || options === void 0 ? void 0 : options.round);
|
|
168
168
|
mutable.era = eras[eraIndex];
|
|
169
169
|
// Constrain the year and other fields within the era, so the era doesn't change when we balance below.
|
|
170
|
-
$
|
|
170
|
+
$13bd2ffe0df4e09c$export$c4e2ecac49351ef2(mutable);
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
case 'year':
|
|
@@ -176,24 +176,24 @@ function $735220c2d4774dd3$export$d52ced6badfb9a4c(value, field, amount, options
|
|
|
176
176
|
// The year field should not cycle within the era as that can cause weird behavior affecting other fields.
|
|
177
177
|
// We need to also allow values < 1 so that decrementing goes to the previous era. If we get -Infinity back
|
|
178
178
|
// we know we wrapped around after reaching 9999 (the maximum), so set the year back to 1.
|
|
179
|
-
mutable.year = $
|
|
179
|
+
mutable.year = $13bd2ffe0df4e09c$var$cycleValue(value.year, amount, -Infinity, 9999, options === null || options === void 0 ? void 0 : options.round);
|
|
180
180
|
if (mutable.year === -Infinity) mutable.year = 1;
|
|
181
181
|
if (mutable.calendar.balanceYearMonth) mutable.calendar.balanceYearMonth(mutable, value);
|
|
182
182
|
break;
|
|
183
183
|
case 'month':
|
|
184
|
-
mutable.month = $
|
|
184
|
+
mutable.month = $13bd2ffe0df4e09c$var$cycleValue(value.month, amount, 1, value.calendar.getMonthsInYear(value), options === null || options === void 0 ? void 0 : options.round);
|
|
185
185
|
break;
|
|
186
186
|
case 'day':
|
|
187
|
-
mutable.day = $
|
|
187
|
+
mutable.day = $13bd2ffe0df4e09c$var$cycleValue(value.day, amount, 1, value.calendar.getDaysInMonth(value), options === null || options === void 0 ? void 0 : options.round);
|
|
188
188
|
break;
|
|
189
189
|
default:
|
|
190
190
|
throw new Error('Unsupported field ' + field);
|
|
191
191
|
}
|
|
192
192
|
if (value.calendar.balanceDate) value.calendar.balanceDate(mutable);
|
|
193
|
-
$
|
|
193
|
+
$13bd2ffe0df4e09c$export$c4e2ecac49351ef2(mutable);
|
|
194
194
|
return mutable;
|
|
195
195
|
}
|
|
196
|
-
function $
|
|
196
|
+
function $13bd2ffe0df4e09c$export$dd02b3e0007dfe28(value, field, amount, options) {
|
|
197
197
|
let mutable = value.copy();
|
|
198
198
|
switch(field){
|
|
199
199
|
case 'hour':
|
|
@@ -206,24 +206,24 @@ function $735220c2d4774dd3$export$dd02b3e0007dfe28(value, field, amount, options
|
|
|
206
206
|
min = isPM ? 12 : 0;
|
|
207
207
|
max = isPM ? 23 : 11;
|
|
208
208
|
}
|
|
209
|
-
mutable.hour = $
|
|
209
|
+
mutable.hour = $13bd2ffe0df4e09c$var$cycleValue(hours, amount, min, max, options === null || options === void 0 ? void 0 : options.round);
|
|
210
210
|
break;
|
|
211
211
|
}
|
|
212
212
|
case 'minute':
|
|
213
|
-
mutable.minute = $
|
|
213
|
+
mutable.minute = $13bd2ffe0df4e09c$var$cycleValue(value.minute, amount, 0, 59, options === null || options === void 0 ? void 0 : options.round);
|
|
214
214
|
break;
|
|
215
215
|
case 'second':
|
|
216
|
-
mutable.second = $
|
|
216
|
+
mutable.second = $13bd2ffe0df4e09c$var$cycleValue(value.second, amount, 0, 59, options === null || options === void 0 ? void 0 : options.round);
|
|
217
217
|
break;
|
|
218
218
|
case 'millisecond':
|
|
219
|
-
mutable.millisecond = $
|
|
219
|
+
mutable.millisecond = $13bd2ffe0df4e09c$var$cycleValue(value.millisecond, amount, 0, 999, options === null || options === void 0 ? void 0 : options.round);
|
|
220
220
|
break;
|
|
221
221
|
default:
|
|
222
222
|
throw new Error('Unsupported field ' + field);
|
|
223
223
|
}
|
|
224
224
|
return mutable;
|
|
225
225
|
}
|
|
226
|
-
function $
|
|
226
|
+
function $13bd2ffe0df4e09c$var$cycleValue(value, amount, min, max, round = false) {
|
|
227
227
|
if (round) {
|
|
228
228
|
value += Math.sign(amount);
|
|
229
229
|
if (value < min) value = max;
|
|
@@ -238,10 +238,10 @@ function $735220c2d4774dd3$var$cycleValue(value, amount, min, max, round = false
|
|
|
238
238
|
}
|
|
239
239
|
return value;
|
|
240
240
|
}
|
|
241
|
-
function $
|
|
241
|
+
function $13bd2ffe0df4e09c$export$96b1d28349274637(dateTime, duration) {
|
|
242
242
|
let ms;
|
|
243
243
|
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) {
|
|
244
|
-
let res = $
|
|
244
|
+
let res = $13bd2ffe0df4e09c$export$e16d8520af44a096((0, $e83297bd1a9e3ddc$export$b21e0b124e224484)(dateTime), {
|
|
245
245
|
years: duration.years,
|
|
246
246
|
months: duration.months,
|
|
247
247
|
weeks: duration.weeks,
|
|
@@ -249,9 +249,9 @@ function $735220c2d4774dd3$export$96b1d28349274637(dateTime, duration) {
|
|
|
249
249
|
});
|
|
250
250
|
// Changing the date may change the timezone offset, so we need to recompute
|
|
251
251
|
// using the 'compatible' disambiguation.
|
|
252
|
-
ms = (0, $
|
|
252
|
+
ms = (0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(res, dateTime.timeZone);
|
|
253
253
|
} else // Otherwise, preserve the offset of the original date.
|
|
254
|
-
ms = (0, $
|
|
254
|
+
ms = (0, $e83297bd1a9e3ddc$export$bd4fb2bc8bb06fb)(dateTime) - dateTime.offset;
|
|
255
255
|
// Perform time manipulation in milliseconds rather than on the original time fields to account for DST.
|
|
256
256
|
// For example, adding one hour during a DST transition may result in the hour field staying the same or
|
|
257
257
|
// skipping an hour. This results in the offset field changing value instead of the specified field.
|
|
@@ -259,13 +259,13 @@ function $735220c2d4774dd3$export$96b1d28349274637(dateTime, duration) {
|
|
|
259
259
|
ms += (duration.seconds || 0) * 1000;
|
|
260
260
|
ms += (duration.minutes || 0) * 60000;
|
|
261
261
|
ms += (duration.hours || 0) * 3600000;
|
|
262
|
-
let res = (0, $
|
|
263
|
-
return (0, $
|
|
262
|
+
let res = (0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone);
|
|
263
|
+
return (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)(res, dateTime.calendar);
|
|
264
264
|
}
|
|
265
|
-
function $
|
|
266
|
-
return $
|
|
265
|
+
function $13bd2ffe0df4e09c$export$6814caac34ca03c7(dateTime, duration) {
|
|
266
|
+
return $13bd2ffe0df4e09c$export$96b1d28349274637(dateTime, $13bd2ffe0df4e09c$export$3e2544e88a25bff8(duration));
|
|
267
267
|
}
|
|
268
|
-
function $
|
|
268
|
+
function $13bd2ffe0df4e09c$export$9a297d111fc86b79(dateTime, field, amount, options) {
|
|
269
269
|
// For date fields, we want the time to remain consistent and the UTC offset to potentially change to account for DST changes.
|
|
270
270
|
// 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
|
|
271
271
|
// offset changing in the case of a backward DST transition, or skipping an hour in the case of a forward DST transition.
|
|
@@ -284,61 +284,61 @@ function $735220c2d4774dd3$export$9a297d111fc86b79(dateTime, field, amount, opti
|
|
|
284
284
|
// Or it might end at midnight and repeat the 11pm hour. To handle this, we get
|
|
285
285
|
// the possible absolute times for the min and max, and find the maximum range
|
|
286
286
|
// that is within the current day.
|
|
287
|
-
let plainDateTime = (0, $
|
|
288
|
-
let minDate = (0, $
|
|
287
|
+
let plainDateTime = (0, $e83297bd1a9e3ddc$export$b21e0b124e224484)(dateTime);
|
|
288
|
+
let minDate = (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)($13bd2ffe0df4e09c$export$e5d5e1c1822b6e56(plainDateTime, {
|
|
289
289
|
hour: min
|
|
290
|
-
}), new (0, $
|
|
290
|
+
}), new (0, $f25df78da1f6b40f$export$80ee6245ec4f29ec)());
|
|
291
291
|
let minAbsolute = [
|
|
292
|
-
(0, $
|
|
293
|
-
(0, $
|
|
294
|
-
].filter((ms)=>(0, $
|
|
295
|
-
let maxDate = (0, $
|
|
292
|
+
(0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(minDate, dateTime.timeZone, 'earlier'),
|
|
293
|
+
(0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(minDate, dateTime.timeZone, 'later')
|
|
294
|
+
].filter((ms)=>(0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone).day === minDate.day)[0];
|
|
295
|
+
let maxDate = (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)($13bd2ffe0df4e09c$export$e5d5e1c1822b6e56(plainDateTime, {
|
|
296
296
|
hour: max
|
|
297
|
-
}), new (0, $
|
|
297
|
+
}), new (0, $f25df78da1f6b40f$export$80ee6245ec4f29ec)());
|
|
298
298
|
let maxAbsolute = [
|
|
299
|
-
(0, $
|
|
300
|
-
(0, $
|
|
301
|
-
].filter((ms)=>(0, $
|
|
299
|
+
(0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(maxDate, dateTime.timeZone, 'earlier'),
|
|
300
|
+
(0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(maxDate, dateTime.timeZone, 'later')
|
|
301
|
+
].filter((ms)=>(0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone).day === maxDate.day).pop();
|
|
302
302
|
// Since hours may repeat, we need to operate on the absolute time in milliseconds.
|
|
303
303
|
// This is done in hours from the Unix epoch so that cycleValue works correctly,
|
|
304
304
|
// and then converted back to milliseconds.
|
|
305
|
-
let ms = (0, $
|
|
306
|
-
let hours = Math.floor(ms / $
|
|
307
|
-
let remainder = ms % $
|
|
308
|
-
ms = $
|
|
305
|
+
let ms = (0, $e83297bd1a9e3ddc$export$bd4fb2bc8bb06fb)(dateTime) - dateTime.offset;
|
|
306
|
+
let hours = Math.floor(ms / $13bd2ffe0df4e09c$var$ONE_HOUR);
|
|
307
|
+
let remainder = ms % $13bd2ffe0df4e09c$var$ONE_HOUR;
|
|
308
|
+
ms = $13bd2ffe0df4e09c$var$cycleValue(hours, amount, Math.floor(minAbsolute / $13bd2ffe0df4e09c$var$ONE_HOUR), Math.floor(maxAbsolute / $13bd2ffe0df4e09c$var$ONE_HOUR), options === null || options === void 0 ? void 0 : options.round) * $13bd2ffe0df4e09c$var$ONE_HOUR + remainder;
|
|
309
309
|
// Now compute the new timezone offset, and convert the absolute time back to local time.
|
|
310
|
-
return (0, $
|
|
310
|
+
return (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)((0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone), dateTime.calendar);
|
|
311
311
|
}
|
|
312
312
|
case 'minute':
|
|
313
313
|
case 'second':
|
|
314
314
|
case 'millisecond':
|
|
315
315
|
// @ts-ignore
|
|
316
|
-
return $
|
|
316
|
+
return $13bd2ffe0df4e09c$export$dd02b3e0007dfe28(dateTime, field, amount, options);
|
|
317
317
|
case 'era':
|
|
318
318
|
case 'year':
|
|
319
319
|
case 'month':
|
|
320
320
|
case 'day':
|
|
321
321
|
{
|
|
322
|
-
let res = $
|
|
323
|
-
let ms = (0, $
|
|
324
|
-
return (0, $
|
|
322
|
+
let res = $13bd2ffe0df4e09c$export$d52ced6badfb9a4c((0, $e83297bd1a9e3ddc$export$b21e0b124e224484)(dateTime), field, amount, options);
|
|
323
|
+
let ms = (0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(res, dateTime.timeZone);
|
|
324
|
+
return (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)((0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone), dateTime.calendar);
|
|
325
325
|
}
|
|
326
326
|
default:
|
|
327
327
|
throw new Error('Unsupported field ' + field);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
function $
|
|
330
|
+
function $13bd2ffe0df4e09c$export$31b5430eb18be4f8(dateTime, fields, disambiguation) {
|
|
331
331
|
// Set the date/time fields, and recompute the UTC offset to account for DST changes.
|
|
332
332
|
// We also need to validate by converting back to a local time in case hours are skipped during forward DST transitions.
|
|
333
|
-
let plainDateTime = (0, $
|
|
334
|
-
let res = $
|
|
333
|
+
let plainDateTime = (0, $e83297bd1a9e3ddc$export$b21e0b124e224484)(dateTime);
|
|
334
|
+
let res = $13bd2ffe0df4e09c$export$e5d5e1c1822b6e56($13bd2ffe0df4e09c$export$adaa4cf7ef1b65be(plainDateTime, fields), fields);
|
|
335
335
|
// If the resulting plain date time values are equal, return the original time.
|
|
336
336
|
// We don't want to change the offset when setting the time to the same value.
|
|
337
337
|
if (res.compare(plainDateTime) === 0) return dateTime;
|
|
338
|
-
let ms = (0, $
|
|
339
|
-
return (0, $
|
|
338
|
+
let ms = (0, $e83297bd1a9e3ddc$export$5107c82f94518f5c)(res, dateTime.timeZone, disambiguation);
|
|
339
|
+
return (0, $e83297bd1a9e3ddc$export$b4a036af3fc0b032)((0, $e83297bd1a9e3ddc$export$1b96692a1ba042ac)(ms, dateTime.timeZone), dateTime.calendar);
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
|
|
343
|
-
export {$
|
|
344
|
-
//# sourceMappingURL=manipulation.
|
|
343
|
+
export {$13bd2ffe0df4e09c$export$e16d8520af44a096 as add, $13bd2ffe0df4e09c$export$c4e2ecac49351ef2 as constrain, $13bd2ffe0df4e09c$export$3e2544e88a25bff8 as invertDuration, $13bd2ffe0df4e09c$export$4e2d2ead65e5f7e3 as subtract, $13bd2ffe0df4e09c$export$adaa4cf7ef1b65be as set, $13bd2ffe0df4e09c$export$e5d5e1c1822b6e56 as setTime, $13bd2ffe0df4e09c$export$7555de1e070510cb as constrainTime, $13bd2ffe0df4e09c$export$7ed87b6bc2506470 as addTime, $13bd2ffe0df4e09c$export$fe34d3a381cd7501 as subtractTime, $13bd2ffe0df4e09c$export$d52ced6badfb9a4c as cycleDate, $13bd2ffe0df4e09c$export$dd02b3e0007dfe28 as cycleTime, $13bd2ffe0df4e09c$export$96b1d28349274637 as addZoned, $13bd2ffe0df4e09c$export$6814caac34ca03c7 as subtractZoned, $13bd2ffe0df4e09c$export$9a297d111fc86b79 as cycleZoned, $13bd2ffe0df4e09c$export$31b5430eb18be4f8 as setZoned};
|
|
344
|
+
//# sourceMappingURL=manipulation.js.map
|
|
@@ -1 +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;IACj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OAAO,QAAQ;QAC5C,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;YAAO;gBACV,IAAI,MAAM,0CAAU,CAAA,GAAA,yCAAiB,EAAE,WAAW,OAAO,QAAQ;gBACjE,IAAI,KAAK,CAAA,GAAA,yCAAS,EAAE,KAAK,SAAS,QAAQ;gBAC1C,OAAO,CAAA,GAAA,yCAAS,EAAE,CAAA,GAAA,yCAAW,EAAE,IAAI,SAAS,QAAQ,GAAG,SAAS,QAAQ;YAC1E;QACA;YACE,MAAM,IAAI,MAAM,uBAAuB;IAC3C;AACF;AAEO,SAAS,0CAAS,QAAuB,EAAE,MAA+B,EAAE,cAA+B;IAChH,qFAAqF;IACrF,wHAAwH;IACxH,IAAI,gBAAgB,CAAA,GAAA,yCAAiB,EAAE;IACvC,IAAI,MAAM,0CAAQ,0CAAI,eAAe,SAAS;IAE9C,+EAA+E;IAC/E,8EAA8E;IAC9E,IAAI,IAAI,OAAO,CAAC,mBAAmB,GACjC,OAAO;IAGT,IAAI,KAAK,CAAA,GAAA,yCAAS,EAAE,KAAK,SAAS,QAAQ,EAAE;IAC5C,OAAO,CAAA,GAAA,yCAAS,EAAE,CAAA,GAAA,yCAAW,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.module.js.map"}
|
|
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;YACX,oCAAA;QAAnB,IAAI,gBAAe,qCAAA,CAAA,wBAAA,YAAY,QAAQ,EAAC,YAAY,cAAjC,yDAAA,wCAAA,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Q;gBACjE,IAAI,KAAK,CAAA,GAAA,yCAAS,EAAE,KAAK,SAAS,QAAQ;gBAC1C,OAAO,CAAA,GAAA,yCAAS,EAAE,CAAA,GAAA,yCAAW,EAAE,IAAI,SAAS,QAAQ,GAAG,SAAS,QAAQ;YAC1E;QACA;YACE,MAAM,IAAI,MAAM,uBAAuB;IAC3C;AACF;AAEO,SAAS,0CAAS,QAAuB,EAAE,MAA+B,EAAE,cAA+B;IAChH,qFAAqF;IACrF,wHAAwH;IACxH,IAAI,gBAAgB,CAAA,GAAA,yCAAiB,EAAE;IACvC,IAAI,MAAM,0CAAQ,0CAAI,eAAe,SAAS;IAE9C,+EAA+E;IAC/E,8EAA8E;IAC9E,IAAI,IAAI,OAAO,CAAC,mBAAmB,GACjC,OAAO;IAGT,IAAI,KAAK,CAAA,GAAA,yCAAS,EAAE,KAAK,SAAS,QAAQ,EAAE;IAC5C,OAAO,CAAA,GAAA,yCAAS,EAAE,CAAA,GAAA,yCAAW,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.js.map"}
|