since-time-ago
since-time-ago converts timestamps into readable format
Formats a timestamp to:
- just now
- 3 minutes ago
- 5 hours ago
- 8 days ago
- 6 months ago
- 4 years ago
Install
$ npm i since-time-ago
Use
This module exports a main function 'since()' that takes one argument 'timestamp' and returns timestamp formated in a readable form:
; // Timestamps for one minute, one hour, one day, one month and one yearconst minute = 60 * 1000;const hour = 60 * minute;const day = 24 * hour;const month = 30 * day;const year = 12 * month; // simulating different inputsconst nowTimestamp = ; // nowconst fiveMinutesAgoTimestamp = nowTimestamp - 5 * minute; // timestamp for 5 minutes agoconst fiveHoursAgoTimestamp = nowTimestamp - 5 * hour; // timestamp for 5 hours agoconst fiveDaysAgoTimestamp = nowTimestamp - 5 * day; // timestamp for 5 days agoconst fiveMonthsAgoTimestamp = nowTimestamp - 5 * month; // timestamp for 5 months agoconst fiveYearsAgoTimestamp = nowTimestamp - 5 * year; // timestamp for 5 years ago // using since(); // returns undefined; // throws an Error; // returns 'just now'; // returns '5 minutes ago'; // returns '5 hours ago'; // returns '5 days ago'; // returns '5 months ago'; // returns '5 years ago'