Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions collections/date-time/format-relative-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```javascript
const rtf = (value, unit) => new Intl.RelativeTimeFormat('en').format(value, unit);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const rtf = (value, unit) => new Intl.RelativeTimeFormat('en').format(value, unit);
const rtf = (value, unit, locale = 'en') => new Intl.RelativeTimeFormat(locale).format(value, unit);


/*
value - Numeric value to use in the internationalized relative time message.
unit - Unit to use in the relative time internationalized message.
Possible values are: "year", "quarter", "month", "week", "day", "hour", "minute", "second".
Plural forms are also permitted.
*/
Copy link

@WiXSL WiXSL Dec 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*/
locale - String representing the locale to be used. Defaults to "en"
*/

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the local could be passed as an optional parameter.


// Example
rtf(5, 'day'); // in 5 days
rtf(-3, 'day'); // 3 days ago
rtf(2, 'minutes'); // in 2 min
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rtf(2, 'minutes'); // in 2 min
rtf(2, 'minutes'); // in 2 min
rtf(2, 'minutes', 'es'); // dentro de 2 minutos

```