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
Is your feature request related to a problem? Please describe.
format.relativeTime currently only supports returning a relative time using an automatically calculated unit in this function.
However, there may be cases that we sometimes want to use a specific unit to develop an application.
For example, if we were to create a timeline UI that groups photos by date in a photo album app, we might want to specify the day unit when creating a title for the timeline, since, with other units, it might get too detailed.
Describe the solution you'd like
One solution I came up with is to add a unit argument to relativeTime function, like this:
constdateTime=newDate('2020-11-20T00:00:00Z');constnow=newDate('2020-11-20T01:00:00Z');constformat=useFormatter();format.relativeTime(dateTime,now,'day');// returns 'today', not '1 hour'
Describe alternatives you've considered
We can also use RelativeTimeFormat directly instead:
Maybe we should accept an object, in case we allow to configure further properties in the future. E.g. {unit: 'day'}.
now is an optional parameter, maybe we should overload the second argument to avoid something like format.relativeTime(dateTime, undefined, {unit: 'day'}).
Based on this, format.relativeTime(dateTime: Date, nowOrOptions: Date | {now?: Date, unit?: string}) could be an idea.
What do you think? Would you be interested in contributing this feature and the corresponding docs?
This PR adds the `relativeTime` options to support custom units and
updates the documentation accordingly.
Close: #565
---------
Co-authored-by: Jan Amann <[email protected]>
Is your feature request related to a problem? Please describe.
format.relativeTime
currently only supports returning a relative time using an automatically calculated unit in this function.However, there may be cases that we sometimes want to use a specific unit to develop an application.
For example, if we were to create a timeline UI that groups photos by date in a photo album app, we might want to specify the
day
unit when creating a title for the timeline, since, with other units, it might get too detailed.Describe the solution you'd like
One solution I came up with is to add a
unit
argument to relativeTime function, like this:Describe alternatives you've considered
We can also use
RelativeTimeFormat
directly instead:The text was updated successfully, but these errors were encountered: