Variable.formatRelativeTime - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatRelativeTime
Variable: formatRelativeTime()
const
formatRelativeTime: (value
,unit
,locales?
,options?
) =>string
Defined in: lib/relative-time-format/index.ts:44
Formats a relative time with support for various styles.
Parameters
Parameter | Type |
---|---|
value |
number |
unit |
RelativeTimeFormatUnit |
locales? |
string | string [] |
options? |
RelativeTimeFormatOptions |
Returns
string
Example
import { formatRelativeTime } from '@sumup-oss/intl';
formatRelativeTime(1, 'day', 'de-DE'); // 'in 1 Tag'
formatRelativeTime(7, 'years', ['pt-BR', 'pt']); // 'em 7 anos'
formatRelativeTime(-5, 'months', 'en-GB', {
style: 'narrow',
}); // '5 mo ago'
Remarks
In runtimes that don't support the Intl.RelativeTimeFormat
API,
the relative time is formatted using the Intl.NumberFormat
API instead.