MCPcopy Create free account
hub / github.com/adobe/react-spectrum / toHourCycle

Function toHourCycle

packages/react-stately/src/datepicker/IncompleteDate.ts:370–398  ·  view source on GitHub ↗
(hour: number, hourCycle: HourCycle)

Source from the content-addressed store, hash-verified

368}
369
370function toHourCycle(hour: number, hourCycle: HourCycle): [number | null, number] {
371 let dayPeriod: number | null = hour >= 12 ? 1 : 0;
372 switch (hourCycle) {
373 case 'h11':
374 // Hours are numbered from 0 to 11. Used in Japan.
375 if (hour >= 12) {
376 hour -= 12;
377 }
378 break;
379 case 'h12':
380 // Hours are numbered from 12 (representing 0) to 11.
381 if (hour === 0) {
382 hour = 12;
383 } else if (hour > 12) {
384 hour -= 12;
385 }
386 break;
387 case 'h23':
388 // 24 hour time, numbered 0 to 23.
389 dayPeriod = null;
390 break;
391 case 'h24':
392 // 24 hour time numbered 24 to 23. Unused but supported by Intl.DateTimeFormat.
393 hour += 1;
394 dayPeriod = null;
395 }
396
397 return [dayPeriod, hour];
398}
399
400function fromHourCycle(hour: number, dayPeriod: number, hourCycle: HourCycle): number {
401 switch (hourCycle) {

Callers 4

constructorMethod · 0.85
validateMethod · 0.85
setMethod · 0.85
cycleMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected