@@ -6,19 +6,19 @@ export function detectCanadianTimezone(): string {
66 try {
77 // Use Intl API to get the IANA timezone identifier
88 const timeZone = Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ;
9-
9+
1010 // Map IANA timezone identifiers to Canadian timezone abbreviations
1111 const timezoneMap : Record < string , string > = {
1212 // Newfoundland Standard Time
1313 'America/St_Johns' : 'NST' ,
14-
14+
1515 // Atlantic Standard Time
1616 'America/Halifax' : 'AST' ,
1717 'America/Moncton' : 'AST' ,
1818 'America/Glace_Bay' : 'AST' ,
1919 'America/Goose_Bay' : 'AST' ,
2020 'America/Blanc-Sablon' : 'AST' ,
21-
21+
2222 // Eastern Standard Time
2323 'America/Toronto' : 'EST' ,
2424 'America/Montreal' : 'EST' ,
@@ -27,12 +27,12 @@ export function detectCanadianTimezone(): string {
2727 'America/Nipigon' : 'EST' ,
2828 'America/Rainy_River' : 'EST' ,
2929 'America/Atikokan' : 'EST' ,
30-
30+
3131 // Central Standard Time
3232 'America/Winnipeg' : 'CST' , // Manitoba uses Central Time
3333 'America/Regina' : 'CST' ,
3434 'America/Swift_Current' : 'CST' ,
35-
35+
3636 // Mountain Standard Time
3737 'America/Edmonton' : 'MST' ,
3838 'America/Calgary' : 'MST' ,
@@ -41,24 +41,24 @@ export function detectCanadianTimezone(): string {
4141 'America/Cambridge_Bay' : 'MST' ,
4242 'America/Dawson_Creek' : 'MST' ,
4343 'America/Fort_Nelson' : 'MST' ,
44-
44+
4545 // Pacific Standard Time
4646 'America/Vancouver' : 'PST' ,
4747 'America/Whitehorse' : 'PST' ,
4848 'America/Dawson' : 'PST' ,
4949 } ;
50-
50+
5151 // Check if we have a direct mapping
5252 if ( timezoneMap [ timeZone ] ) {
5353 return timezoneMap [ timeZone ] ;
5454 }
55-
55+
5656 // Fallback: Use timezone offset to estimate
5757 // Get UTC offset in hours (accounting for DST)
5858 const now = new Date ( ) ;
5959 const offsetMinutes = now . getTimezoneOffset ( ) ;
6060 const offsetHours = - offsetMinutes / 60 ; // Invert because getTimezoneOffset returns opposite sign
61-
61+
6262 // Map UTC offsets to Canadian timezones (accounting for DST)
6363 // During DST, offsets are shifted by 1 hour, so we map to standard time equivalents
6464 if ( offsetHours === - 3.5 || offsetHours === - 2.5 ) return 'NST' ; // Newfoundland (standard or daylight)
@@ -67,11 +67,10 @@ export function detectCanadianTimezone(): string {
6767 if ( offsetHours === - 6 || offsetHours === - 5 ) return 'CST' ; // Central (standard or daylight)
6868 if ( offsetHours === - 7 || offsetHours === - 6 ) return 'MST' ; // Mountain (standard or daylight)
6969 if ( offsetHours === - 8 || offsetHours === - 7 ) return 'PST' ; // Pacific (standard or daylight)
70-
70+
7171 return '' ;
7272 } catch ( error ) {
7373 console . warn ( 'Unable to detect timezone:' , error ) ;
7474 return '' ;
7575 }
7676}
77-
0 commit comments