@radulucut/relative
TypeScript icon, indicating that this package has built-in type declarations

2.0.5 • Public • Published

relative (Relative Time Format)

npm npm GitHub

Format the relative time between the current date and a given date in a human readable format. The output is rounded to the nearest time unit, i.e. 1 year ago, 5 minutes ago, in 3 days, in 6 seconds.

Built on top of the Intl.RelativeTimeFormat API. Supports multiple languages and custom formatting options.

Install

$ npm install @radulucut/relative --save

Usage

import Time from "@radulucut/relative";

const time = Time();
time.Relative(new Date("2024-01-01T00:00:00.000Z")); // "2 months ago"

const timeRO = Time("ro", { numeric: "auto" });
timeRO.Relative(new Date("2024-05-01T00:00:00.000Z")); // "peste 2 luni"

const timeES = Time("es", { style: "long" });
timeES.Relative(new Date("2024-01-01T00:00:00.000Z")); // "hace 2 meses"

Package Sidebar

Install

npm i @radulucut/relative

Weekly Downloads

23

Version

2.0.5

License

MIT

Unpacked Size

7.67 kB

Total Files

5

Last publish

Collaborators

  • radulucut