Variable.formatRelativeTime - sumup-oss/intl-js GitHub Wiki
@sumup-oss/intl / formatRelativeTime
Variable: formatRelativeTime
constformatRelativeTime: (value,unit,locales?,options?) =>string
Defined in: lib/relative-time-format/index.ts:49
Formats a relative time with support for various styles.
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
number |
- |
unit |
RelativeTimeFormatUnit |
- |
locales? |
string | string[] |
Formatting locale. Omitting this is deprecated and will become required in a future major version. When omitted, formatting uses the runtime default (browser or server locale), which may not match your user. |
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.