You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am starting to use <relative-time> in an app that supports multiple languages and users are in different countries. I started with the basics and just set the datetime attribute and inner text.
I noticed the automatic title always had short months. I tried to change it by setting formatStyle="long" and month="long" to no avail. Inspecting the source I found that titles use a fixed format:
// Internal: Format the ISO 8601 timestamp according to the user agent's
// locale-aware formatting rules. The element's existing `title` attribute
// value takes precedence over this custom format.
//
// Returns a formatted time String.
#getFormattedTitle(date: Date): string|undefined{
returnnewIntl.DateTimeFormat(this.#lang,{
day: 'numeric',
month: 'short',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
timeZoneName: 'short',
}).format(date)
}
Thanks to the comment in the code above, I was able to temporarily solve for my use case by rendering the title from the server side, but that meant giving up showing the time in the timezone of the browser.
Would you consider re-using the style settings when formatting the title or provide a specific formatting rule for the title, independent from the inner text?
PS: Related, but less important, it would also be useful to add some text around the date, like title="Updated at {formatted-date-here}" (where the string "Updated at" is rendered in the correct locale on the server).
Thanks again!
The text was updated successfully, but these errors were encountered:
Hello, and thanks for this custom element!
I am starting to use
<relative-time>
in an app that supports multiple languages and users are in different countries. I started with the basics and just set thedatetime
attribute and inner text.I noticed the automatic
title
always had short months. I tried to change it by settingformatStyle="long"
andmonth="long"
to no avail. Inspecting the source I found that titles use a fixed format:relative-time-element/src/relative-time-element.ts
Lines 116 to 130 in 7e40806
Thanks to the comment in the code above, I was able to temporarily solve for my use case by rendering the title from the server side, but that meant giving up showing the time in the timezone of the browser.
Would you consider re-using the style settings when formatting the title or provide a specific formatting rule for the title, independent from the inner text?
PS: Related, but less important, it would also be useful to add some text around the date, like
title="Updated at {formatted-date-here}"
(where the string "Updated at" is rendered in the correct locale on the server).Thanks again!
The text was updated successfully, but these errors were encountered: