File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// @effect -diagnostics globalDate:off -- A fixed instant keeps calendar-window assertions deterministic.
2- import { describe , expect , it } from "vite-plus/test" ;
2+ import { describe , expect , it , vi } from "vite-plus/test" ;
33
44import {
55 enumerateHourStarts ,
@@ -54,4 +54,20 @@ describe("hourly usage formatting", () => {
5454 expect ( window . sinceTime ) . toBe ( "2026-08-10T12:37:00.000Z" ) ;
5555 expect ( window . untilTime ) . toBe ( "2026-08-11T12:37:00.000Z" ) ;
5656 } ) ;
57+
58+ it ( "degrades an unknown resolved zone to UTC instead of crashing" , ( ) => {
59+ const resolved = new Intl . DateTimeFormat ( ) . resolvedOptions ( ) ;
60+ const resolvedOptions = vi
61+ . spyOn ( Intl . DateTimeFormat . prototype , "resolvedOptions" )
62+ . mockReturnValue ( { ...resolved , timeZone : "Etc/Unknown" } ) ;
63+
64+ try {
65+ const now = new Date ( "2026-08-11T12:37:42.123Z" ) ;
66+
67+ expect ( makeWindow ( 1 , now , "hour" ) . timeZone ) . toBe ( "UTC" ) ;
68+ expect ( makeWindow ( 30 , now ) . timeZone ) . toBe ( "UTC" ) ;
69+ } finally {
70+ resolvedOptions . mockRestore ( ) ;
71+ }
72+ } ) ;
5773} ) ;
Original file line number Diff line number Diff line change @@ -179,13 +179,25 @@ export function makeWindow(
179179 now = new Date ( ) ,
180180 resolution : UsageResolution = "day" ,
181181) : UsageSummaryInput {
182- const timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone || "UTC" ;
183- const format = new Intl . DateTimeFormat ( "en-CA" , {
184- timeZone,
185- year : "numeric" ,
186- month : "2-digit" ,
187- day : "2-digit" ,
188- } ) ;
182+ let timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone || "UTC" ;
183+ let format : Intl . DateTimeFormat ;
184+ try {
185+ format = new Intl . DateTimeFormat ( "en-CA" , {
186+ timeZone,
187+ year : "numeric" ,
188+ month : "2-digit" ,
189+ day : "2-digit" ,
190+ } ) ;
191+ } catch {
192+ // An unknown zone should degrade to UTC rather than crash the page.
193+ timeZone = "UTC" ;
194+ format = new Intl . DateTimeFormat ( "en-CA" , {
195+ timeZone : "UTC" ,
196+ year : "numeric" ,
197+ month : "2-digit" ,
198+ day : "2-digit" ,
199+ } ) ;
200+ }
189201 const untilDay = format . format ( now ) ;
190202 if ( resolution === "hour" ) {
191203 // Minute-aligned bounds keep labels readable while still representing an
You can’t perform that action at this time.
0 commit comments