@react-stately/datepicker 3.15.2 → 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.
@@ -1,7 +1,9 @@
1
1
  var $50d5d6a623389320$exports = require("./utils.main.js");
2
2
  var $e1e8ada727fae1a1$exports = require("./placeholders.main.js");
3
+ var $fd62790d5a95383f$exports = require("./IncompleteDate.main.js");
3
4
  var $iqS8N$internationalizeddate = require("@internationalized/date");
4
5
  var $iqS8N$reactstatelyform = require("@react-stately/form");
6
+ var $iqS8N$internationalizednumber = require("@internationalized/number");
5
7
  var $iqS8N$reactstatelyutils = require("@react-stately/utils");
6
8
  var $iqS8N$react = require("react");
7
9
 
@@ -27,6 +29,8 @@ $parcel$export(module.exports, "useDateFieldState", () => $596a1f0f523d6752$expo
27
29
 
28
30
 
29
31
 
32
+
33
+
30
34
  const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
31
35
  year: true,
32
36
  month: true,
@@ -60,12 +64,23 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
60
64
  let timeZone = defaultTimeZone || 'UTC';
61
65
  // props.granularity must actually exist in the value if one is provided.
62
66
  if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
63
- let defaultFormatter = (0, $iqS8N$react.useMemo)(()=>new (0, $iqS8N$internationalizeddate.DateFormatter)(locale), [
64
- locale
65
- ]);
66
- let calendar = (0, $iqS8N$react.useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
67
- createCalendar,
68
- defaultFormatter
67
+ // Resolve default hour cycle and calendar system.
68
+ let [calendar, hourCycle] = (0, $iqS8N$react.useMemo)(()=>{
69
+ let formatter = new (0, $iqS8N$internationalizeddate.DateFormatter)(locale, {
70
+ dateStyle: 'short',
71
+ timeStyle: 'short',
72
+ hour12: props.hourCycle != null ? props.hourCycle === 12 : undefined
73
+ });
74
+ let opts = formatter.resolvedOptions();
75
+ let calendar = createCalendar(opts.calendar);
76
+ return [
77
+ calendar,
78
+ opts.hourCycle
79
+ ];
80
+ }, [
81
+ locale,
82
+ props.hourCycle,
83
+ createCalendar
69
84
  ]);
70
85
  var _props_defaultValue;
71
86
  let [value, setDate] = (0, $iqS8N$reactstatelyutils.useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
@@ -77,13 +92,8 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
77
92
  value,
78
93
  calendar
79
94
  ]);
80
- // We keep track of the placeholder date separately in state so that onChange is not called
81
- // until all segments are set. If the value === null (not undefined), then assume the component
82
- // is controlled, so use the placeholder as the value until all segments are entered so it doesn't
83
- // change from uncontrolled to controlled and emit a warning.
84
- let [placeholderDate, setPlaceholderDate] = (0, $iqS8N$react.useState)(()=>(0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
85
- let val = calendarValue || placeholderDate;
86
- let showEra = calendar.identifier === 'gregory' && val.era === 'BC';
95
+ let [displayValue, setDisplayValue] = (0, $iqS8N$react.useState)(()=>new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue));
96
+ let showEra = calendar.identifier === 'gregory' && displayValue.era === 'BC';
87
97
  let formatOpts = (0, $iqS8N$react.useMemo)(()=>{
88
98
  var _props_maxGranularity;
89
99
  return {
@@ -114,76 +124,85 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
114
124
  let resolvedOptions = (0, $iqS8N$react.useMemo)(()=>dateFormatter.resolvedOptions(), [
115
125
  dateFormatter
116
126
  ]);
117
- // Determine how many editable segments there are for validation purposes.
118
- // The result is cached for performance.
119
- let allSegments = (0, $iqS8N$react.useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$596a1f0f523d6752$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[$596a1f0f523d6752$var$TYPE_MAPPING[seg.type] || seg.type] = true, p), {}), [
120
- dateFormatter
127
+ let placeholder = (0, $iqS8N$react.useMemo)(()=>(0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone), [
128
+ props.placeholderValue,
129
+ granularity,
130
+ calendar,
131
+ defaultTimeZone
121
132
  ]);
122
- let [validSegments, setValidSegments] = (0, $iqS8N$react.useState)(()=>props.value || props.defaultValue ? {
123
- ...allSegments
124
- } : {});
125
- let clearedSegment = (0, $iqS8N$react.useRef)(null);
126
- // Reset placeholder when calendar changes
127
- let lastCalendar = (0, $iqS8N$react.useRef)(calendar);
128
- (0, $iqS8N$react.useEffect)(()=>{
129
- if (!(0, $iqS8N$internationalizeddate.isEqualCalendar)(calendar, lastCalendar.current)) {
130
- lastCalendar.current = calendar;
131
- setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $iqS8N$internationalizeddate.toCalendar)(placeholder, calendar) : (0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
132
- }
133
+ let displaySegments = (0, $iqS8N$react.useMemo)(()=>{
134
+ let is12HourClock = hourCycle === 'h11' || hourCycle === 'h12';
135
+ let segments = [
136
+ 'era',
137
+ 'year',
138
+ 'month',
139
+ 'day',
140
+ 'hour',
141
+ ...is12HourClock ? [
142
+ 'dayPeriod'
143
+ ] : [],
144
+ 'minute',
145
+ 'second'
146
+ ];
147
+ let minIndex = segments.indexOf(props.maxGranularity || 'era');
148
+ let maxIndex = segments.indexOf(granularity === 'hour' && is12HourClock ? 'dayPeriod' : granularity);
149
+ return segments.slice(minIndex, maxIndex + 1);
133
150
  }, [
134
- calendar,
151
+ props.maxGranularity,
135
152
  granularity,
136
- validSegments,
137
- defaultTimeZone,
138
- props.placeholderValue
153
+ hourCycle
139
154
  ]);
140
- // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
141
- if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
142
- validSegments = {
143
- ...allSegments
144
- };
145
- setValidSegments(validSegments);
155
+ let [lastValue, setLastValue] = (0, $iqS8N$react.useState)(calendarValue);
156
+ let [lastCalendar, setLastCalendar] = (0, $iqS8N$react.useState)(calendar);
157
+ let [lastHourCycle, setLastHourCycle] = (0, $iqS8N$react.useState)(hourCycle);
158
+ if (calendarValue !== lastValue || hourCycle !== lastHourCycle || !(0, $iqS8N$internationalizeddate.isEqualCalendar)(calendar, lastCalendar)) {
159
+ displayValue = new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue);
160
+ setLastValue(calendarValue);
161
+ setLastCalendar(calendar);
162
+ setLastHourCycle(hourCycle);
163
+ setDisplayValue(displayValue);
146
164
  }
147
- // If the value is set to null and all segments are valid, reset the placeholder.
148
- if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
149
- validSegments = {};
150
- setValidSegments(validSegments);
151
- setPlaceholderDate((0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
152
- }
153
- // If all segments are valid, use the date from state, otherwise use the placeholder date.
154
- let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
155
165
  let setValue = (newValue)=>{
156
166
  if (props.isDisabled || props.isReadOnly) return;
157
- let validKeys = Object.keys(validSegments);
158
- let allKeys = Object.keys(allSegments);
159
- // if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared
160
- if (newValue == null) {
167
+ if (newValue == null || newValue instanceof (0, $fd62790d5a95383f$exports.IncompleteDate) && newValue.isCleared(displaySegments)) {
168
+ setDisplayValue(new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue));
161
169
  setDate(null);
162
- setPlaceholderDate((0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone));
163
- setValidSegments({});
164
- } else if (validKeys.length === 0 && clearedSegment.current == null || validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== 'dayPeriod') {
165
- // If the field was empty (no valid segments) or all segments are completed, commit the new value.
166
- // When committing from an empty state, mark every segment as valid so value is committed.
167
- if (validKeys.length === 0) {
168
- validSegments = {
169
- ...allSegments
170
- };
171
- setValidSegments(validSegments);
172
- }
170
+ } else if (!(newValue instanceof (0, $fd62790d5a95383f$exports.IncompleteDate))) {
173
171
  // The display calendar should not have any effect on the emitted value.
174
172
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
175
173
  newValue = (0, $iqS8N$internationalizeddate.toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $iqS8N$internationalizeddate.GregorianCalendar)());
174
+ setDisplayValue(new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue));
176
175
  setDate(newValue);
177
- } else setPlaceholderDate(newValue);
178
- clearedSegment.current = null;
176
+ } else {
177
+ // If the new value is complete and valid, trigger onChange eagerly.
178
+ // If it represents an incomplete or invalid value (e.g. February 30th),
179
+ // wait until the field is blurred to trigger onChange.
180
+ if (newValue.isComplete(displaySegments)) {
181
+ let dateValue = newValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
182
+ if (newValue.validate(dateValue, displaySegments)) {
183
+ let newDateValue = (0, $iqS8N$internationalizeddate.toCalendar)(dateValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $iqS8N$internationalizeddate.GregorianCalendar)());
184
+ if (!value || newDateValue.compare(value) !== 0) {
185
+ setDisplayValue(new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue)); // reset in case prop isn't updated
186
+ setDate(newDateValue);
187
+ return;
188
+ }
189
+ }
190
+ }
191
+ // Incomplete/invalid value. Set temporary display override.
192
+ setDisplayValue(newValue);
193
+ }
179
194
  };
180
- let dateValue = (0, $iqS8N$react.useMemo)(()=>displayValue.toDate(timeZone), [
195
+ let dateValue = (0, $iqS8N$react.useMemo)(()=>{
196
+ let v = displayValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
197
+ return v.toDate(timeZone);
198
+ }, [
181
199
  displayValue,
182
- timeZone
200
+ timeZone,
201
+ calendarValue,
202
+ placeholder
183
203
  ]);
184
- let segments = (0, $iqS8N$react.useMemo)(()=>$596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFormatter, resolvedOptions, displayValue, calendar, locale, granularity), [
204
+ let segments = (0, $iqS8N$react.useMemo)(()=>$596a1f0f523d6752$var$processSegments(dateValue, displayValue, dateFormatter, resolvedOptions, calendar, locale, granularity), [
185
205
  dateValue,
186
- validSegments,
187
206
  dateFormatter,
188
207
  resolvedOptions,
189
208
  displayValue,
@@ -191,33 +210,8 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
191
210
  locale,
192
211
  granularity
193
212
  ]);
194
- // When the era field appears, mark it valid if the year field is already valid.
195
- // If the era field disappears, remove it from the valid segments.
196
- if (allSegments.era && validSegments.year && !validSegments.era) {
197
- validSegments.era = true;
198
- setValidSegments({
199
- ...validSegments
200
- });
201
- } else if (!allSegments.era && validSegments.era) {
202
- delete validSegments.era;
203
- setValidSegments({
204
- ...validSegments
205
- });
206
- }
207
- let markValid = (part)=>{
208
- validSegments[part] = true;
209
- if (part === 'year' && allSegments.era) validSegments.era = true;
210
- setValidSegments({
211
- ...validSegments
212
- });
213
- };
214
213
  let adjustSegment = (type, amount)=>{
215
- if (!validSegments[type]) {
216
- markValid(type);
217
- let validKeys = Object.keys(validSegments);
218
- let allKeys = Object.keys(allSegments);
219
- if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) setValue(displayValue);
220
- } else setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
214
+ setValue(displayValue.cycle(type, amount, placeholder, displaySegments));
221
215
  };
222
216
  let builtinValidation = (0, $iqS8N$react.useMemo)(()=>(0, $50d5d6a623389320$exports.getValidationResult)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
223
217
  value,
@@ -262,48 +256,30 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
262
256
  decrementPage (part) {
263
257
  adjustSegment(part, -($596a1f0f523d6752$var$PAGE_STEP[part] || 1));
264
258
  },
259
+ incrementToMax (part) {
260
+ let maxValue = part === 'hour' && hourCycle === 'h12' ? 11 : displayValue.getSegmentLimits(part).maxValue;
261
+ setValue(displayValue.set(part, maxValue, placeholder));
262
+ },
263
+ decrementToMin (part) {
264
+ let minValue = part === 'hour' && hourCycle === 'h12' ? 12 : displayValue.getSegmentLimits(part).minValue;
265
+ setValue(displayValue.set(part, minValue, placeholder));
266
+ },
265
267
  setSegment (part, v) {
266
- markValid(part);
267
- setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
268
+ setValue(displayValue.set(part, v, placeholder));
268
269
  },
269
270
  confirmPlaceholder () {
270
271
  if (props.isDisabled || props.isReadOnly) return;
271
- // Confirm the placeholder if only the day period is not filled in.
272
- let validKeys = Object.keys(validSegments);
273
- let allKeys = Object.keys(allSegments);
274
- if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
275
- validSegments = {
276
- ...allSegments
277
- };
278
- setValidSegments(validSegments);
279
- setValue(displayValue.copy());
272
+ // If the display value is complete but invalid, we need to constrain it and emit onChange on blur.
273
+ if (displayValue.isComplete(displaySegments)) {
274
+ let dateValue = displayValue.toValue(calendarValue !== null && calendarValue !== void 0 ? calendarValue : placeholder);
275
+ let newDateValue = (0, $iqS8N$internationalizeddate.toCalendar)(dateValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $iqS8N$internationalizeddate.GregorianCalendar)());
276
+ if (!value || newDateValue.compare(value) !== 0) setDate(newDateValue);
277
+ setDisplayValue(new (0, $fd62790d5a95383f$exports.IncompleteDate)(calendar, hourCycle, calendarValue));
280
278
  }
281
279
  },
282
280
  clearSegment (part) {
283
- delete validSegments[part];
284
- clearedSegment.current = part;
285
- setValidSegments({
286
- ...validSegments
287
- });
288
- let placeholder = (0, $50d5d6a623389320$exports.createPlaceholderDate)(props.placeholderValue, granularity, calendar, defaultTimeZone);
289
281
  let value = displayValue;
290
- // Reset day period to default without changing the hour.
291
- if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {
292
- let isPM = displayValue.hour >= 12;
293
- let shouldBePM = placeholder.hour >= 12;
294
- if (isPM && !shouldBePM) value = displayValue.set({
295
- hour: displayValue.hour - 12
296
- });
297
- else if (!isPM && shouldBePM) value = displayValue.set({
298
- hour: displayValue.hour + 12
299
- });
300
- } else if (part === 'hour' && 'hour' in displayValue && displayValue.hour >= 12 && validSegments.dayPeriod) value = displayValue.set({
301
- hour: placeholder['hour'] + 12
302
- });
303
- else if (part in displayValue) value = displayValue.set({
304
- [part]: placeholder[part]
305
- });
306
- setDate(null);
282
+ if (part !== 'timeZoneName' && part !== 'literal') value = displayValue.clear(part);
307
283
  setValue(value);
308
284
  },
309
285
  formatValue (fieldOptions) {
@@ -322,24 +298,40 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
322
298
  }
323
299
  };
324
300
  }
325
- function $596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFormatter, resolvedOptions, displayValue, calendar, locale, granularity) {
301
+ function $596a1f0f523d6752$var$processSegments(dateValue, displayValue, dateFormatter, resolvedOptions, calendar, locale, granularity) {
326
302
  let timeValue = [
327
303
  'hour',
328
304
  'minute',
329
305
  'second'
330
306
  ];
331
307
  let segments = dateFormatter.formatToParts(dateValue);
308
+ // In order to allow formatting temporarily invalid dates during editing (e.g. February 30th),
309
+ // use a NumberFormatter to manually format segments directly from raw numbers.
310
+ // When the user blurs the date field, the invalid segments will be constrained.
311
+ let numberFormatter = new (0, $iqS8N$internationalizednumber.NumberFormatter)(locale, {
312
+ useGrouping: false
313
+ });
314
+ let twoDigitFormatter = new (0, $iqS8N$internationalizednumber.NumberFormatter)(locale, {
315
+ useGrouping: false,
316
+ minimumIntegerDigits: 2
317
+ });
318
+ for (let segment of segments)if (segment.type === 'year' || segment.type === 'month' || segment.type === 'day' || segment.type === 'hour') {
319
+ var _displayValue_segment_type;
320
+ let value = (_displayValue_segment_type = displayValue[segment.type]) !== null && _displayValue_segment_type !== void 0 ? _displayValue_segment_type : 0;
321
+ if (resolvedOptions[segment.type] === '2-digit') segment.value = twoDigitFormatter.format(value);
322
+ else segment.value = numberFormatter.format(value);
323
+ }
332
324
  let processedSegments = [];
333
325
  for (let segment of segments){
334
326
  let type = $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type;
335
327
  let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[type];
336
328
  if (type === 'era' && calendar.getEras().length === 1) isEditable = false;
337
- let isPlaceholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[type] && !validSegments[type];
329
+ let isPlaceholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[type] && displayValue[segment.type] == null;
338
330
  let placeholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[type] ? (0, $e1e8ada727fae1a1$exports.getPlaceholder)(type, segment.value, locale) : null;
339
331
  let dateSegment = {
340
332
  type: type,
341
333
  text: isPlaceholder ? placeholder : segment.value,
342
- ...$596a1f0f523d6752$var$getSegmentLimits(displayValue, type, resolvedOptions),
334
+ ...displayValue.getSegmentLimits(type),
343
335
  isPlaceholder: isPlaceholder,
344
336
  placeholder: placeholder,
345
337
  isEditable: isEditable
@@ -352,7 +344,6 @@ function $596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFor
352
344
  processedSegments.push({
353
345
  type: 'literal',
354
346
  text: '\u2066',
355
- ...$596a1f0f523d6752$var$getSegmentLimits(displayValue, 'literal', resolvedOptions),
356
347
  isPlaceholder: false,
357
348
  placeholder: '',
358
349
  isEditable: false
@@ -362,7 +353,6 @@ function $596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFor
362
353
  if (type === granularity) processedSegments.push({
363
354
  type: 'literal',
364
355
  text: '\u2069',
365
- ...$596a1f0f523d6752$var$getSegmentLimits(displayValue, 'literal', resolvedOptions),
366
356
  isPlaceholder: false,
367
357
  placeholder: '',
368
358
  isEditable: false
@@ -373,7 +363,6 @@ function $596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFor
373
363
  processedSegments.push({
374
364
  type: 'literal',
375
365
  text: '\u2069',
376
- ...$596a1f0f523d6752$var$getSegmentLimits(displayValue, 'literal', resolvedOptions),
377
366
  isPlaceholder: false,
378
367
  placeholder: '',
379
368
  isEditable: false
@@ -383,139 +372,6 @@ function $596a1f0f523d6752$var$processSegments(dateValue, validSegments, dateFor
383
372
  }
384
373
  return processedSegments;
385
374
  }
386
- function $596a1f0f523d6752$var$getSegmentLimits(date, type, options) {
387
- switch(type){
388
- case 'era':
389
- {
390
- let eras = date.calendar.getEras();
391
- return {
392
- value: eras.indexOf(date.era),
393
- minValue: 0,
394
- maxValue: eras.length - 1
395
- };
396
- }
397
- case 'year':
398
- return {
399
- value: date.year,
400
- minValue: 1,
401
- maxValue: date.calendar.getYearsInEra(date)
402
- };
403
- case 'month':
404
- return {
405
- value: date.month,
406
- minValue: (0, $iqS8N$internationalizeddate.getMinimumMonthInYear)(date),
407
- maxValue: date.calendar.getMonthsInYear(date)
408
- };
409
- case 'day':
410
- return {
411
- value: date.day,
412
- minValue: (0, $iqS8N$internationalizeddate.getMinimumDayInMonth)(date),
413
- maxValue: date.calendar.getDaysInMonth(date)
414
- };
415
- }
416
- if ('hour' in date) switch(type){
417
- case 'dayPeriod':
418
- return {
419
- value: date.hour >= 12 ? 12 : 0,
420
- minValue: 0,
421
- maxValue: 12
422
- };
423
- case 'hour':
424
- if (options.hour12) {
425
- let isPM = date.hour >= 12;
426
- return {
427
- value: date.hour,
428
- minValue: isPM ? 12 : 0,
429
- maxValue: isPM ? 23 : 11
430
- };
431
- }
432
- return {
433
- value: date.hour,
434
- minValue: 0,
435
- maxValue: 23
436
- };
437
- case 'minute':
438
- return {
439
- value: date.minute,
440
- minValue: 0,
441
- maxValue: 59
442
- };
443
- case 'second':
444
- return {
445
- value: date.second,
446
- minValue: 0,
447
- maxValue: 59
448
- };
449
- }
450
- return {};
451
- }
452
- function $596a1f0f523d6752$var$addSegment(value, part, amount, options) {
453
- switch(part){
454
- case 'era':
455
- case 'year':
456
- case 'month':
457
- case 'day':
458
- return value.cycle(part, amount, {
459
- round: part === 'year'
460
- });
461
- }
462
- if ('hour' in value) switch(part){
463
- case 'dayPeriod':
464
- {
465
- let hours = value.hour;
466
- let isPM = hours >= 12;
467
- return value.set({
468
- hour: isPM ? hours - 12 : hours + 12
469
- });
470
- }
471
- case 'hour':
472
- case 'minute':
473
- case 'second':
474
- return value.cycle(part, amount, {
475
- round: part !== 'hour',
476
- hourCycle: options.hour12 ? 12 : 24
477
- });
478
- }
479
- throw new Error('Unknown segment: ' + part);
480
- }
481
- function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
482
- switch(part){
483
- case 'day':
484
- case 'month':
485
- case 'year':
486
- case 'era':
487
- return value.set({
488
- [part]: segmentValue
489
- });
490
- }
491
- if ('hour' in value && typeof segmentValue === 'number') switch(part){
492
- case 'dayPeriod':
493
- {
494
- let hours = value.hour;
495
- let wasPM = hours >= 12;
496
- let isPM = segmentValue >= 12;
497
- if (isPM === wasPM) return value;
498
- return value.set({
499
- hour: wasPM ? hours - 12 : hours + 12
500
- });
501
- }
502
- case 'hour':
503
- // In 12 hour time, ensure that AM/PM does not change
504
- if (options.hour12) {
505
- let hours = value.hour;
506
- let wasPM = hours >= 12;
507
- if (!wasPM && segmentValue === 12) segmentValue = 0;
508
- if (wasPM && segmentValue < 12) segmentValue += 12;
509
- }
510
- // fallthrough
511
- case 'minute':
512
- case 'second':
513
- return value.set({
514
- [part]: segmentValue
515
- });
516
- }
517
- throw new Error('Unknown segment: ' + part);
518
- }
519
375
 
520
376
 
521
377
  //# sourceMappingURL=useDateFieldState.main.js.map