Skip to content

fix(utils): pick the timezone abbreviation from the UTC offset, not the formatted date - #9923

Open
laoyyu wants to merge 1 commit into
simstudioai:mainfrom
laoyyu:fix/timezone-abbreviation-from-offset
Open

laoyyu wants to merge 1 commit into
simstudioai:mainfrom
laoyyu:fix/timezone-abbreviation-from-offset

Conversation

@laoyyu

@laoyyu laoyyu commented Nov 12, 2026

Copy link
Copy Markdown

What

getTimezoneAbbreviation decides between the standard and daylight label by comparing formatted strings:

const isDSTObserved = januaryFormatter.format(januaryDate) !== julyFormatter.format(julyDate)
...
const isDST = currentFormatter.format(date) !== januaryFormatter.format(januaryDate)

format() also renders the calendar date, which always differs between two dates, so for every zone in the map isDSTObserved was true and isDST was true too — the daylight label was returned all year:

getTimezoneAbbreviation('America/Los_Angeles', new Date('2026-01-15T12:00:00Z')) // 'PDT'
getTimezoneAbbreviation('Europe/London',        new Date('2026-01-15T12:00:00Z')) // 'BST'
getTimezoneAbbreviation('Australia/Sydney',     new Date('2026-07-15T12:00:00Z')) // 'AEDT'
formatDateTime(new Date('2026-01-15T12:00:00Z'), 'America/Los_Angeles')
// 'Jan 15, 2026, 4:00 AM PDT' — the local time is PST

Fix

Compare the zone's UTC offsets at the two ends of the year instead of formatted strings (getOffsetMinutes, derived from Intl.formatToParts, since Date has no timezone-aware offset accessor):

  • equal offsets → the zone does not observe DST → the standard label;
  • otherwise the smaller offset is standard time, and a larger offset on the target date means daylight time. Daylight time moves the clock forward in both hemispheres, so Sydney and Los Angeles are handled by the same rule.

How it was checked

  • packages/utils/src/formatting.test.ts gains four cases: winter/summer for northern zones, the inverted seasons for Australia/Sydney, and zones without DST (Asia/Tokyo, Asia/Singapore).
  • The same 13 zone/date expectations were executed on Node 22 against the patched logic: all hold (PST/PDT, GMT/BST, CET/CEST, EST/EDT, AEDT/AEST, JST, SGT).
  • tsc --noEmit --skipLibCheck on the patched file passes.

Fixes #9831. Prepared with an AI coding assistant; I reviewed the diff and ran the checks above.

…he formatted date

getTimezoneAbbreviation compared Intl.DateTimeFormat#format() results of two
dates in the same year. The formatted string always contains the calendar date,
so the comparison reported "DST is observed" for every zone and then "the target
date is daylight time" for every date: Los Angeles in January came out as PDT,
London as BST, Sydney in July as AEDT.

Compare the zone's UTC offsets at the two ends of the year instead. A zone whose
offsets match does not observe DST; otherwise the smaller offset is standard
time and any larger offset on the target date is daylight time, which covers
both hemispheres.
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@laoyyu is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches time-zone labels in date formatting and schedule summaries.

The timezone fix appears sound, but the added comment must meet the repository's explicit rules before merging.

Findings

  1. P2 Comment records change history ▶

Summary

getTimezoneAbbreviation now compares UTC offsets instead of formatted dates.

  • Mapped time-zone abbreviations match the season of the requested date.

Reviews (1) · Last reviewed commit: "fix(utils): pick the timezone abbreviati..." · Reviewed by Greptile

Comment on lines +60 to +62
// Compare the zone's UTC offsets across the year: `format()` always
// includes the calendar date, so comparing formatted strings reported
// "DST observed" for the whole year and then "daylight" for every date.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Comment records change history

The new comment recounts the previous bug, but CLAUDE.md says change history belongs in commit messages. Keep the explanation that format() includes the calendar date and remove the account of the old behavior. This repository requirement must be satisfied before merging.

Suggested change
// Compare the zone's UTC offsets across the year: `format()` always
// includes the calendar date, so comparing formatted strings reported
// "DST observed" for the whole year and then "daylight" for every date.
// Compare UTC offsets because `format()` also includes the calendar date.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Timezone formatter labels winter dates with daylight-time abbreviations

1 participant