Control whether weekday names should be allowed, e.g. "2 Sundays ago". When enabled this will only emit a weekday name when the week field is being formatted and the start and end dates share the same weekday.
numericOnly?: boolean
Always use a format that includes a number, e.g. "1 day ago" instead of "Yesterday".
alwaysNow?: boolean
In numericOnly mode, if the value to be formatted is exactly zero, use the "now" format instead of a numeric format, e.g. "Today" instead of "In 0 days".
width?: RelativeTimeWidthType
Width of the unit of relative time: 'short' | 'narrow' | 'wide'
const cldr = framework.get('en');
const opts: RelativeTimeFormatOptions = { width: 'wide' };
const start = cldr.Calendars.toGregorianDate({ date: newDate(2019, 6, 11) });
const nums = [-5, -2, -1, 0, 1, 2, 5];
for (const n of nums) {
const end = start.add({ month: n });
let a = cldr.Calendars.formatRelativeTime(start, end, opts);
let b = cldr.Calendars.formatRelativeTime(start, end, { field: 'day', ...opts });
log(`${a} (${b})`);
}
5 months ago (150 days ago)
2 months ago (61 days ago)
last month (30 days ago)
now (today)
next month (in 31 days)
in 2 months (in 62 days)
in 5 months (in 153 days)
opts = { numericOnly: true };
for (const n of nums) {
const end = start.add({ month: n });
log(cldr.Calendars.formatRelativeTime(start, end, opts));
}
5 months ago
2 months ago
1 month ago
in 0 seconds
in 1 month
in 2 months
in 5 months
nums = [-2, -1, 0, 1, 2];
opts = { numericOnly: true, alwaysNow: true };
for (const n of nums) {
const end = start.add({ month: n });
log(cldr.Calendars.formatRelativeTime(start, end, opts));
}
2 months ago
1 month ago
now
in 1 month
in 2 months
for (const n of nums) {
const end = start.add({ month: n });
log(cldr.Calendars.formatRelativeTime(start, end, { ...opts, field: 'day' }));
}
61 days ago
30 days ago
today
in 31 days
in 62 days