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