1.1.0 • Published 5 years ago
last-seen-ago v1.1.0
last-seen-ago
last-seen-ago is a zero-dependency module that highly customizable real time to last seen like Facebook,Twitter,Instagram...
It is a simple one line code ,Its automatically converts to given timestamp in the right units like seconds, minutes, hours, days,weeks, years using getLastSeen() method.
Examples:
- Juts Now
- 45 seconds
- one minute ago
- 15 minutes ago
- an hour ago
- 2 hrs ago
- yesterday
- 2 days ago
- a week ago
- 2 weeks ago
- …
Installation
npm install last-seen-ago --saveUsage
As early as possible in your application, require and configure last seen.Check it following Rules.
###getLastSeen()
//require last-seen-ago module
const lastSeenAgo = require("last-seen-ago");
//for example your real time timestamp 1602050284
const realTime = 1602050284;
//get exact last seen according to time
const lastSeen = lastSeenAgo.getLastSeen(realTime)
//print output will be "34 minutes ago"
console.log(lastSeen)Rules
The parsing timstamp support the following rules:
- To timestampvalue should bedoubledata type.
- To get the timestampasseconds. For example- To get the timestamp Date.now()method can be called.
- Note that this method returns the timestamp in milliseconds.
- To get the timestamp as seconds we can divideit by1000.
 
- To get the timestamp 
Given are the following formats:
- Format type 1 with backslashes (/) as the separator characters.
- Format type 2 with dashes (-) as the separator characters.
- Format type 3 with dots (.) as the separator characters.
- Format type 4 with spaces ( ) as the separator characters.
| Type | Example | 
|---|---|
| YYYY-MM-DDoryyyy-mm-dd | 2020-10-12 | 
| YYYY-DD-MMorYYYY-DD-MM | 2020-12-10 | 
| MM-DD-YYYYormm-dd-yyyy | 10-12-2020 | 
| DD-MM-YYYYorDD-MM-YYYY | 12-10-2020 | 
| YYYY-MM-DD HH:MM:SSoryyyy-mm-dd hh:mm:ss | 2020-10-12 11:26:1 | 
| YYYY-DD-MM HH:MM:SSorYYYY-DD-MM hh:mm:ss | 2020-12-10 11:26:1 | 
| MM-DD-YYYY HH:MM:SSormm-dd-yyyy hh:mm:ss | 10-12-2020 11:26:1 | 
| DD-MM-YYYY HH:MM:SSorDD-MM-YYYY hh:mm:ss | 12-10-2020 11:26:1 | 
| YYYY.MM.DDoryyyy.mm.dd | 2020.10.12 | 
| YYYY.DD.MMorYYYY.DD.MM | 2020.12.10 | 
| MM.DD.YYYYormm.dd.yyyy | 10.12.2020 | 
| DD.MM.YYYYorDD.MM.YYYY | 12.10.2020 | 
| YYYY.MM.DD HH:MM:SSoryyyy.mm.dd hh:mm:ss | 2020.10.12 11:26:1 | 
| YYYY.DD.MM HH:MM:SSorYYYY.DD.MM hh:mm:ss | 2020.12.10 11:26:1 | 
| MM.DD.YYYY HH:MM:SSormm.dd.yyyy hh:mm:ss | 10.12.2020 11:26:1 | 
| DD.MM.YYYY HH:MM:SSorDD.MM.YYYY hh:mm:ss | 12.10.2020 11:26:1 | 
| YYYY/MM/DDoryyyy/mm/dd | 2020/10/12 | 
| YYYY/DD/MMorYYYY/DD/MM | 2020/12/10 | 
| MM/DD/YYYYormm/dd/yyyy | 10/12/2020 | 
| DD/MM/YYYYorDD/MM/YYYY | 12/10/2020 | 
| YYYY/MM/DD HH:MM:SSoryyyy/mm/dd hh:mm:ss | 2020/10/12 11:26:1 | 
| YYYY/DD/MM HH:MM:SSorYYYY/DD/MM hh:mm:ss | 2020/12/10 11:26:1 | 
| MM/DD/YYYY HH:MM:SSormm/dd/yyyy hh:mm:ss | 10/12/2020 11:26:1 | 
| DD/MM/YYYY HH:MM:SSorDD/MM/YYYY hh:mm:ss | 12/10/2020 11:26:1 | 
| YYYY MM DDoryyyy mm dd | 2020 10 12 | 
| YYYY DD MMorYYYY DD MM | 2020 12 10 | 
| MM DD YYYYormm dd yyyy | 10 12 2020 | 
| DD MM YYYYorDD MM YYYY | 12 10 2020 | 
| YYYY MM DD HH:MM:SSoryyyy mm dd hh:mm:ss | 2020 10 12 11:26:1 | 
| YYYY DD MM HH:MM:SSorYYYY DD MM hh:mm:ss | 2020 12 10 11:26:1 | 
| MM DD YYYY HH:MM:SSormm dd yyyy hh:mm:ss | 10 12 2020 11:26:1 | 
| DD MM YYYY HH:MM:SSorDD MM YYYY hh:mm:ss | 12 10 2020 11:26:1 | 
Some Short formats
| Type | Example | 
|---|---|
| Y/m/d H:m:s | 2020/10/12 11:26:1 | 
| Y/d/m H:m:s | 2020/12/10 11:26:1 | 
| m/d/Y H:m:s | 10/12/2020 11:26:1 | 
| d/m/Y H:m:s | 12/10/2020 11:26:1 | 
| Y-m-d H:m:s | 2020-10-12 11:26:1 | 
| Y-d-m H:m:s | 2020-12-10 11:26:1 | 
| m-d-Y H:m:s | 10-12-2020 11:26:1 | 
| d-m-Y H:m:s | 12-10-2020 11:26:1 | 
| Y.m.d H:m:s | 2020.10.12 11:26:1 | 
| Y.d.m H:m:s | 2020.12.10 11:26:1 | 
| m.d.Y H:m:s | 10.12.2020 11:26:1 | 
| d.m.Y H:m:s | 12.10.2020 11:26:1 | 
###getFormat()
//require last-seen-ago module
const lastSeenAgo = require("last-seen-ago");
//if timestamp in 1602495292171(miliseconds),then converts timestamp in seconds divide it by 1000.
const realTime = 1602495292171;
//if timestamp in 1602495292 (seconds).
const realTime = 1602495292;
//get exact last seen according to timestmap and specific format.
const lastSeen = lastSeenAgo.getFormat(realTime,'YYYY-MM-DD')
//print output will be 2020-12-10"
console.log(lastSeen)Future Plan
More features added soon like.