-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider <time> improvements #1023
Comments
Many 😉
Formatting durations is very useful but in general I think using an ISO duration can be a little unwieldy. I believe a more natural API for developers retrieving dates will likely be getting 2 dates from their DB, or comparing a date to "now" (which must be allowed to be an implicit value rather than a fixed date to allow for effective page caching). So e.g.
In
FWIW the main issue here is that Other notable things:We have quite a bit of guidance in the primer docs around relative time. It's worth a read, in my opinion. ThresholdsWe have an option for "Live" Timers
Elapsed TimersWe also offer an AccessibilityAccessibility for these times is... problematic. IIRC ATs don't do anything special with the |
There hasn't been any discussion on this issue for a while, so we're marking it as stale. If you choose to kick off the discussion again, we'll remove the 'stale' label. |
The
<time>
element has itsdatetime
attribute that expresses a point in time or a duration, but it doesn't use that to improve the information the user sees. https://github.com/github/relative-time-element and https://shoelace.style/components/relative-time have a group of behaviors that improve on this, and I think we should consider importing them into HTML.I see 4 kinds of behaviors that might be useful:
Auto-formatting durations like
<time datetime="P3DT7H">
Neither library handles this, and the only reason to do it on the client would be to auto-match the user's locale, which is also available through
Accept-Language
on the server. I'd call this low priority.Auto-formatting points in time like
<time datetime="2024-03-28T10:57:32Z">
Available through
<relative-time datetime="2024-04-01T16:30:00Z" format="datetime">
but not available in<sl-relative-time>
.The benefit to this is in matching the user's timezone, which is not sent to the server by default.
<relative-time>
also omits the year if it's the current year.The behavior here is nearly all defined by
Intl.DateTimeFormat
, except that the behavior of dropping the year is custom. That behavior resembles the wayformatRange
can drop part of the second date if it repeats part of the first date, exceptformatRange
doesn't currently drop the year (at least in en-US), and it can drop the whole date part.Representing points-in-time as offsets from now
This has 2 sub-options:
Use terms like "tomorrow"
This is the default behavior of both libraries, as
<relative-time datetime="2024-04-01T16:30:00Z">
or<sl-relative-time date="2020-07-15T09:17:00-04:00">
, and they show strings like "now", "2 minutes ago", "yesterday", or "3 days from now".<relative-time>
updates that offset in real-time while<sl-relative-time>
only does so if thesync
attribute is given.The output is produced using
Intl.RelativeTimeFormat
, but the conversion from a duration to the arguments ofRelativeTimeFormat.format()
(in particular, when to jump to the next unit) isn't standardized.Show just the duration
Available through
<relative-time datetime="2024-04-01T16:30:00Z" format="duration">
but not available in<sl-relative-time>
.There's a Stage 3 proposal for the rendering of this at https://github.com/tc39/proposal-intl-duration-format.
@keithamus maintains
<relative-time>
and probably has opinions. :)The text was updated successfully, but these errors were encountered: