@react-stately/datepicker 3.16.0 → 3.17.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.
Files changed (227) hide show
  1. package/dist/import.mjs +5 -5
  2. package/dist/main.js +8 -8
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +5 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +9 -0
  7. package/package.json +17 -20
  8. package/src/index.ts +9 -9
  9. package/dist/IncompleteDate.main.js +0 -335
  10. package/dist/IncompleteDate.main.js.map +0 -1
  11. package/dist/IncompleteDate.mjs +0 -330
  12. package/dist/IncompleteDate.module.js +0 -330
  13. package/dist/IncompleteDate.module.js.map +0 -1
  14. package/dist/ar-AE.main.js +0 -9
  15. package/dist/ar-AE.main.js.map +0 -1
  16. package/dist/ar-AE.mjs +0 -11
  17. package/dist/ar-AE.module.js +0 -11
  18. package/dist/ar-AE.module.js.map +0 -1
  19. package/dist/bg-BG.main.js +0 -9
  20. package/dist/bg-BG.main.js.map +0 -1
  21. package/dist/bg-BG.mjs +0 -11
  22. package/dist/bg-BG.module.js +0 -11
  23. package/dist/bg-BG.module.js.map +0 -1
  24. package/dist/cs-CZ.main.js +0 -9
  25. package/dist/cs-CZ.main.js.map +0 -1
  26. package/dist/cs-CZ.mjs +0 -11
  27. package/dist/cs-CZ.module.js +0 -11
  28. package/dist/cs-CZ.module.js.map +0 -1
  29. package/dist/da-DK.main.js +0 -9
  30. package/dist/da-DK.main.js.map +0 -1
  31. package/dist/da-DK.mjs +0 -11
  32. package/dist/da-DK.module.js +0 -11
  33. package/dist/da-DK.module.js.map +0 -1
  34. package/dist/de-DE.main.js +0 -9
  35. package/dist/de-DE.main.js.map +0 -1
  36. package/dist/de-DE.mjs +0 -11
  37. package/dist/de-DE.module.js +0 -11
  38. package/dist/de-DE.module.js.map +0 -1
  39. package/dist/el-GR.main.js +0 -9
  40. package/dist/el-GR.main.js.map +0 -1
  41. package/dist/el-GR.mjs +0 -11
  42. package/dist/el-GR.module.js +0 -11
  43. package/dist/el-GR.module.js.map +0 -1
  44. package/dist/en-US.main.js +0 -9
  45. package/dist/en-US.main.js.map +0 -1
  46. package/dist/en-US.mjs +0 -11
  47. package/dist/en-US.module.js +0 -11
  48. package/dist/en-US.module.js.map +0 -1
  49. package/dist/es-ES.main.js +0 -9
  50. package/dist/es-ES.main.js.map +0 -1
  51. package/dist/es-ES.mjs +0 -11
  52. package/dist/es-ES.module.js +0 -11
  53. package/dist/es-ES.module.js.map +0 -1
  54. package/dist/et-EE.main.js +0 -9
  55. package/dist/et-EE.main.js.map +0 -1
  56. package/dist/et-EE.mjs +0 -11
  57. package/dist/et-EE.module.js +0 -11
  58. package/dist/et-EE.module.js.map +0 -1
  59. package/dist/fi-FI.main.js +0 -9
  60. package/dist/fi-FI.main.js.map +0 -1
  61. package/dist/fi-FI.mjs +0 -11
  62. package/dist/fi-FI.module.js +0 -11
  63. package/dist/fi-FI.module.js.map +0 -1
  64. package/dist/fr-FR.main.js +0 -9
  65. package/dist/fr-FR.main.js.map +0 -1
  66. package/dist/fr-FR.mjs +0 -11
  67. package/dist/fr-FR.module.js +0 -11
  68. package/dist/fr-FR.module.js.map +0 -1
  69. package/dist/he-IL.main.js +0 -9
  70. package/dist/he-IL.main.js.map +0 -1
  71. package/dist/he-IL.mjs +0 -11
  72. package/dist/he-IL.module.js +0 -11
  73. package/dist/he-IL.module.js.map +0 -1
  74. package/dist/hr-HR.main.js +0 -9
  75. package/dist/hr-HR.main.js.map +0 -1
  76. package/dist/hr-HR.mjs +0 -11
  77. package/dist/hr-HR.module.js +0 -11
  78. package/dist/hr-HR.module.js.map +0 -1
  79. package/dist/hu-HU.main.js +0 -9
  80. package/dist/hu-HU.main.js.map +0 -1
  81. package/dist/hu-HU.mjs +0 -11
  82. package/dist/hu-HU.module.js +0 -11
  83. package/dist/hu-HU.module.js.map +0 -1
  84. package/dist/intlStrings.main.js +0 -108
  85. package/dist/intlStrings.main.js.map +0 -1
  86. package/dist/intlStrings.mjs +0 -110
  87. package/dist/intlStrings.module.js +0 -110
  88. package/dist/intlStrings.module.js.map +0 -1
  89. package/dist/it-IT.main.js +0 -9
  90. package/dist/it-IT.main.js.map +0 -1
  91. package/dist/it-IT.mjs +0 -11
  92. package/dist/it-IT.module.js +0 -11
  93. package/dist/it-IT.module.js.map +0 -1
  94. package/dist/ja-JP.main.js +0 -9
  95. package/dist/ja-JP.main.js.map +0 -1
  96. package/dist/ja-JP.mjs +0 -11
  97. package/dist/ja-JP.module.js +0 -11
  98. package/dist/ja-JP.module.js.map +0 -1
  99. package/dist/ko-KR.main.js +0 -9
  100. package/dist/ko-KR.main.js.map +0 -1
  101. package/dist/ko-KR.mjs +0 -11
  102. package/dist/ko-KR.module.js +0 -11
  103. package/dist/ko-KR.module.js.map +0 -1
  104. package/dist/lt-LT.main.js +0 -9
  105. package/dist/lt-LT.main.js.map +0 -1
  106. package/dist/lt-LT.mjs +0 -11
  107. package/dist/lt-LT.module.js +0 -11
  108. package/dist/lt-LT.module.js.map +0 -1
  109. package/dist/lv-LV.main.js +0 -9
  110. package/dist/lv-LV.main.js.map +0 -1
  111. package/dist/lv-LV.mjs +0 -11
  112. package/dist/lv-LV.module.js +0 -11
  113. package/dist/lv-LV.module.js.map +0 -1
  114. package/dist/nb-NO.main.js +0 -9
  115. package/dist/nb-NO.main.js.map +0 -1
  116. package/dist/nb-NO.mjs +0 -11
  117. package/dist/nb-NO.module.js +0 -11
  118. package/dist/nb-NO.module.js.map +0 -1
  119. package/dist/nl-NL.main.js +0 -9
  120. package/dist/nl-NL.main.js.map +0 -1
  121. package/dist/nl-NL.mjs +0 -11
  122. package/dist/nl-NL.module.js +0 -11
  123. package/dist/nl-NL.module.js.map +0 -1
  124. package/dist/pl-PL.main.js +0 -9
  125. package/dist/pl-PL.main.js.map +0 -1
  126. package/dist/pl-PL.mjs +0 -11
  127. package/dist/pl-PL.module.js +0 -11
  128. package/dist/pl-PL.module.js.map +0 -1
  129. package/dist/placeholders.main.js +0 -414
  130. package/dist/placeholders.main.js.map +0 -1
  131. package/dist/placeholders.mjs +0 -409
  132. package/dist/placeholders.module.js +0 -409
  133. package/dist/placeholders.module.js.map +0 -1
  134. package/dist/pt-BR.main.js +0 -9
  135. package/dist/pt-BR.main.js.map +0 -1
  136. package/dist/pt-BR.mjs +0 -11
  137. package/dist/pt-BR.module.js +0 -11
  138. package/dist/pt-BR.module.js.map +0 -1
  139. package/dist/pt-PT.main.js +0 -9
  140. package/dist/pt-PT.main.js.map +0 -1
  141. package/dist/pt-PT.mjs +0 -11
  142. package/dist/pt-PT.module.js +0 -11
  143. package/dist/pt-PT.module.js.map +0 -1
  144. package/dist/ro-RO.main.js +0 -9
  145. package/dist/ro-RO.main.js.map +0 -1
  146. package/dist/ro-RO.mjs +0 -11
  147. package/dist/ro-RO.module.js +0 -11
  148. package/dist/ro-RO.module.js.map +0 -1
  149. package/dist/ru-RU.main.js +0 -9
  150. package/dist/ru-RU.main.js.map +0 -1
  151. package/dist/ru-RU.mjs +0 -11
  152. package/dist/ru-RU.module.js +0 -11
  153. package/dist/ru-RU.module.js.map +0 -1
  154. package/dist/sk-SK.main.js +0 -9
  155. package/dist/sk-SK.main.js.map +0 -1
  156. package/dist/sk-SK.mjs +0 -11
  157. package/dist/sk-SK.module.js +0 -11
  158. package/dist/sk-SK.module.js.map +0 -1
  159. package/dist/sl-SI.main.js +0 -9
  160. package/dist/sl-SI.main.js.map +0 -1
  161. package/dist/sl-SI.mjs +0 -11
  162. package/dist/sl-SI.module.js +0 -11
  163. package/dist/sl-SI.module.js.map +0 -1
  164. package/dist/sr-SP.main.js +0 -9
  165. package/dist/sr-SP.main.js.map +0 -1
  166. package/dist/sr-SP.mjs +0 -11
  167. package/dist/sr-SP.module.js +0 -11
  168. package/dist/sr-SP.module.js.map +0 -1
  169. package/dist/sv-SE.main.js +0 -9
  170. package/dist/sv-SE.main.js.map +0 -1
  171. package/dist/sv-SE.mjs +0 -11
  172. package/dist/sv-SE.module.js +0 -11
  173. package/dist/sv-SE.module.js.map +0 -1
  174. package/dist/tr-TR.main.js +0 -9
  175. package/dist/tr-TR.main.js.map +0 -1
  176. package/dist/tr-TR.mjs +0 -11
  177. package/dist/tr-TR.module.js +0 -11
  178. package/dist/tr-TR.module.js.map +0 -1
  179. package/dist/types.d.ts +0 -253
  180. package/dist/types.d.ts.map +0 -1
  181. package/dist/uk-UA.main.js +0 -9
  182. package/dist/uk-UA.main.js.map +0 -1
  183. package/dist/uk-UA.mjs +0 -11
  184. package/dist/uk-UA.module.js +0 -11
  185. package/dist/uk-UA.module.js.map +0 -1
  186. package/dist/useDateFieldState.main.js +0 -377
  187. package/dist/useDateFieldState.main.js.map +0 -1
  188. package/dist/useDateFieldState.mjs +0 -372
  189. package/dist/useDateFieldState.module.js +0 -372
  190. package/dist/useDateFieldState.module.js.map +0 -1
  191. package/dist/useDatePickerState.main.js +0 -141
  192. package/dist/useDatePickerState.main.js.map +0 -1
  193. package/dist/useDatePickerState.mjs +0 -136
  194. package/dist/useDatePickerState.module.js +0 -136
  195. package/dist/useDatePickerState.module.js.map +0 -1
  196. package/dist/useDateRangePickerState.main.js +0 -268
  197. package/dist/useDateRangePickerState.main.js.map +0 -1
  198. package/dist/useDateRangePickerState.mjs +0 -263
  199. package/dist/useDateRangePickerState.module.js +0 -263
  200. package/dist/useDateRangePickerState.module.js.map +0 -1
  201. package/dist/useTimeFieldState.main.js +0 -89
  202. package/dist/useTimeFieldState.main.js.map +0 -1
  203. package/dist/useTimeFieldState.mjs +0 -84
  204. package/dist/useTimeFieldState.module.js +0 -84
  205. package/dist/useTimeFieldState.module.js.map +0 -1
  206. package/dist/utils.main.js +0 -200
  207. package/dist/utils.main.js.map +0 -1
  208. package/dist/utils.mjs +0 -189
  209. package/dist/utils.module.js +0 -189
  210. package/dist/utils.module.js.map +0 -1
  211. package/dist/zh-CN.main.js +0 -9
  212. package/dist/zh-CN.main.js.map +0 -1
  213. package/dist/zh-CN.mjs +0 -11
  214. package/dist/zh-CN.module.js +0 -11
  215. package/dist/zh-CN.module.js.map +0 -1
  216. package/dist/zh-TW.main.js +0 -9
  217. package/dist/zh-TW.main.js.map +0 -1
  218. package/dist/zh-TW.mjs +0 -11
  219. package/dist/zh-TW.module.js +0 -11
  220. package/dist/zh-TW.module.js.map +0 -1
  221. package/src/IncompleteDate.ts +0 -392
  222. package/src/placeholders.ts +0 -109
  223. package/src/useDateFieldState.ts +0 -478
  224. package/src/useDatePickerState.ts +0 -203
  225. package/src/useDateRangePickerState.ts +0 -330
  226. package/src/useTimeFieldState.ts +0 -99
  227. package/src/utils.ts +0 -272
