Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@yaireo/relative-time

yairEO8.9kMIT1.0.5TypeScript support: included

javascript function to transform timestamp or date to local relative-time

relative time, date, timestamp, javascript, js, local, locale

readme

Transform timestamp or date to local relative-time


Super lightweight (< 500 bytes)   🕙   Uses native browser API


Install:

NPM / CDN / Download from this repo

npm i @yaireo/relative-time -S

Usage:

Import:

import RelativeTime from '@yaireo/relative-time'

And use:

```js
const relativeTime = new RelativeTime(); // defaults to OS locale
const relativeTimeSpanish = new RelativeTime({ locale: 'es' }); // set Spanish locale

console.log(   relativeTime.from(new Date('2015'))  )  // "6 years ago"
console.log(   relativeTimeSpanish.from(new Date('2015'))  )  // "hace 6 años"

Live demo