@@ -126,19 +126,38 @@ export function enumerateHourStarts(sinceTime: string, untilTime: string): reado
126126 return starts ;
127127}
128128
129+ /** Hour fields for the hourly labels. Without `hour12` they keep the `en-US` 12-hour clock. */
130+ function hourOptions ( hour12 : boolean | undefined ) : Intl . DateTimeFormatOptions {
131+ if ( hour12 === undefined ) return { hour : "numeric" } ;
132+ return hour12 ? { hour : "numeric" , hourCycle : "h12" } : { hour : "2-digit" , hourCycle : "h23" } ;
133+ }
134+
135+ /**
136+ * Formats an hour label. Like `2 PM`, a 24-hour label names the whole hour, so
137+ * it reads `14:00` even when the rolling bucket starts at 14:37. A bare `14`
138+ * does not read as a time.
139+ */
140+ function formatHour ( format : Intl . DateTimeFormat , date : Date , hour12 : boolean | undefined ) : string {
141+ if ( hour12 !== false ) return format . format ( date ) ;
142+ return format
143+ . formatToParts ( date )
144+ . map ( ( part ) => ( part . type === "hour" ? `${ part . value } :00` : part . value ) )
145+ . join ( "" ) ;
146+ }
147+
129148/**
130149 * A rolling bucket start rendered in the viewer's requested time zone.
131150 *
132151 * Repeated wall-clock hours during a fall-back transition include their short
133152 * zone name so the two distinct buckets remain distinguishable.
134153 */
135- export function formatHourShort ( hourStart : string , timeZone ?: string ) : string {
154+ export function formatHourShort ( hourStart : string , timeZone ?: string , hour12 ?: boolean ) : string {
136155 const instant = new Date ( hourStart ) ;
137156 if ( Number . isNaN ( instant . getTime ( ) ) ) return hourStart ;
138157 const options = timeZone === undefined ? { } : { timeZone } ;
139158 const hourFormat = dateTimeFormatter ( "en-US" , {
140159 ...options ,
141- hour : "numeric" ,
160+ ... hourOptions ( hour12 ) ,
142161 } ) ;
143162 const wallHourFormat = dateTimeFormatter ( "en-CA" , {
144163 ...options ,
@@ -153,36 +172,39 @@ export function formatHourShort(hourStart: string, timeZone?: string): string {
153172 ( offset ) => wallHourFormat . format ( new Date ( instant . getTime ( ) + offset ) ) === wallHour ,
154173 ) ;
155174
156- if ( ! isRepeatedHour ) return hourFormat . format ( instant ) ;
157- return dateTimeFormatter ( "en-US" , {
158- ...( timeZone === undefined ? { } : { timeZone } ) ,
159- hour : "numeric" ,
175+ if ( ! isRepeatedHour ) return formatHour ( hourFormat , instant , hour12 ) ;
176+ const zonedHourFormat = dateTimeFormatter ( "en-US" , {
177+ ...options ,
178+ ... hourOptions ( hour12 ) ,
160179 timeZoneName : "short" ,
161- } ) . format ( instant ) ;
180+ } ) ;
181+ return formatHour ( zonedHourFormat , instant , hour12 ) ;
162182}
163183
164- /** `2026-08-11T14:37:00Z` to `Aug 11, 2 PM` in the requested zone. */
165- export function formatDateTimeShort ( instant : string , timeZone ?: string ) : string {
184+ /** `2026-08-11T14:37:00Z` to `Aug 11, 2 PM` (or `Aug 11, 14:00`) in the requested zone. */
185+ export function formatDateTimeShort ( instant : string , timeZone ?: string , hour12 ?: boolean ) : string {
166186 const date = new Date ( instant ) ;
167187 if ( Number . isNaN ( date . getTime ( ) ) ) return instant ;
168- return dateTimeFormatter ( "en-US" , {
188+ const dateHourFormat = dateTimeFormatter ( "en-US" , {
169189 ...( timeZone === undefined ? { } : { timeZone } ) ,
170190 month : "short" ,
171191 day : "numeric" ,
172- hour : "numeric" ,
173- } ) . format ( date ) ;
192+ ...hourOptions ( hour12 ) ,
193+ } ) ;
194+ return formatHour ( dateHourFormat , date , hour12 ) ;
174195}
175196
176197/** An hourly tooltip label relative to the rolling window's end date. */
177198export function formatRelativeHourShort (
178199 hourStart : string ,
179200 relativeTo : string ,
180201 timeZone ?: string ,
202+ hour12 ?: boolean ,
181203) : string {
182204 const instant = new Date ( hourStart ) ;
183205 const reference = new Date ( relativeTo ) ;
184206 if ( Number . isNaN ( instant . getTime ( ) ) || Number . isNaN ( reference . getTime ( ) ) ) {
185- return formatDateTimeShort ( hourStart , timeZone ) ;
207+ return formatDateTimeShort ( hourStart , timeZone , hour12 ) ;
186208 }
187209
188210 const dayFormat = dateTimeFormatter ( "en-CA" , {
@@ -194,11 +216,11 @@ export function formatRelativeHourShort(
194216 const instantDay = Date . parse ( `${ dayFormat . format ( instant ) } T00:00:00Z` ) ;
195217 const referenceDay = Date . parse ( `${ dayFormat . format ( reference ) } T00:00:00Z` ) ;
196218 const calendarDaysAgo = Math . round ( ( referenceDay - instantDay ) / ( 24 * HOUR_MS ) ) ;
197- const hour = formatHourShort ( hourStart , timeZone ) ;
219+ const hour = formatHourShort ( hourStart , timeZone , hour12 ) ;
198220
199221 if ( calendarDaysAgo === 0 ) return `${ hour } today` ;
200222 if ( calendarDaysAgo === 1 ) return `${ hour } yesterday` ;
201- return formatDateTimeShort ( hourStart , timeZone ) ;
223+ return formatDateTimeShort ( hourStart , timeZone , hour12 ) ;
202224}
203225
204226/**
0 commit comments