@react-stately/datepicker 3.15.3 → 3.16.0

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.
@@ -0,0 +1,330 @@
1
+ import {CalendarDate as $8PHEu$CalendarDate} from "@internationalized/date";
2
+
3
+ /*
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ class $f863c03ccd9aead0$export$ae165b50d181e1ef {
15
+ copy() {
16
+ let res = new $f863c03ccd9aead0$export$ae165b50d181e1ef(this.calendar, this.hourCycle);
17
+ res.era = this.era;
18
+ res.year = this.year;
19
+ res.month = this.month;
20
+ res.day = this.day;
21
+ res.hour = this.hour;
22
+ res.dayPeriod = this.dayPeriod;
23
+ res.minute = this.minute;
24
+ res.second = this.second;
25
+ res.millisecond = this.millisecond;
26
+ res.offset = this.offset;
27
+ return res;
28
+ }
29
+ /** Checks whether all the specified segments have a value. */ isComplete(segments) {
30
+ return segments.every((segment)=>this[segment] != null);
31
+ }
32
+ /** Checks whether the given date value matches this value for the specified segments. */ validate(dt, segments) {
33
+ return segments.every((segment)=>{
34
+ if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {
35
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(dt.hour, this.hourCycle);
36
+ return this.dayPeriod === dayPeriod && this.hour === hour;
37
+ }
38
+ return this[segment] === dt[segment];
39
+ });
40
+ }
41
+ /** Checks if the date is empty (i.e. all specified segments are null). */ isCleared(segments) {
42
+ return segments.every((segment)=>this[segment] === null);
43
+ }
44
+ /** Sets the given field. */ set(field, value, placeholder) {
45
+ let result = this.copy();
46
+ result[field] = value;
47
+ if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) result.dayPeriod = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle)[0];
48
+ if (field === 'year' && result.era == null) result.era = placeholder.era;
49
+ // clear offset when a date/time field changes since it may no longer be valid
50
+ if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') result.offset = null;
51
+ return result;
52
+ }
53
+ /** Sets the given field to null. */ clear(field) {
54
+ let result = this.copy();
55
+ // @ts-ignore
56
+ result[field] = null;
57
+ if (field === 'year') result.era = null;
58
+ // clear offset when a field is cleared since it may no longer be valid
59
+ result.offset = null;
60
+ return result;
61
+ }
62
+ /** Increments or decrements the given field. If it is null, then it is set to the placeholder value. */ cycle(field, amount, placeholder, displaySegments) {
63
+ let res = this.copy();
64
+ // If field is null, default to placeholder.
65
+ if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {
66
+ if (field === 'hour' && 'hour' in placeholder) {
67
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle);
68
+ res.dayPeriod = dayPeriod;
69
+ res.hour = hour;
70
+ } else res[field] = placeholder[field];
71
+ if (field === 'year' && res.era == null) res.era = placeholder.era;
72
+ return res;
73
+ }
74
+ switch(field){
75
+ case 'era':
76
+ {
77
+ let eras = this.calendar.getEras();
78
+ let index = eras.indexOf(res.era);
79
+ index = $f863c03ccd9aead0$var$cycleValue(index, amount, 0, eras.length - 1);
80
+ res.era = eras[index];
81
+ break;
82
+ }
83
+ case 'year':
84
+ {
85
+ var _this_era, _this_year, _this_month, _this_day;
86
+ // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.
87
+ let date = new (0, $8PHEu$CalendarDate)(this.calendar, (_this_era = this.era) !== null && _this_era !== void 0 ? _this_era : placeholder.era, (_this_year = this.year) !== null && _this_year !== void 0 ? _this_year : placeholder.year, (_this_month = this.month) !== null && _this_month !== void 0 ? _this_month : 1, (_this_day = this.day) !== null && _this_day !== void 0 ? _this_day : 1);
88
+ date = date.cycle(field, amount, {
89
+ round: field === 'year'
90
+ });
91
+ res.era = date.era;
92
+ res.year = date.year;
93
+ break;
94
+ }
95
+ case 'month':
96
+ var _res_month;
97
+ res.month = $f863c03ccd9aead0$var$cycleValue((_res_month = res.month) !== null && _res_month !== void 0 ? _res_month : 1, amount, 1, this.calendar.getMaximumMonthsInYear());
98
+ break;
99
+ case 'day':
100
+ var _res_day;
101
+ // Allow incrementing up to the maximum number of days in any month.
102
+ res.day = $f863c03ccd9aead0$var$cycleValue((_res_day = res.day) !== null && _res_day !== void 0 ? _res_day : 1, amount, 1, this.calendar.getMaximumDaysInMonth());
103
+ break;
104
+ case 'hour':
105
+ {
106
+ // if date is fully defined or it is just a time field, and we have a time zone, use toValue to get a ZonedDateTime to cycle
107
+ // so DST fallback is properly handled
108
+ let hasDateSegements = displaySegments.some((s)=>[
109
+ 'year',
110
+ 'month',
111
+ 'day'
112
+ ].includes(s));
113
+ if ('timeZone' in placeholder && (!hasDateSegements || res.year != null && res.month != null && res.day != null)) {
114
+ let date = this.toValue(placeholder);
115
+ date = date.cycle('hour', amount, {
116
+ hourCycle: this.hourCycle === 'h12' ? 12 : 24,
117
+ round: false
118
+ });
119
+ let [dayPeriod, adjustedHour] = $f863c03ccd9aead0$var$toHourCycle(date.hour, this.hourCycle);
120
+ res.hour = adjustedHour;
121
+ res.dayPeriod = dayPeriod;
122
+ res.offset = date.offset;
123
+ } else {
124
+ var _res_hour;
125
+ let hours = (_res_hour = res.hour) !== null && _res_hour !== void 0 ? _res_hour : 0;
126
+ let limits = this.getSegmentLimits('hour');
127
+ res.hour = $f863c03ccd9aead0$var$cycleValue(hours, amount, limits.minValue, limits.maxValue);
128
+ if (res.dayPeriod == null && 'hour' in placeholder) res.dayPeriod = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle)[0];
129
+ }
130
+ break;
131
+ }
132
+ case 'dayPeriod':
133
+ var _res_dayPeriod;
134
+ res.dayPeriod = $f863c03ccd9aead0$var$cycleValue((_res_dayPeriod = res.dayPeriod) !== null && _res_dayPeriod !== void 0 ? _res_dayPeriod : 0, amount, 0, 1);
135
+ break;
136
+ case 'minute':
137
+ var _res_minute;
138
+ res.minute = $f863c03ccd9aead0$var$cycleValue((_res_minute = res.minute) !== null && _res_minute !== void 0 ? _res_minute : 0, amount, 0, 59, true);
139
+ break;
140
+ case 'second':
141
+ var _res_second;
142
+ res.second = $f863c03ccd9aead0$var$cycleValue((_res_second = res.second) !== null && _res_second !== void 0 ? _res_second : 0, amount, 0, 59, true);
143
+ break;
144
+ }
145
+ return res;
146
+ }
147
+ /** Converts the incomplete date to a full date value, using the provided value for any unset fields. */ toValue(value) {
148
+ var _this_era, _this_year, _this_month, _this_day;
149
+ if ('hour' in value) {
150
+ let hour = this.hour;
151
+ var _this_dayPeriod;
152
+ if (hour != null) hour = $f863c03ccd9aead0$var$fromHourCycle(hour, (_this_dayPeriod = this.dayPeriod) !== null && _this_dayPeriod !== void 0 ? _this_dayPeriod : 0, this.hourCycle);
153
+ else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') hour = this.dayPeriod === 1 ? 12 : 0;
154
+ var _this_era1, _this_year1, _this_month1, _this_day1, _this_minute, _this_second, _this_millisecond;
155
+ let res = value.set({
156
+ era: (_this_era1 = this.era) !== null && _this_era1 !== void 0 ? _this_era1 : value.era,
157
+ year: (_this_year1 = this.year) !== null && _this_year1 !== void 0 ? _this_year1 : value.year,
158
+ month: (_this_month1 = this.month) !== null && _this_month1 !== void 0 ? _this_month1 : value.month,
159
+ day: (_this_day1 = this.day) !== null && _this_day1 !== void 0 ? _this_day1 : value.day,
160
+ hour: hour !== null && hour !== void 0 ? hour : value.hour,
161
+ minute: (_this_minute = this.minute) !== null && _this_minute !== void 0 ? _this_minute : value.minute,
162
+ second: (_this_second = this.second) !== null && _this_second !== void 0 ? _this_second : value.second,
163
+ millisecond: (_this_millisecond = this.millisecond) !== null && _this_millisecond !== void 0 ? _this_millisecond : value.millisecond
164
+ });
165
+ if ('offset' in res && this.offset != null && res.offset !== this.offset) res = res.add({
166
+ milliseconds: res.offset - this.offset
167
+ });
168
+ return res;
169
+ } else return value.set({
170
+ era: (_this_era = this.era) !== null && _this_era !== void 0 ? _this_era : value.era,
171
+ year: (_this_year = this.year) !== null && _this_year !== void 0 ? _this_year : value.year,
172
+ month: (_this_month = this.month) !== null && _this_month !== void 0 ? _this_month : value.month,
173
+ day: (_this_day = this.day) !== null && _this_day !== void 0 ? _this_day : value.day
174
+ });
175
+ }
176
+ getSegmentLimits(type) {
177
+ switch(type){
178
+ case 'era':
179
+ {
180
+ let eras = this.calendar.getEras();
181
+ return {
182
+ value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,
183
+ minValue: 0,
184
+ maxValue: eras.length - 1
185
+ };
186
+ }
187
+ case 'year':
188
+ return {
189
+ value: this.year,
190
+ minValue: 1,
191
+ maxValue: 9999
192
+ };
193
+ case 'month':
194
+ return {
195
+ value: this.month,
196
+ minValue: 1,
197
+ maxValue: this.calendar.getMaximumMonthsInYear()
198
+ };
199
+ case 'day':
200
+ return {
201
+ value: this.day,
202
+ minValue: 1,
203
+ maxValue: this.calendar.getMaximumDaysInMonth()
204
+ };
205
+ case 'dayPeriod':
206
+ return {
207
+ value: this.dayPeriod,
208
+ minValue: 0,
209
+ maxValue: 1
210
+ };
211
+ case 'hour':
212
+ {
213
+ let minValue = 0;
214
+ let maxValue = 23;
215
+ if (this.hourCycle === 'h12') {
216
+ minValue = 1;
217
+ maxValue = 12;
218
+ } else if (this.hourCycle === 'h11') {
219
+ minValue = 0;
220
+ maxValue = 11;
221
+ }
222
+ return {
223
+ value: this.hour,
224
+ minValue: minValue,
225
+ maxValue: maxValue
226
+ };
227
+ }
228
+ case 'minute':
229
+ return {
230
+ value: this.minute,
231
+ minValue: 0,
232
+ maxValue: 59
233
+ };
234
+ case 'second':
235
+ return {
236
+ value: this.second,
237
+ minValue: 0,
238
+ maxValue: 59
239
+ };
240
+ }
241
+ }
242
+ constructor(calendar, hourCycle, dateValue){
243
+ var _dateValue_era;
244
+ this.era = (_dateValue_era = dateValue === null || dateValue === void 0 ? void 0 : dateValue.era) !== null && _dateValue_era !== void 0 ? _dateValue_era : null;
245
+ this.calendar = calendar;
246
+ var _dateValue_year;
247
+ this.year = (_dateValue_year = dateValue === null || dateValue === void 0 ? void 0 : dateValue.year) !== null && _dateValue_year !== void 0 ? _dateValue_year : null;
248
+ var _dateValue_month;
249
+ this.month = (_dateValue_month = dateValue === null || dateValue === void 0 ? void 0 : dateValue.month) !== null && _dateValue_month !== void 0 ? _dateValue_month : null;
250
+ var _dateValue_day;
251
+ this.day = (_dateValue_day = dateValue === null || dateValue === void 0 ? void 0 : dateValue.day) !== null && _dateValue_day !== void 0 ? _dateValue_day : null;
252
+ var _dateValue_hour;
253
+ this.hour = (_dateValue_hour = dateValue === null || dateValue === void 0 ? void 0 : dateValue.hour) !== null && _dateValue_hour !== void 0 ? _dateValue_hour : null;
254
+ this.hourCycle = hourCycle;
255
+ this.dayPeriod = null;
256
+ var _dateValue_minute;
257
+ this.minute = (_dateValue_minute = dateValue === null || dateValue === void 0 ? void 0 : dateValue.minute) !== null && _dateValue_minute !== void 0 ? _dateValue_minute : null;
258
+ var _dateValue_second;
259
+ this.second = (_dateValue_second = dateValue === null || dateValue === void 0 ? void 0 : dateValue.second) !== null && _dateValue_second !== void 0 ? _dateValue_second : null;
260
+ var _dateValue_millisecond;
261
+ this.millisecond = (_dateValue_millisecond = dateValue === null || dateValue === void 0 ? void 0 : dateValue.millisecond) !== null && _dateValue_millisecond !== void 0 ? _dateValue_millisecond : null;
262
+ this.offset = 'offset' in (dateValue !== null && dateValue !== void 0 ? dateValue : {}) ? dateValue.offset : null;
263
+ // Convert the hour from 24 hour time to the given hour cycle.
264
+ if (this.hour != null) {
265
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(this.hour, hourCycle);
266
+ this.dayPeriod = dayPeriod;
267
+ this.hour = hour;
268
+ }
269
+ }
270
+ }
271
+ function $f863c03ccd9aead0$var$cycleValue(value, amount, min, max, round = false) {
272
+ if (round) {
273
+ value += Math.sign(amount);
274
+ if (value < min) value = max;
275
+ let div = Math.abs(amount);
276
+ if (amount > 0) value = Math.ceil(value / div) * div;
277
+ else value = Math.floor(value / div) * div;
278
+ if (value > max) value = min;
279
+ } else {
280
+ value += amount;
281
+ if (value < min) value = max - (min - value - 1);
282
+ else if (value > max) value = min + (value - max - 1);
283
+ }
284
+ return value;
285
+ }
286
+ function $f863c03ccd9aead0$var$toHourCycle(hour, hourCycle) {
287
+ let dayPeriod = hour >= 12 ? 1 : 0;
288
+ switch(hourCycle){
289
+ case 'h11':
290
+ // Hours are numbered from 0 to 11. Used in Japan.
291
+ if (hour >= 12) hour -= 12;
292
+ break;
293
+ case 'h12':
294
+ // Hours are numbered from 12 (representing 0) to 11.
295
+ if (hour === 0) hour = 12;
296
+ else if (hour > 12) hour -= 12;
297
+ break;
298
+ case 'h23':
299
+ // 24 hour time, numbered 0 to 23.
300
+ dayPeriod = null;
301
+ break;
302
+ case 'h24':
303
+ // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.
304
+ hour += 1;
305
+ dayPeriod = null;
306
+ }
307
+ return [
308
+ dayPeriod,
309
+ hour
310
+ ];
311
+ }
312
+ function $f863c03ccd9aead0$var$fromHourCycle(hour, dayPeriod, hourCycle) {
313
+ switch(hourCycle){
314
+ case 'h11':
315
+ if (dayPeriod === 1) hour += 12;
316
+ break;
317
+ case 'h12':
318
+ if (hour === 12) hour = 0;
319
+ if (dayPeriod === 1) hour += 12;
320
+ break;
321
+ case 'h24':
322
+ hour -= 1;
323
+ break;
324
+ }
325
+ return hour;
326
+ }
327
+
328
+
329
+ export {$f863c03ccd9aead0$export$ae165b50d181e1ef as IncompleteDate};
330
+ //# sourceMappingURL=IncompleteDate.module.js.map
@@ -0,0 +1,330 @@
1
+ import {CalendarDate as $8PHEu$CalendarDate} from "@internationalized/date";
2
+
3
+ /*
4
+ * Copyright 2026 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+ class $f863c03ccd9aead0$export$ae165b50d181e1ef {
15
+ copy() {
16
+ let res = new $f863c03ccd9aead0$export$ae165b50d181e1ef(this.calendar, this.hourCycle);
17
+ res.era = this.era;
18
+ res.year = this.year;
19
+ res.month = this.month;
20
+ res.day = this.day;
21
+ res.hour = this.hour;
22
+ res.dayPeriod = this.dayPeriod;
23
+ res.minute = this.minute;
24
+ res.second = this.second;
25
+ res.millisecond = this.millisecond;
26
+ res.offset = this.offset;
27
+ return res;
28
+ }
29
+ /** Checks whether all the specified segments have a value. */ isComplete(segments) {
30
+ return segments.every((segment)=>this[segment] != null);
31
+ }
32
+ /** Checks whether the given date value matches this value for the specified segments. */ validate(dt, segments) {
33
+ return segments.every((segment)=>{
34
+ if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {
35
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(dt.hour, this.hourCycle);
36
+ return this.dayPeriod === dayPeriod && this.hour === hour;
37
+ }
38
+ return this[segment] === dt[segment];
39
+ });
40
+ }
41
+ /** Checks if the date is empty (i.e. all specified segments are null). */ isCleared(segments) {
42
+ return segments.every((segment)=>this[segment] === null);
43
+ }
44
+ /** Sets the given field. */ set(field, value, placeholder) {
45
+ let result = this.copy();
46
+ result[field] = value;
47
+ if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) result.dayPeriod = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle)[0];
48
+ if (field === 'year' && result.era == null) result.era = placeholder.era;
49
+ // clear offset when a date/time field changes since it may no longer be valid
50
+ if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') result.offset = null;
51
+ return result;
52
+ }
53
+ /** Sets the given field to null. */ clear(field) {
54
+ let result = this.copy();
55
+ // @ts-ignore
56
+ result[field] = null;
57
+ if (field === 'year') result.era = null;
58
+ // clear offset when a field is cleared since it may no longer be valid
59
+ result.offset = null;
60
+ return result;
61
+ }
62
+ /** Increments or decrements the given field. If it is null, then it is set to the placeholder value. */ cycle(field, amount, placeholder, displaySegments) {
63
+ let res = this.copy();
64
+ // If field is null, default to placeholder.
65
+ if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {
66
+ if (field === 'hour' && 'hour' in placeholder) {
67
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle);
68
+ res.dayPeriod = dayPeriod;
69
+ res.hour = hour;
70
+ } else res[field] = placeholder[field];
71
+ if (field === 'year' && res.era == null) res.era = placeholder.era;
72
+ return res;
73
+ }
74
+ switch(field){
75
+ case 'era':
76
+ {
77
+ let eras = this.calendar.getEras();
78
+ let index = eras.indexOf(res.era);
79
+ index = $f863c03ccd9aead0$var$cycleValue(index, amount, 0, eras.length - 1);
80
+ res.era = eras[index];
81
+ break;
82
+ }
83
+ case 'year':
84
+ {
85
+ var _this_era, _this_year, _this_month, _this_day;
86
+ // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.
87
+ let date = new (0, $8PHEu$CalendarDate)(this.calendar, (_this_era = this.era) !== null && _this_era !== void 0 ? _this_era : placeholder.era, (_this_year = this.year) !== null && _this_year !== void 0 ? _this_year : placeholder.year, (_this_month = this.month) !== null && _this_month !== void 0 ? _this_month : 1, (_this_day = this.day) !== null && _this_day !== void 0 ? _this_day : 1);
88
+ date = date.cycle(field, amount, {
89
+ round: field === 'year'
90
+ });
91
+ res.era = date.era;
92
+ res.year = date.year;
93
+ break;
94
+ }
95
+ case 'month':
96
+ var _res_month;
97
+ res.month = $f863c03ccd9aead0$var$cycleValue((_res_month = res.month) !== null && _res_month !== void 0 ? _res_month : 1, amount, 1, this.calendar.getMaximumMonthsInYear());
98
+ break;
99
+ case 'day':
100
+ var _res_day;
101
+ // Allow incrementing up to the maximum number of days in any month.
102
+ res.day = $f863c03ccd9aead0$var$cycleValue((_res_day = res.day) !== null && _res_day !== void 0 ? _res_day : 1, amount, 1, this.calendar.getMaximumDaysInMonth());
103
+ break;
104
+ case 'hour':
105
+ {
106
+ // if date is fully defined or it is just a time field, and we have a time zone, use toValue to get a ZonedDateTime to cycle
107
+ // so DST fallback is properly handled
108
+ let hasDateSegements = displaySegments.some((s)=>[
109
+ 'year',
110
+ 'month',
111
+ 'day'
112
+ ].includes(s));
113
+ if ('timeZone' in placeholder && (!hasDateSegements || res.year != null && res.month != null && res.day != null)) {
114
+ let date = this.toValue(placeholder);
115
+ date = date.cycle('hour', amount, {
116
+ hourCycle: this.hourCycle === 'h12' ? 12 : 24,
117
+ round: false
118
+ });
119
+ let [dayPeriod, adjustedHour] = $f863c03ccd9aead0$var$toHourCycle(date.hour, this.hourCycle);
120
+ res.hour = adjustedHour;
121
+ res.dayPeriod = dayPeriod;
122
+ res.offset = date.offset;
123
+ } else {
124
+ var _res_hour;
125
+ let hours = (_res_hour = res.hour) !== null && _res_hour !== void 0 ? _res_hour : 0;
126
+ let limits = this.getSegmentLimits('hour');
127
+ res.hour = $f863c03ccd9aead0$var$cycleValue(hours, amount, limits.minValue, limits.maxValue);
128
+ if (res.dayPeriod == null && 'hour' in placeholder) res.dayPeriod = $f863c03ccd9aead0$var$toHourCycle(placeholder.hour, this.hourCycle)[0];
129
+ }
130
+ break;
131
+ }
132
+ case 'dayPeriod':
133
+ var _res_dayPeriod;
134
+ res.dayPeriod = $f863c03ccd9aead0$var$cycleValue((_res_dayPeriod = res.dayPeriod) !== null && _res_dayPeriod !== void 0 ? _res_dayPeriod : 0, amount, 0, 1);
135
+ break;
136
+ case 'minute':
137
+ var _res_minute;
138
+ res.minute = $f863c03ccd9aead0$var$cycleValue((_res_minute = res.minute) !== null && _res_minute !== void 0 ? _res_minute : 0, amount, 0, 59, true);
139
+ break;
140
+ case 'second':
141
+ var _res_second;
142
+ res.second = $f863c03ccd9aead0$var$cycleValue((_res_second = res.second) !== null && _res_second !== void 0 ? _res_second : 0, amount, 0, 59, true);
143
+ break;
144
+ }
145
+ return res;
146
+ }
147
+ /** Converts the incomplete date to a full date value, using the provided value for any unset fields. */ toValue(value) {
148
+ var _this_era, _this_year, _this_month, _this_day;
149
+ if ('hour' in value) {
150
+ let hour = this.hour;
151
+ var _this_dayPeriod;
152
+ if (hour != null) hour = $f863c03ccd9aead0$var$fromHourCycle(hour, (_this_dayPeriod = this.dayPeriod) !== null && _this_dayPeriod !== void 0 ? _this_dayPeriod : 0, this.hourCycle);
153
+ else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') hour = this.dayPeriod === 1 ? 12 : 0;
154
+ var _this_era1, _this_year1, _this_month1, _this_day1, _this_minute, _this_second, _this_millisecond;
155
+ let res = value.set({
156
+ era: (_this_era1 = this.era) !== null && _this_era1 !== void 0 ? _this_era1 : value.era,
157
+ year: (_this_year1 = this.year) !== null && _this_year1 !== void 0 ? _this_year1 : value.year,
158
+ month: (_this_month1 = this.month) !== null && _this_month1 !== void 0 ? _this_month1 : value.month,
159
+ day: (_this_day1 = this.day) !== null && _this_day1 !== void 0 ? _this_day1 : value.day,
160
+ hour: hour !== null && hour !== void 0 ? hour : value.hour,
161
+ minute: (_this_minute = this.minute) !== null && _this_minute !== void 0 ? _this_minute : value.minute,
162
+ second: (_this_second = this.second) !== null && _this_second !== void 0 ? _this_second : value.second,
163
+ millisecond: (_this_millisecond = this.millisecond) !== null && _this_millisecond !== void 0 ? _this_millisecond : value.millisecond
164
+ });
165
+ if ('offset' in res && this.offset != null && res.offset !== this.offset) res = res.add({
166
+ milliseconds: res.offset - this.offset
167
+ });
168
+ return res;
169
+ } else return value.set({
170
+ era: (_this_era = this.era) !== null && _this_era !== void 0 ? _this_era : value.era,
171
+ year: (_this_year = this.year) !== null && _this_year !== void 0 ? _this_year : value.year,
172
+ month: (_this_month = this.month) !== null && _this_month !== void 0 ? _this_month : value.month,
173
+ day: (_this_day = this.day) !== null && _this_day !== void 0 ? _this_day : value.day
174
+ });
175
+ }
176
+ getSegmentLimits(type) {
177
+ switch(type){
178
+ case 'era':
179
+ {
180
+ let eras = this.calendar.getEras();
181
+ return {
182
+ value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,
183
+ minValue: 0,
184
+ maxValue: eras.length - 1
185
+ };
186
+ }
187
+ case 'year':
188
+ return {
189
+ value: this.year,
190
+ minValue: 1,
191
+ maxValue: 9999
192
+ };
193
+ case 'month':
194
+ return {
195
+ value: this.month,
196
+ minValue: 1,
197
+ maxValue: this.calendar.getMaximumMonthsInYear()
198
+ };
199
+ case 'day':
200
+ return {
201
+ value: this.day,
202
+ minValue: 1,
203
+ maxValue: this.calendar.getMaximumDaysInMonth()
204
+ };
205
+ case 'dayPeriod':
206
+ return {
207
+ value: this.dayPeriod,
208
+ minValue: 0,
209
+ maxValue: 1
210
+ };
211
+ case 'hour':
212
+ {
213
+ let minValue = 0;
214
+ let maxValue = 23;
215
+ if (this.hourCycle === 'h12') {
216
+ minValue = 1;
217
+ maxValue = 12;
218
+ } else if (this.hourCycle === 'h11') {
219
+ minValue = 0;
220
+ maxValue = 11;
221
+ }
222
+ return {
223
+ value: this.hour,
224
+ minValue: minValue,
225
+ maxValue: maxValue
226
+ };
227
+ }
228
+ case 'minute':
229
+ return {
230
+ value: this.minute,
231
+ minValue: 0,
232
+ maxValue: 59
233
+ };
234
+ case 'second':
235
+ return {
236
+ value: this.second,
237
+ minValue: 0,
238
+ maxValue: 59
239
+ };
240
+ }
241
+ }
242
+ constructor(calendar, hourCycle, dateValue){
243
+ var _dateValue_era;
244
+ this.era = (_dateValue_era = dateValue === null || dateValue === void 0 ? void 0 : dateValue.era) !== null && _dateValue_era !== void 0 ? _dateValue_era : null;
245
+ this.calendar = calendar;
246
+ var _dateValue_year;
247
+ this.year = (_dateValue_year = dateValue === null || dateValue === void 0 ? void 0 : dateValue.year) !== null && _dateValue_year !== void 0 ? _dateValue_year : null;
248
+ var _dateValue_month;
249
+ this.month = (_dateValue_month = dateValue === null || dateValue === void 0 ? void 0 : dateValue.month) !== null && _dateValue_month !== void 0 ? _dateValue_month : null;
250
+ var _dateValue_day;
251
+ this.day = (_dateValue_day = dateValue === null || dateValue === void 0 ? void 0 : dateValue.day) !== null && _dateValue_day !== void 0 ? _dateValue_day : null;
252
+ var _dateValue_hour;
253
+ this.hour = (_dateValue_hour = dateValue === null || dateValue === void 0 ? void 0 : dateValue.hour) !== null && _dateValue_hour !== void 0 ? _dateValue_hour : null;
254
+ this.hourCycle = hourCycle;
255
+ this.dayPeriod = null;
256
+ var _dateValue_minute;
257
+ this.minute = (_dateValue_minute = dateValue === null || dateValue === void 0 ? void 0 : dateValue.minute) !== null && _dateValue_minute !== void 0 ? _dateValue_minute : null;
258
+ var _dateValue_second;
259
+ this.second = (_dateValue_second = dateValue === null || dateValue === void 0 ? void 0 : dateValue.second) !== null && _dateValue_second !== void 0 ? _dateValue_second : null;
260
+ var _dateValue_millisecond;
261
+ this.millisecond = (_dateValue_millisecond = dateValue === null || dateValue === void 0 ? void 0 : dateValue.millisecond) !== null && _dateValue_millisecond !== void 0 ? _dateValue_millisecond : null;
262
+ this.offset = 'offset' in (dateValue !== null && dateValue !== void 0 ? dateValue : {}) ? dateValue.offset : null;
263
+ // Convert the hour from 24 hour time to the given hour cycle.
264
+ if (this.hour != null) {
265
+ let [dayPeriod, hour] = $f863c03ccd9aead0$var$toHourCycle(this.hour, hourCycle);
266
+ this.dayPeriod = dayPeriod;
267
+ this.hour = hour;
268
+ }
269
+ }
270
+ }
271
+ function $f863c03ccd9aead0$var$cycleValue(value, amount, min, max, round = false) {
272
+ if (round) {
273
+ value += Math.sign(amount);
274
+ if (value < min) value = max;
275
+ let div = Math.abs(amount);
276
+ if (amount > 0) value = Math.ceil(value / div) * div;
277
+ else value = Math.floor(value / div) * div;
278
+ if (value > max) value = min;
279
+ } else {
280
+ value += amount;
281
+ if (value < min) value = max - (min - value - 1);
282
+ else if (value > max) value = min + (value - max - 1);
283
+ }
284
+ return value;
285
+ }
286
+ function $f863c03ccd9aead0$var$toHourCycle(hour, hourCycle) {
287
+ let dayPeriod = hour >= 12 ? 1 : 0;
288
+ switch(hourCycle){
289
+ case 'h11':
290
+ // Hours are numbered from 0 to 11. Used in Japan.
291
+ if (hour >= 12) hour -= 12;
292
+ break;
293
+ case 'h12':
294
+ // Hours are numbered from 12 (representing 0) to 11.
295
+ if (hour === 0) hour = 12;
296
+ else if (hour > 12) hour -= 12;
297
+ break;
298
+ case 'h23':
299
+ // 24 hour time, numbered 0 to 23.
300
+ dayPeriod = null;
301
+ break;
302
+ case 'h24':
303
+ // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.
304
+ hour += 1;
305
+ dayPeriod = null;
306
+ }
307
+ return [
308
+ dayPeriod,
309
+ hour
310
+ ];
311
+ }
312
+ function $f863c03ccd9aead0$var$fromHourCycle(hour, dayPeriod, hourCycle) {
313
+ switch(hourCycle){
314
+ case 'h11':
315
+ if (dayPeriod === 1) hour += 12;
316
+ break;
317
+ case 'h12':
318
+ if (hour === 12) hour = 0;
319
+ if (dayPeriod === 1) hour += 12;
320
+ break;
321
+ case 'h24':
322
+ hour -= 1;
323
+ break;
324
+ }
325
+ return hour;
326
+ }
327
+
328
+
329
+ export {$f863c03ccd9aead0$export$ae165b50d181e1ef as IncompleteDate};
330
+ //# sourceMappingURL=IncompleteDate.module.js.map