Conversation
zaataylor
approved these changes
Nov 25, 2025
| #isToday(date: Date): boolean { | ||
| const now = new Date() | ||
| const formatter = new Intl.DateTimeFormat(this.#lang, { | ||
| timeZone: this.timeZone, |
Contributor
There was a problem hiding this comment.
Nice, having this be sensitive to user's TZ will save us many-a bug report!
| } | ||
|
|
||
| if ((format === 'relative' || format === 'duration') && !displayUserPreferredAbsoluteTime) { | ||
| const shouldObserve = |
Contributor
There was a problem hiding this comment.
Thanks for breaking out that long conditional, this is much more readable to me
Comment on lines
+1978
to
+1991
| test('respects locale formatting', async () => { | ||
| freezeTime(new Date('2023-01-15T17:00:00.000Z')) | ||
|
|
||
| document.documentElement.setAttribute('data-prefers-absolute-time', 'true') | ||
| const el = document.createElement('relative-time') | ||
| el.setAttribute('lang', 'es-ES') | ||
| el.setAttribute('time-zone', 'Europe/Madrid') | ||
|
|
||
| el.setAttribute('datetime', '2023-01-15T17:00:00.000Z') | ||
| await Promise.resolve() | ||
|
|
||
| // Spanish formatting - "hoy" = "today", 24-hour format | ||
| assert.equal(el.shadowRoot.textContent, 'Hoy 18:00 CET') | ||
| }) |
Contributor
There was a problem hiding this comment.
This is the future! l10n!
| }) | ||
|
|
||
| suite('experimental: [data-prefers-absolute-time]', async () => { | ||
| teardown(() => { |
Contributor
There was a problem hiding this comment.
I had initially wondered if we'd need a test for the boundary condition of moving from Today to the full timestamp, but this should "just work" given how we have the observable behavior set up!
Contributor
llastflowers
left a comment
There was a problem hiding this comment.
Looks fine from Primer!
llastflowers
approved these changes
Nov 26, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes updates to our currently experimental feature! This PR updates the format when users prefer absolute time, to provide more contextual information for recent dates:
This was a decision based upon user feedback.
Approach
The desired format
Today, 2:34 PM EDTisn't natively supported byIntl.DateTimeFormat, so this PR makes a best attempt at it by combining:RelativeTimeFormat)DateTimeFormat)Assumptions & trade-offs
This approach assumes:
Alternative considered
Hard-coding this custom format for English-only, but feels unideal/inconsistent to special-case a format for english-only.
Examples
English:
TBD