MCPcopy Index your code
hub / github.com/ionic-team/ionic-framework / getFormattedHour

Function getFormattedHour

core/src/components/datetime/utils/format.ts:105–136  ·  view source on GitHub ↗
(hour: number, hourCycle: DatetimeHourCycle)

Source from the content-addressed store, hash-verified

103 * hour 0 is formatted as '12'.
104 */
105export const getFormattedHour = (hour: number, hourCycle: DatetimeHourCycle): string => {
106 /**
107 * Midnight for h11 starts at 0:00am
108 * Midnight for h12 starts at 12:00am
109 * Midnight for h23 starts at 00:00
110 * Midnight for h24 starts at 24:00
111 */
112 if (hour === 0) {
113 switch (hourCycle) {
114 case 'h11':
115 return '0';
116 case 'h12':
117 return '12';
118 case 'h23':
119 return '00';
120 case 'h24':
121 return '24';
122 default:
123 throw new Error(`Invalid hour cycle "${hourCycle}"`);
124 }
125 }
126
127 const use24Hour = is24Hour(hourCycle);
128 /**
129 * h23 and h24 use 24 hour times.
130 */
131 if (use24Hour) {
132 return addTimePadding(hour);
133 }
134
135 return hour.toString();
136};
137
138/**
139 * Generates an aria-label to be read by screen readers

Callers 2

getTimeColumnsDataFunction · 0.90
format.spec.tsFile · 0.90

Calls 2

is24HourFunction · 0.90
addTimePaddingFunction · 0.85

Tested by

no test coverage detected