Skip to content

Fix year check to use the display time zone instead of UTC - #384

Open
kwy404 wants to merge 1 commit into
github:mainfrom
kwy404:fix-year-in-display-time-zone
Open

kwy404 wants to merge 1 commit into
github:mainfrom
kwy404:fix-year-in-display-time-zone

Conversation

@kwy404

@kwy404 kwy404 commented Sep 26, 2026

Copy link
Copy Markdown

Root cause

When the year attribute is not set, the year getter decides whether to show the year with new Date().getUTCFullYear() !== this.date?.getUTCFullYear(). That compares UTC years, but the date is rendered in the element's time-zone (or the browser's). Near New Year the two disagree, so a date from last year can lose its year, or a date from this year can get one.

Example: with time-zone="America/New_York" and the current date in June 2023, datetime="2023-01-01T02:00:00.000Z" renders as Sat, Dec 31 instead of Sat, Dec 31, 2022.

Fix

Reuse the existing #isCurrentYear(date, locale, timeZone) helper (already used by the absolute time format), so the year is compared in the same time zone the date is displayed in. When there is no date the getter still returns 'numeric', as before.

Testing

Added a test in the [timeZone] suite for the example above.

  • Before: expected 'Sat, Dec 31' to equal 'Sat, Dec 31, 2022' (634 passed, 1 failed)
  • After: 635 passed, 0 failed
  • npm run lint passes

The default year option compared UTC years, so a date that falls in a
different calendar year in the element's time zone (or the browser's)
lost its year, or got one it did not need, near New Year.
@kwy404
kwy404 requested a review from a team as a code owner September 26, 2026 13:23

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.

1 participant