Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/tzOffset/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const offsetCache: Record<string, number> = {};
* @returns UTC offset in minutes
*/
export function tzOffset(timeZone: string | undefined, date: Date): number {
if (timeZone! in offsetCache) return offsetCache[timeZone!]!;

try {
const format = (offsetFormatCache[timeZone!] ||= new Intl.DateTimeFormat(
"en-GB",
Expand All @@ -29,7 +31,6 @@ export function tzOffset(timeZone: string | undefined, date: Date): number {
} catch {
// Fallback to manual parsing if the runtime doesn't support 卤HH:MM/卤HHMM/卤HH
// See: https://github.com/nodejs/node/issues/53419
if (timeZone! in offsetCache) return offsetCache[timeZone!]!;
const captures = timeZone?.match(offsetRe);
if (captures) return calcOffset(timeZone!, captures.slice(1));

Expand Down