1.0.10 • Published 2 years ago

relative-time-ago v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

relative-time-ago

relativeTimeAgo(date, key);

Returns a specified amount of time since a specified date.

Npm package

Github repo

Installation

npm install relative-time-ago

Usage

import relativeTimeAgo from "relative-time-ago";

- Inputs -

date - Either a date string or UNIX number.

key - What you want your time intervals to be relevant to..

  • year - returns number of years ago
  • month - returns number of months ago
  • day - returns number of days ago
  • hour - returns number of hours ago
  • minute - returns number of minutes ago
  • second - returns number of seconds ago

- Outputs -

By default will return the number of milliseconds between the given date and whenever relativeTimeAgo is called.

Alternatively, if given a key, will return a message:

console.log(relativeTimeAgo(date, 'second');

  ---> // X seconds ago

If the difference in time is less than the requested interval, a different message is returned:

console.log(relativeTimeAgo(dateLessThanAYearAgo, 'year');

  ---> // less than one year ago

If no key is given, the time since the given date is returned in milliseconds:

console.log(relativeTimeAgo(date);

  ---> // XXXXX milliseconds ago

If relativeTimeAgo is called without a date argument, check your console to see error.


Thanks for reading! Check out my portfolio at derekmason.dev

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago