Receks
5/20/2019 - 7:48 AM

Relative Time Format

Supports all languages out of the box and does not increase bundle size, because the translations should be provided by the browser

const rtf = new Intl.RelativeTimeFormat('en', {numeric: 'auto'});

rtf.format(-1, 'day'); // -> yesterday
rtf.format(0, 'day'); // -> today
rtf.format(1, 'day'); // -> tomorrow 
// ... seconds, week, month, quarter, ...