rel-time-format
v5.1.2
Published
A simple wrapper for Intl.RelativeTimeFormat
Downloads
6
Readme
🕰️ rel-time-format
JavaScript library for human-friendly relative date formatting.
This is a simple wrapper for Intl.RelativeTimeFormat.
Installation
Using npm:
npm install rel-time-format
Using yarn:
yarn add rel-time-format
Usage
Important
The rel-time-format library is ESM.
The rel-time-format library is written using ECMAScript Internationalization API, which requires Node.js version 14 or higher.
import { getRelTime } from 'rel-time-format';
getRelTime(new Date(), new Date(), {
locales: 'en',
numeric: 'auto',
});
//=> now
getRelTime(new Date(2023, 0, 1), new Date('2022-12-01'), {
locales: 'ru',
style: 'short',
});
//=> через 1 мес.
import { getRelYears } from 'rel-time-format';
getRelYears(new Date('2000 Jan 1'), new Date('2022-01-01'), { locales: 'en' });
//=> 22 years ago
import { getDiffInCalendarDays } from 'rel-time-format';
getDiffInCalendarDays(
new Date('2022-01-01'),
new Date('2022-01-02T23:59:59'),
true
);
//=> 1
Documentation
Check out the documentation website.
Support
- Node.js >= 14
- Chrome >= 71
- Edge >= 79
- Firefox >= 65
- Opera >= 68
- Safari >= 14