@@ -1,392 +0,0 @@
1
- /*
2
- * Copyright 2026 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {AnyDateTime, Calendar, CalendarDate, ZonedDateTime} from '@internationalized/date';
14
- import {DateValue} from '@react-types/datepicker';
15
- import {SegmentType} from './useDateFieldState';
16
-
17
- type HourCycle = 'h12' | 'h11' | 'h23' | 'h24';
18
-
19
- /**
20
- * This class represents a date that is incomplete or otherwise invalid as a result of user editing.
21
- * For example, it can represent temporary dates such as February 31st if the user edits the day before the month.
22
- * Times are represented according to an hour cycle rather than always in 24 hour time. This enables the user to adjust
23
- * the day period (e.g. am/pm) independently from the hour.
24
- */
25
- export class IncompleteDate {
26
- calendar: Calendar;
27
- era: string | null;
28
- year: number | null;
29
- month: number | null;
30
- day: number | null;
31
- hour: number | null;
32
- hourCycle: HourCycle;
33
- dayPeriod: number | null;
34
- minute: number | null;
35
- second: number | null;
36
- millisecond: number | null;
37
- offset: number | null;
38
-
39
- constructor(calendar: Calendar, hourCycle: HourCycle, dateValue?: Partial<Omit<AnyDateTime, 'copy'>> | null) {
40
- this.era = dateValue?.era ?? null;
41
- this.calendar = calendar;
42
- this.year = dateValue?.year ?? null;
43
- this.month = dateValue?.month ?? null;
44
- this.day = dateValue?.day ?? null;
45
- this.hour = dateValue?.hour ?? null;
46
- this.hourCycle = hourCycle;
47
- this.dayPeriod = null;
48
- this.minute = dateValue?.minute ?? null;
49
- this.second = dateValue?.second ?? null;
50
- this.millisecond = dateValue?.millisecond ?? null;
51
- this.offset = 'offset' in (dateValue ?? {}) ? (dateValue as any).offset : null;
52
-
53
- // Convert the hour from 24 hour time to the given hour cycle.
54
- if (this.hour != null) {
55
- let [dayPeriod, hour] = toHourCycle(this.hour, hourCycle);
56
- this.dayPeriod = dayPeriod;
57
- this.hour = hour;
58
- }
59
- }
60
-
61
- copy(): IncompleteDate {
62
- let res = new IncompleteDate(this.calendar, this.hourCycle);
63
- res.era = this.era;
64
- res.year = this.year;
65
- res.month = this.month;
66
- res.day = this.day;
67
- res.hour = this.hour;
68
- res.dayPeriod = this.dayPeriod;
69
- res.minute = this.minute;
70
- res.second = this.second;
71
- res.millisecond = this.millisecond;
72
- res.offset = this.offset;
73
- return res;
74
- }
75
-
76
- /** Checks whether all the specified segments have a value. */
77
- isComplete(segments: SegmentType[]) {
78
- return segments.every(segment => this[segment] != null);
79
- }
80
-
81
- /** Checks whether the given date value matches this value for the specified segments. */
82
- validate(dt: DateValue, segments: SegmentType[]) {
83
- return segments.every(segment => {
84
- if ((segment === 'hour' || segment === 'dayPeriod') && 'hour' in dt) {
85
- let [dayPeriod, hour] = toHourCycle(dt.hour, this.hourCycle);
86
- return this.dayPeriod === dayPeriod && this.hour === hour;
87
- }
88
- return this[segment] === dt[segment];
89
- });
90
- }
91
-
92
- /** Checks if the date is empty (i.e. all specified segments are null). */
93
- isCleared(segments: SegmentType[]): boolean {
94
- return segments.every(segment => this[segment] === null);
95
- }
96
-
97
- /** Sets the given field. */
98
- set(field: SegmentType, value: number | string, placeholder: DateValue): IncompleteDate {
99
- let result = this.copy();
100
- result[field] = value;
101
- if (field === 'hour' && result.dayPeriod == null && 'hour' in placeholder) {
102
- result.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
103
- }
104
- if (field === 'year' && result.era == null) {
105
- result.era = placeholder.era;
106
- }
107
-
108
- // clear offset when a date/time field changes since it may no longer be valid
109
- if (field !== 'second' && field !== 'literal' && field !== 'timeZoneName') {
110
- result.offset = null;
111
- }
112
- return result;
113
- }
114
-
115
- /** Sets the given field to null. */
116
- clear(field: SegmentType): IncompleteDate {
117
- let result = this.copy();
118
- // @ts-ignore
119
- result[field] = null;
120
- if (field === 'year') {
121
- result.era = null;
122
- }
123
-
124
- // clear offset when a field is cleared since it may no longer be valid
125
- result.offset = null;
126
- return result;
127
- }
128
-
129
- /** Increments or decrements the given field. If it is null, then it is set to the placeholder value. */
130
- cycle(field: SegmentType, amount: number, placeholder: DateValue, displaySegments: SegmentType[]): IncompleteDate {
131
- let res = this.copy();
132
-
133
- // If field is null, default to placeholder.
134
- if (res[field] == null && field !== 'dayPeriod' && field !== 'era') {
135
- if (field === 'hour' && 'hour' in placeholder) {
136
- let [dayPeriod, hour] = toHourCycle(placeholder.hour, this.hourCycle);
137
- res.dayPeriod = dayPeriod;
138
- res.hour = hour;
139
- } else {
140
- res[field] = placeholder[field];
141
- }
142
- if (field === 'year' && res.era == null) {
143
- res.era = placeholder.era;
144
- }
145
-
146
- return res;
147
- }
148
-
149
- switch (field) {
150
- case 'era': {
151
- let eras = this.calendar.getEras();
152
- let index = eras.indexOf(res.era!);
153
- index = cycleValue(index, amount, 0, eras.length - 1);
154
- res.era = eras[index];
155
- break;
156
- }
157
- case 'year': {
158
- // Use CalendarDate to cycle so that we update the era when going between 1 AD and 1 BC.
159
- let date = new CalendarDate(this.calendar, this.era ?? placeholder.era, this.year ?? placeholder.year, this.month ?? 1, this.day ?? 1);
160
- date = date.cycle(field, amount, {round: field === 'year'});
161
- res.era = date.era;
162
- res.year = date.year;
163
- break;
164
- }
165
- case 'month':
166
- res.month = cycleValue(res.month ?? 1, amount, 1, this.calendar.getMaximumMonthsInYear());
167
- break;
168
- case 'day':
169
- // Allow incrementing up to the maximum number of days in any month.
170
- res.day = cycleValue(res.day ?? 1, amount, 1, this.calendar.getMaximumDaysInMonth());
171
- break;
172
- case 'hour': {
173
- // 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
174
- // so DST fallback is properly handled
175
- let hasDateSegements = displaySegments.some(s => ['year', 'month', 'day'].includes(s));
176
- if ('timeZone' in placeholder && (!hasDateSegements || (res.year != null && res.month != null && res.day != null))) {
177
- let date = this.toValue(placeholder) as ZonedDateTime;
178
- date = date.cycle('hour', amount, {hourCycle: this.hourCycle === 'h12' ? 12 : 24, round: false});
179
- let [dayPeriod, adjustedHour] = toHourCycle(date.hour, this.hourCycle);
180
- res.hour = adjustedHour;
181
- res.dayPeriod = dayPeriod;
182
- res.offset = date.offset;
183
- } else {
184
- let hours = res.hour ?? 0;
185
- let limits = this.getSegmentLimits('hour')!;
186
- res.hour = cycleValue(hours, amount, limits.minValue, limits.maxValue);
187
- if (res.dayPeriod == null && 'hour' in placeholder) {
188
- res.dayPeriod = toHourCycle(placeholder.hour, this.hourCycle)[0];
189
- }
190
- }
191
- break;
192
- }
193
- case 'dayPeriod':
194
- res.dayPeriod = cycleValue(res.dayPeriod ?? 0, amount, 0, 1);
195
- break;
196
- case 'minute':
197
- res.minute = cycleValue(res.minute ?? 0, amount, 0, 59, true);
198
- break;
199
- case 'second':
200
- res.second = cycleValue(res.second ?? 0, amount, 0, 59, true);
201
- break;
202
- }
203
-
204
- return res;
205
- }
206
-
207
- /** Converts the incomplete date to a full date value, using the provided value for any unset fields. */
208
- toValue(value: DateValue): DateValue {
209
- if ('hour' in value) {
210
- let hour = this.hour;
211
- if (hour != null) {
212
- hour = fromHourCycle(hour, this.dayPeriod ?? 0, this.hourCycle);
213
- } else if (this.hourCycle === 'h12' || this.hourCycle === 'h11') {
214
- hour = this.dayPeriod === 1 ? 12 : 0;
215
- }
216
-
217
- let res = value.set({
218
- era: this.era ?? value.era,
219
- year: this.year ?? value.year,
220
- month: this.month ?? value.month,
221
- day: this.day ?? value.day,
222
- hour: hour ?? value.hour,
223
- minute: this.minute ?? value.minute,
224
- second: this.second ?? value.second,
225
- millisecond: this.millisecond ?? value.millisecond
226
- });
227
-
228
- if ('offset' in res && this.offset != null && res.offset !== this.offset) {
229
- res = res.add({milliseconds: res.offset - this.offset});
230
- }
231
-
232
- return res;
233
- } else {
234
- return value.set({
235
- era: this.era ?? value.era,
236
- year: this.year ?? value.year,
237
- month: this.month ?? value.month,
238
- day: this.day ?? value.day
239
- });
240
- }
241
- }
242
-
243
- getSegmentLimits(type: string): {value: number | null, minValue: number, maxValue: number} | undefined {
244
- switch (type) {
245
- case 'era': {
246
- let eras = this.calendar.getEras();
247
- return {
248
- value: this.era != null ? eras.indexOf(this.era) : eras.length - 1,
249
- minValue: 0,
250
- maxValue: eras.length - 1
251
- };
252
- }
253
- case 'year':
254
- return {
255
- value: this.year,
256
- minValue: 1,
257
- maxValue: 9999
258
- };
259
- case 'month':
260
- return {
261
- value: this.month,
262
- minValue: 1,
263
- maxValue: this.calendar.getMaximumMonthsInYear()
264
- };
265
- case 'day':
266
- return {
267
- value: this.day,
268
- minValue: 1,
269
- maxValue: this.calendar.getMaximumDaysInMonth()
270
- };
271
- case 'dayPeriod': {
272
- return {
273
- value: this.dayPeriod,
274
- minValue: 0,
275
- maxValue: 1
276
- };
277
- }
278
- case 'hour': {
279
- let minValue = 0;
280
- let maxValue = 23;
281
- if (this.hourCycle === 'h12') {
282
- minValue = 1;
283
- maxValue = 12;
284
- } else if (this.hourCycle === 'h11') {
285
- minValue = 0;
286
- maxValue = 11;
287
- }
288
-
289
- return {
290
- value: this.hour,
291
- minValue,
292
- maxValue
293
- };
294
- }
295
- case 'minute':
296
- return {
297
- value: this.minute,
298
- minValue: 0,
299
- maxValue: 59
300
- };
301
- case 'second':
302
- return {
303
- value: this.second,
304
- minValue: 0,
305
- maxValue: 59
306
- };
307
- }
308
- }
309
- }
310
-
311
- function cycleValue(value: number, amount: number, min: number, max: number, round = false) {
312
- if (round) {
313
- value += Math.sign(amount);
314
-
315
- if (value < min) {
316
- value = max;
317
- }
318
-
319
- let div = Math.abs(amount);
320
- if (amount > 0) {
321
- value = Math.ceil(value / div) * div;
322
- } else {
323
- value = Math.floor(value / div) * div;
324
- }
325
-
326
- if (value > max) {
327
- value = min;
328
- }
329
- } else {
330
- value += amount;
331
- if (value < min) {
332
- value = max - (min - value - 1);
333
- } else if (value > max) {
334
- value = min + (value - max - 1);
335
- }
336
- }
337
-
338
- return value;
339
- }
340
-
341
- function toHourCycle(hour: number, hourCycle: HourCycle): [number | null, number] {
342
- let dayPeriod: number | null = hour >= 12 ? 1 : 0;
343
- switch (hourCycle) {
344
- case 'h11':
345
- // Hours are numbered from 0 to 11. Used in Japan.
346
- if (hour >= 12) {
347
- hour -= 12;
348
- }
349
- break;
350
- case 'h12':
351
- // Hours are numbered from 12 (representing 0) to 11.
352
- if (hour === 0) {
353
- hour = 12;
354
- } else if (hour > 12) {
355
- hour -= 12;
356
- }
357
- break;
358
- case 'h23':
359
- // 24 hour time, numbered 0 to 23.
360
- dayPeriod = null;
361
- break;
362
- case 'h24':
363
- // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.
364
- hour += 1;
365
- dayPeriod = null;
366
- }
367
-
368
- return [dayPeriod, hour];
369
- }
370
-
371
- function fromHourCycle(hour: number, dayPeriod: number, hourCycle: HourCycle): number {
372
- switch (hourCycle) {
373
- case 'h11':
374
- if (dayPeriod === 1) {
375
- hour += 12;
376
- }
377
- break;
378
- case 'h12':
379
- if (hour === 12) {
380
- hour = 0;
381
- }
382
- if (dayPeriod === 1) {
383
- hour += 12;
384
- }
385
- break;
386
- case 'h24':
387
- hour -= 1;
388
- break;
389
- }
390
-
391
- return hour;
392
- }
@@ -1,109 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {LocalizedStringDictionary} from '@internationalized/string';
14
-
15
- // These placeholders are based on the strings used by the <input type="date">
16
- // implementations in Chrome and Firefox. Additional languages are supported
17
- // here than React Spectrum's typical translations.
18
- const placeholders = new LocalizedStringDictionary({
19
- ach: {year: 'mwaka', month: 'dwe', day: 'nino'},
20
- af: {year: 'jjjj', month: 'mm', day: 'dd'},
21
- am: {year: 'ዓዓዓዓ', month: 'ሚሜ', day: 'ቀቀ'},
22
- an: {year: 'aaaa', month: 'mm', day: 'dd'},
23
- ar: {year: 'سنة', month: 'شهر', day: 'يوم'},
24
- ast: {year: 'aaaa', month: 'mm', day: 'dd'},
25
- az: {year: 'iiii', month: 'aa', day: 'gg'},
26
- be: {year: 'гггг', month: 'мм', day: 'дд'},
27
- bg: {year: 'гггг', month: 'мм', day: 'дд'},
28
- bn: {year: 'yyyy', month: 'মিমি', day: 'dd'},
29
- br: {year: 'bbbb', month: 'mm', day: 'dd'},
30
- bs: {year: 'gggg', month: 'mm', day: 'dd'},
31
- ca: {year: 'aaaa', month: 'mm', day: 'dd'},
32
- cak: {year: 'jjjj', month: 'ii', day: "q'q'"},
33
- ckb: {year: 'ساڵ', month: 'مانگ', day: 'ڕۆژ'},
34
- cs: {year: 'rrrr', month: 'mm', day: 'dd'},
35
- cy: {year: 'bbbb', month: 'mm', day: 'dd'},
36
- da: {year: 'åååå', month: 'mm', day: 'dd'},
37
- de: {year: 'jjjj', month: 'mm', day: 'tt'},
38
- dsb: {year: 'llll', month: 'mm', day: 'źź'},
39
- el: {year: 'εεεε', month: 'μμ', day: 'ηη'},
40
- en: {year: 'yyyy', month: 'mm', day: 'dd'},
41
- eo: {year: 'jjjj', month: 'mm', day: 'tt'},
42
- es: {year: 'aaaa', month: 'mm', day: 'dd'},
43
- et: {year: 'aaaa', month: 'kk', day: 'pp'},
44
- eu: {year: 'uuuu', month: 'hh', day: 'ee'},
45
- fa: {year: 'سال', month: 'ماه', day: 'روز'},
46
- ff: {year: 'hhhh', month: 'll', day: 'ññ'},
47
- fi: {year: 'vvvv', month: 'kk', day: 'pp'},
48
- fr: {year: 'aaaa', month: 'mm', day: 'jj'},
49
- fy: {year: 'jjjj', month: 'mm', day: 'dd'},
50
- ga: {year: 'bbbb', month: 'mm', day: 'll'},
51
- gd: {year: 'bbbb', month: 'mm', day: 'll'},
52
- gl: {year: 'aaaa', month: 'mm', day: 'dd'},
53
- he: {year: 'שנה', month: 'חודש', day: 'יום'},
54
- hr: {year: 'gggg', month: 'mm', day: 'dd'},
55
- hsb: {year: 'llll', month: 'mm', day: 'dd'},
56
- hu: {year: 'éééé', month: 'hh', day: 'nn'},
57
- ia: {year: 'aaaa', month: 'mm', day: 'dd'},
58
- id: {year: 'tttt', month: 'bb', day: 'hh'},
59
- it: {year: 'aaaa', month: 'mm', day: 'gg'},
60
- ja: {year: '年', month: '月', day: '日'},
61
- ka: {year: 'წწწწ', month: 'თთ', day: 'რრ'},
62
- kk: {year: 'жжжж', month: 'аа', day: 'кк'},
63
- kn: {year: 'ವವವವ', month: 'ಮಿಮೀ', day: 'ದಿದಿ'},
64
- ko: {year: '연도', month: '월', day: '일'},
65
- lb: {year: 'jjjj', month: 'mm', day: 'dd'},
66
- lo: {year: 'ປປປປ', month: 'ດດ', day: 'ວວ'},
67
- lt: {year: 'mmmm', month: 'mm', day: 'dd'},
68
- lv: {year: 'gggg', month: 'mm', day: 'dd'},
69
- meh: {year: 'aaaa', month: 'mm', day: 'dd'},
70
- ml: {year: 'വർഷം', month: 'മാസം', day: 'തീയതി'},
71
- ms: {year: 'tttt', month: 'mm', day: 'hh'},
72
- nb: {year: 'åååå', month: 'mm', day: 'dd'},
73
- nl: {year: 'jjjj', month: 'mm', day: 'dd'},
74
- nn: {year: 'åååå', month: 'mm', day: 'dd'},
75
- no: {year: 'åååå', month: 'mm', day: 'dd'},
76
- oc: {year: 'aaaa', month: 'mm', day: 'jj'},
77
- pl: {year: 'rrrr', month: 'mm', day: 'dd'},
78
- pt: {year: 'aaaa', month: 'mm', day: 'dd'},
79
- rm: {year: 'oooo', month: 'mm', day: 'dd'},
80
- ro: {year: 'aaaa', month: 'll', day: 'zz'},
81
- ru: {year: 'гггг', month: 'мм', day: 'дд'},
82
- sc: {year: 'aaaa', month: 'mm', day: 'dd'},
83
- scn: {year: 'aaaa', month: 'mm', day: 'jj'},
84
- sk: {year: 'rrrr', month: 'mm', day: 'dd'},
85
- sl: {year: 'llll', month: 'mm', day: 'dd'},
86
- sr: {year: 'гггг', month: 'мм', day: 'дд'},
87
- sv: {year: 'åååå', month: 'mm', day: 'dd'},
88
- szl: {year: 'rrrr', month: 'mm', day: 'dd'},
89
- tg: {year: 'сссс', month: 'мм', day: 'рр'},
90
- th: {year: 'ปปปป', month: 'ดด', day: 'วว'},
91
- tr: {year: 'yyyy', month: 'aa', day: 'gg'},
92
- uk: {year: 'рррр', month: 'мм', day: 'дд'},
93
- 'zh-CN': {year: '年', month: '月', day: '日'},
94
- 'zh-TW': {year: '年', month: '月', day: '日'}
95
- }, 'en');
96
-
97
- export function getPlaceholder(field: string, value: string, locale: string): string {
98
- // Use the actual placeholder value for the era and day period fields.
99
- if (field === 'era' || field === 'dayPeriod') {
100
- return value;
101
- }
102
-
103
- if (field === 'year' || field === 'month' || field === 'day') {
104
- return placeholders.getStringForLocale(field, locale);
105
- }
106
-
107
- // For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
108
- return '––';
109
- }