openui / openui/open-ui

Consider <time> improvements

Open
#1,023 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
MDX
Stars
4.5k
Forks
226
Avg merge
2d 22h
Merged PRs (30d)
4

Description

The <time> element has its datetime 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 way formatRange can drop part of the second date if it repeats part of the first date, except formatRange 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 the sync attribute is given.

The output is produced using Intl.RelativeTimeFormat, but the conversion from a duration to the arguments of RelativeTimeFormat.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. :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the HTML element and compare the referenced github/relative-time-element and Shoelace relative-time behaviors. Review Intl.DateTimeFormat, Intl.RelativeTimeFormat, and the Intl.DurationFormat proposal, then determine which behavior is appropriate for HTML. Done means the scope and requirements are agreed rather than merely listing possible improvements.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
frontend, internationalization, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.