@@ -127,41 +127,44 @@ export function enumerateHourStarts(sinceTime: string, untilTime: string): reado
127127}
128128
129129/**
130- * A rolling bucket start rendered in the viewer's requested time zone.
131- *
132- * Repeated wall-clock hours during a fall-back transition include their short
133- * zone name so the two distinct buckets remain distinguishable.
130+ * True when the instant's wall-clock hour occurs twice in the zone, as during a
131+ * fall-back transition. Hour labels add the short zone name for these.
134132 */
135- export function formatHourShort ( hourStart : string , timeZone ?: string ) : string {
136- const instant = new Date ( hourStart ) ;
137- if ( Number . isNaN ( instant . getTime ( ) ) ) return hourStart ;
138- const options = timeZone === undefined ? { } : { timeZone } ;
139- const hourFormat = dateTimeFormatter ( "en-US" , {
140- ...options ,
141- hour : "numeric" ,
142- } ) ;
133+ function isRepeatedWallHour ( instant : Date , timeZone ?: string ) : boolean {
143134 const wallHourFormat = dateTimeFormatter ( "en-CA" , {
144- ...options ,
135+ ...( timeZone === undefined ? { } : { timeZone } ) ,
145136 year : "numeric" ,
146137 month : "2-digit" ,
147138 day : "2-digit" ,
148139 hour : "2-digit" ,
149140 hourCycle : "h23" ,
150141 } ) ;
151142 const wallHour = wallHourFormat . format ( instant ) ;
152- const isRepeatedHour = [ - HOUR_MS , HOUR_MS ] . some (
143+ return [ - HOUR_MS , HOUR_MS ] . some (
153144 ( offset ) => wallHourFormat . format ( new Date ( instant . getTime ( ) + offset ) ) === wallHour ,
154145 ) ;
146+ }
155147
156- if ( ! isRepeatedHour ) return hourFormat . format ( instant ) ;
148+ /**
149+ * A rolling bucket start rendered in the viewer's requested time zone.
150+ *
151+ * Repeated wall-clock hours during a fall-back transition include their short
152+ * zone name so the two distinct buckets remain distinguishable.
153+ */
154+ export function formatHourShort ( hourStart : string , timeZone ?: string ) : string {
155+ const instant = new Date ( hourStart ) ;
156+ if ( Number . isNaN ( instant . getTime ( ) ) ) return hourStart ;
157157 return dateTimeFormatter ( "en-US" , {
158158 ...( timeZone === undefined ? { } : { timeZone } ) ,
159159 hour : "numeric" ,
160- timeZoneName : "short" ,
160+ ... ( isRepeatedWallHour ( instant , timeZone ) ? { timeZoneName : "short" } : { } ) ,
161161 } ) . format ( instant ) ;
162162}
163163
164- /** `2026-08-11T14:37:00Z` to `Aug 11, 2 PM` in the requested zone. */
164+ /**
165+ * `2026-08-11T14:37:00Z` to `Aug 11, 2 PM` in the requested zone, with the
166+ * short zone name when that hour repeats during a fall-back transition.
167+ */
165168export function formatDateTimeShort ( instant : string , timeZone ?: string ) : string {
166169 const date = new Date ( instant ) ;
167170 if ( Number . isNaN ( date . getTime ( ) ) ) return instant ;
@@ -170,6 +173,7 @@ export function formatDateTimeShort(instant: string, timeZone?: string): string
170173 month : "short" ,
171174 day : "numeric" ,
172175 hour : "numeric" ,
176+ ...( isRepeatedWallHour ( date , timeZone ) ? { timeZoneName : "short" } : { } ) ,
173177 } ) . format ( date ) ;
174178}
175179
@@ -201,6 +205,11 @@ export function formatRelativeHourShort(
201205 return formatDateTimeShort ( hourStart , timeZone ) ;
202206}
203207
208+ /** Hourly buckets for windows up to a week, daily beyond that. */
209+ export function resolutionForWindow ( days : number ) : UsageResolution {
210+ return days <= 7 ? "hour" : "day" ;
211+ }
212+
204213/**
205214 * The window the page requests, expressed in the viewer's own time zone so days
206215 * line up with what they actually experienced.
@@ -232,10 +241,10 @@ export function makeWindow(
232241 const untilDay = format . format ( now ) ;
233242 if ( resolution === "hour" ) {
234243 // Minute-aligned bounds keep labels readable while still representing an
235- // exact rolling 24-hour duration. Fixed-duration buckets remain correct
236- // across offset changes and daylight-saving transitions.
244+ // exact rolling duration of `days` whole days . Fixed-duration buckets remain
245+ // correct across offset changes and daylight-saving transitions.
237246 const untilTimeMs = Math . floor ( now . getTime ( ) / 60_000 ) * 60_000 ;
238- const sinceTimeMs = untilTimeMs - 24 * HOUR_MS ;
247+ const sinceTimeMs = untilTimeMs - days * 24 * HOUR_MS ;
239248 const sinceTime = new Date ( sinceTimeMs ) ;
240249 const untilTime = new Date ( untilTimeMs ) ;
241250 return {
0 commit comments