@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.
- package/dist/IncompleteDate.main.js +335 -0
- package/dist/IncompleteDate.main.js.map +1 -0
- package/dist/IncompleteDate.mjs +330 -0
- package/dist/IncompleteDate.module.js +330 -0
- package/dist/IncompleteDate.module.js.map +1 -0
- package/dist/types.d.ts +5 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useDateFieldState.main.js +122 -266
- package/dist/useDateFieldState.main.js.map +1 -1
- package/dist/useDateFieldState.mjs +124 -268
- package/dist/useDateFieldState.module.js +124 -268
- package/dist/useDateFieldState.module.js.map +1 -1
- package/package.json +8 -7
- package/src/IncompleteDate.ts +392 -0
- package/src/useDateFieldState.ts +124 -284
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAcM,MAAM;IAoCX,OAAuB;QACrB,IAAI,MAAM,IAAI,0CAAe,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS;QAC1D,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG;QAClB,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI;QACpB,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK;QACtB,IAAI,GAAG,GAAG,IAAI,CAAC,GAAG;QAClB,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI;QACpB,IAAI,SAAS,GAAG,IAAI,CAAC,SAAS;QAC9B,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,IAAI,WAAW,GAAG,IAAI,CAAC,WAAW;QAClC,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM;QACxB,OAAO;IACT;IAEA,4DAA4D,GAC5D,WAAW,QAAuB,EAAE;QAClC,OAAO,SAAS,KAAK,CAAC,CAAA,UAAW,IAAI,CAAC,QAAQ,IAAI;IACpD;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;AAEA,SAAS,kCAAY,IAAY,EAAE,SAAoB;IACrD,IAAI,YAA2B,QAAQ,KAAK,IAAI;IAChD,OAAQ;QACN,KAAK;YACH,kDAAkD;YAClD,IAAI,QAAQ,IACV,QAAQ;YAEV;QACF,KAAK;YACH,qDAAqD;YACrD,IAAI,SAAS,GACX,OAAO;iBACF,IAAI,OAAO,IAChB,QAAQ;YAEV;QACF,KAAK;YACH,kCAAkC;YAClC,YAAY;YACZ;QACF,KAAK;YACH,+EAA+E;YAC/E,QAAQ;YACR,YAAY;IAChB;IAEA,OAAO;QAAC;QAAW;KAAK;AAC1B;AAEA,SAAS,oCAAc,IAAY,EAAE,SAAiB,EAAE,SAAoB;IAC1E,OAAQ;QACN,KAAK;YACH,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,IAAI,SAAS,IACX,OAAO;YAET,IAAI,cAAc,GAChB,QAAQ;YAEV;QACF,KAAK;YACH,QAAQ;YACR;IACJ;IAEA,OAAO;AACT","sources":["packages/@react-stately/datepicker/src/IncompleteDate.ts"],"sourcesContent":["/*\n * Copyright 2026 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 {AnyDateTime, Calendar, CalendarDate, ZonedDateTime} from '@internationalized/date';\nimport {DateValue} from '@react-types/datepicker';\nimport {SegmentType} from './useDateFieldState';\n\ntype HourCycle = 'h12' | 'h11' | 'h23' | 'h24';\n\n/**\n * This class represents a date that is incomplete or otherwise invalid as a result of user editing.\n * For example, it can represent temporary dates such as February 31st if the user edits the day before the month.\n * Times are represented according to an hour cycle rather than always in 24 hour time. This enables the user to adjust\n * the day period (e.g. am/pm) independently from the hour.\n */\nexport class IncompleteDate {\n calendar: Calendar;\n era: string | null;\n year: number | null;\n month: number | null;\n day: number | null;\n hour: number | null;\n hourCycle: HourCycle;\n dayPeriod: number | null;\n minute: number | null;\n second: number | null;\n millisecond: number | null;\n offset: number | null;\n\n constructor(calendar: Calendar, hourCycle: HourCycle, dateValue?: Partial<Omit<AnyDateTime, 'copy'>> | null) {\n this.era = dateValue?.era ?? null;\n this.calendar = calendar;\n this.year = dateValue?.year ?? null;\n this.month = dateValue?.month ?? null;\n this.day = dateValue?.day ?? null;\n this.hour = dateValue?.hour ?? null;\n this.hourCycle = hourCycle;\n this.dayPeriod = null;\n this.minute = dateValue?.minute ?? null;\n this.second = dateValue?.second ?? null;\n this.millisecond = dateValue?.millisecond ?? null;\n this.offset = 'offset' in (dateValue ?? {}) ? (dateValue as any).offset : null;\n\n // Convert the hour from 24 hour time to the given hour cycle.\n if (this.hour != null) {\n let [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);\n this.dayPeriod = dayPeriod;\n this.hour = hour;\n }\n }\n\n copy(): IncompleteDate {\n let res = new IncompleteDate(this.calendar, this.hourCycle);\n res.era = this.era;\n res.year = this.year;\n res.month = this.month;\n res.day = this.day;\n res.hour = this.hour;\n res.dayPeriod = this.dayPeriod;\n res.minute = this.minute;\n res.second = this.second;\n res.millisecond = this.millisecond;\n res.offset = this.offset;\n return res;\n }\n\n /** Checks whether all the specified segments have a value. */\n isComplete(segments: SegmentType[]) {\n return segments.every(segment => this[segment] != null);\n }\n\n /** Checks whether the given date value matches this value for the specified segments. */\n validate(dt: DateValue, segments: SegmentType[]) {\n return segments.every(segment => {\n if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {\n let [dayPeriod, hour] = toHourCycle(dt.hour, this.hourCycle);\n return this.dayPeriod === dayPeriod && this.hour === hour;\n }\n return this[segment] === dt[segment];\n });\n }\n\n /** Checks if the date is empty (i.e. all specified segments are null). */\n isCleared(segments: SegmentType[]): boolean {\n return segments.every(segment => this[segment] === null);\n }\n\n /** Sets the given field. */\n set(field: SegmentType, value: number | string, placeholder: DateValue): IncompleteDate {\n let result = this.copy();\n result[field] = value;\n if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) {\n result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n if (field === 'year' && result.era == null) {\n result.era = placeholder.era;\n }\n\n // clear offset when a date/time field changes since it may no longer be valid\n if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') {\n result.offset = null;\n }\n return result;\n }\n\n /** Sets the given field to null. */\n clear(field: SegmentType): IncompleteDate {\n let result = this.copy();\n // @ts-ignore\n result[field] = null;\n if (field === 'year') {\n result.era = null;\n }\n\n // clear offset when a field is cleared since it may no longer be valid\n result.offset = null;\n return result;\n }\n\n /** Increments or decrements the given field. If it is null, then it is set to the placeholder value. */\n cycle(field: SegmentType, amount: number, placeholder: DateValue, displaySegments: SegmentType[]): IncompleteDate {\n let res = this.copy();\n\n // If field is null, default to placeholder.\n if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {\n if (field === 'hour' && 'hour' in placeholder) {\n let [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);\n res.dayPeriod = dayPeriod;\n res.hour = hour;\n } else {\n res[field] = placeholder[field];\n }\n if (field === 'year' && res.era == null) {\n res.era = placeholder.era;\n }\n\n return res;\n }\n\n switch (field) {\n case 'era': {\n let eras = this.calendar.getEras();\n let index = eras.indexOf(res.era!);\n index = cycleValue(index, amount, 0, eras.length - 1);\n res.era = eras[index];\n break;\n }\n case 'year': {\n // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.\n let date = new CalendarDate(this.calendar, this.era ?? placeholder.era, this.year ?? placeholder.year, this.month ?? 1, this.day ?? 1);\n date = date.cycle(field, amount, {round: field === 'year'});\n res.era = date.era;\n res.year = date.year;\n break;\n }\n case 'month':\n res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());\n break;\n case 'day':\n // Allow incrementing up to the maximum number of days in any month.\n res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());\n break;\n case 'hour': {\n // 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\n // so DST fallback is properly handled\n let hasDateSegements = displaySegments.some(s => ['year', 'month', 'day'].includes(s));\n if ('timeZone' in placeholder && (!hasDateSegements || (res.year != null && res.month != null && res.day != null))) {\n let date = this.toValue(placeholder) as ZonedDateTime;\n date = date.cycle('hour', amount, {hourCycle: this.hourCycle === 'h12' ? 12 : 24, round: false});\n let [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);\n res.hour = adjustedHour;\n res.dayPeriod = dayPeriod;\n res.offset = date.offset;\n } else {\n let hours = res.hour ?? 0;\n let limits = this.getSegmentLimits('hour')!;\n res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);\n if (res.dayPeriod == null && 'hour' in placeholder) {\n res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];\n }\n }\n break;\n }\n case 'dayPeriod':\n res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);\n break;\n case 'minute':\n res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);\n break;\n case 'second':\n res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);\n break;\n }\n\n return res;\n }\n\n /** Converts the incomplete date to a full date value, using the provided value for any unset fields. */\n toValue(value: DateValue): DateValue {\n if ('hour' in value) {\n let hour = this.hour;\n if (hour != null) {\n hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);\n } else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') {\n hour = this.dayPeriod === 1 ? 12 : 0;\n }\n\n let res = value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day,\n hour: hour ?? value.hour,\n minute: this.minute ?? value.minute,\n second: this.second ?? value.second,\n millisecond: this.millisecond ?? value.millisecond\n });\n\n if ('offset' in res && this.offset != null && res.offset !== this.offset) {\n res = res.add({milliseconds: res.offset - this.offset});\n }\n\n return res;\n } else {\n return value.set({\n era: this.era ?? value.era,\n year: this.year ?? value.year,\n month: this.month ?? value.month,\n day: this.day ?? value.day\n });\n }\n }\n\n getSegmentLimits(type: string): {value: number | null, minValue: number, maxValue: number} | undefined {\n switch (type) {\n case 'era': {\n let eras = this.calendar.getEras();\n return {\n value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,\n minValue: 0,\n maxValue: eras.length - 1\n };\n }\n case 'year':\n return {\n value: this.year,\n minValue: 1,\n maxValue: 9999\n };\n case 'month':\n return {\n value: this.month,\n minValue: 1,\n maxValue: this.calendar.getMaximumMonthsInYear()\n };\n case 'day':\n return {\n value: this.day,\n minValue: 1,\n maxValue: this.calendar.getMaximumDaysInMonth()\n };\n case 'dayPeriod': {\n return {\n value: this.dayPeriod,\n minValue: 0,\n maxValue: 1\n };\n }\n case 'hour': {\n let minValue = 0;\n let maxValue = 23;\n if (this.hourCycle === 'h12') {\n minValue = 1;\n maxValue = 12;\n } else if (this.hourCycle === 'h11') {\n minValue = 0;\n maxValue = 11;\n }\n\n return {\n value: this.hour,\n minValue,\n maxValue\n };\n }\n case 'minute':\n return {\n value: this.minute,\n minValue: 0,\n maxValue: 59\n };\n case 'second':\n return {\n value: this.second,\n minValue: 0,\n maxValue: 59\n };\n }\n }\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\nfunction toHourCycle(hour: number, hourCycle: HourCycle): [number | null, number] {\n let dayPeriod: number | null = hour >= 12 ? 1 : 0;\n switch (hourCycle) {\n case 'h11':\n // Hours are numbered from 0 to 11. Used in Japan.\n if (hour >= 12) {\n hour -= 12;\n }\n break;\n case 'h12':\n // Hours are numbered from 12 (representing 0) to 11.\n if (hour === 0) {\n hour = 12;\n } else if (hour > 12) {\n hour -= 12;\n }\n break;\n case 'h23':\n // 24 hour time, numbered 0 to 23.\n dayPeriod = null;\n break;\n case 'h24':\n // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.\n hour += 1;\n dayPeriod = null;\n }\n\n return [dayPeriod, hour];\n}\n\nfunction fromHourCycle(hour: number, dayPeriod: number, hourCycle: HourCycle): number {\n switch (hourCycle) {\n case 'h11':\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h12':\n if (hour === 12) {\n hour = 0;\n }\n if (dayPeriod === 1) {\n hour += 12;\n }\n break;\n case 'h24':\n hour -= 1;\n break;\n }\n\n return hour;\n}\n"],"names":[],"version":3,"file":"IncompleteDate.module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export interface DateSegment {
|
|
|
73
73
|
/** The formatted text for the segment. */
|
|
74
74
|
text: string;
|
|
75
75
|
/** The numeric value for the segment, if applicable. */
|
|
76
|
-
value?: number;
|
|
76
|
+
value?: number | null;
|
|
77
77
|
/** The minimum numeric value for the segment, if applicable. */
|
|
78
78
|
minValue?: number;
|
|
79
79
|
/** The maximum numeric value for the segment, if applicable. */
|
|
@@ -133,6 +133,10 @@ export interface DateFieldState extends FormValidationState {
|
|
|
133
133
|
* Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
|
|
134
134
|
*/
|
|
135
135
|
decrementPage(type: SegmentType): void;
|
|
136
|
+
/** Increments the given segment to its maxiumum value. */
|
|
137
|
+
incrementToMax(type: SegmentType): void;
|
|
138
|
+
/** Decrements the given segment to its minimum value. */
|
|
139
|
+
decrementToMin(type: SegmentType): void;
|
|
136
140
|
/** Sets the value of the given segment. */
|
|
137
141
|
setSegment(type: 'era', value: string): void;
|
|
138
142
|
setSegment(type: SegmentType, value: number): void;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;AAkIA,oBAA2B,IAAI,CAAC,KAAK,qBAAqB,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC,CAAC;AACrH;IACE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,gBAAgB,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC;IAClD,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,gBAAgB,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC;IACxE,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC;ACtHD,wCAAwC,CAAC,SAAS,SAAS,CAAE,SAAQ,gBAAgB,CAAC,CAAC;IACrF;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,OAAO,CAAC,CAAA;CAChD;AAED,gCAAiC,SAAQ,mBAAmB,EAAE,mBAAmB;IAC/E,mCAAmC;IACnC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,wBAAwB;IACxB,YAAY,EAAE,SAAS,GAAG,IAAI,CAAC;IAC/B,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;IACxC;;;OAGG;IACH,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,0CAA0C;IAC1C,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC;;;OAGG;IACH,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC;IAC5B,0CAA0C;IAC1C,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AClE,wFAAwF;IACxF,WAAW,EAAE,WAAW,CAAC;IACzB,qHAAqH;IACrH,OAAO,EAAE,OAAO,CAAC;IACjB,sDAAsD;IACtD,MAAM,EAAE,OAAO,CAAC;IAChB,iDAAiD;IACjD,OAAO,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/B;;;OAGG;IACH,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IACxC,4GAA4G;IAC5G,SAAS,EAAE,OAAO,CAAC;IACnB,0DAA0D;IAC1D,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAC,GAAG,IAAI,CAAC;IAC7F,+CAA+C;IAC/C,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,aAAa,CAAA;CACjF;AAED;;;;GAIG;AACH,wCAAwC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,4BAA4B,CAAC,CAAC,GAAG,oBAAoB,CAiPpI;ACnTD,uCAAuC,CAAC,SAAS,SAAS,GAAG,SAAS,CAAE,SAAQ,gBAAgB,CAAC,CAAC;IAChG,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAA;CACf;AAED,+BAAgC,SAAQ,cAAc;IACpD,8BAA8B;IAC9B,SAAS,EAAE,IAAI,CAAA;CAChB;AAED;;;;GAIG;AACH,kCAAkC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,cAAc,CAqDlH","sources":["packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/utils.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/useDatePickerState.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/placeholders.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/IncompleteDate.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/useDateFieldState.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/useDateRangePickerState.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/useTimeFieldState.ts","packages/@react-stately/datepicker/src/packages/@react-stately/datepicker/src/index.ts","packages/@react-stately/datepicker/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,"/*\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\nexport {useDatePickerState} from './useDatePickerState';\nexport {useDateFieldState} from './useDateFieldState';\nexport {useDateRangePickerState} from './useDateRangePickerState';\nexport {useTimeFieldState} from './useTimeFieldState';\n\nexport type {DateFieldStateOptions, DateFieldState, DateSegment, SegmentType} from './useDateFieldState';\nexport type {DatePickerStateOptions, DatePickerState} from './useDatePickerState';\nexport type {DateRangePickerStateOptions, DateRangePickerState} from './useDateRangePickerState';\nexport type {TimeFieldStateOptions, TimeFieldState} from './useTimeFieldState';\nexport type {FormatterOptions} from './utils';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
81
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
151
|
+
props.maxGranularity,
|
|
135
152
|
granularity,
|
|
136
|
-
|
|
137
|
-
defaultTimeZone,
|
|
138
|
-
props.placeholderValue
|
|
153
|
+
hourCycle
|
|
139
154
|
]);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
158
|
-
|
|
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
|
-
|
|
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
|
|
178
|
-
|
|
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)(()=>
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
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
|
-
|
|
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,
|
|
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] &&
|
|
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
|
-
|
|
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
|