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 --save
Usage
As early as possible in your application, require and configure last seen
.Check it following Rules.
getLastSeen()
//require last-seen-ago moduleconst lastSeenAgo = ; //for example your real time timestamp 1602050284const realTime = 1602050284; //get exact last seen according to timeconst lastSeen = lastSeenAgo //print output will be "34 minutes ago"console
Rules
The parsing timstamp support the following rules:
- To
timestamp
value should bedouble
data type. - To get the
timestamp
asseconds
. 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
divide
it 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-DD or yyyy-mm-dd |
2020-10-12 |
YYYY-DD-MM or YYYY-DD-MM |
2020-12-10 |
MM-DD-YYYY or mm-dd-yyyy |
10-12-2020 |
DD-MM-YYYY or DD-MM-YYYY |
12-10-2020 |
YYYY-MM-DD HH:MM:SS or yyyy-mm-dd hh:mm:ss |
2020-10-12 11:26:1 |
YYYY-DD-MM HH:MM:SS or YYYY-DD-MM hh:mm:ss |
2020-12-10 11:26:1 |
MM-DD-YYYY HH:MM:SS or mm-dd-yyyy hh:mm:ss |
10-12-2020 11:26:1 |
DD-MM-YYYY HH:MM:SS or DD-MM-YYYY hh:mm:ss |
12-10-2020 11:26:1 |
YYYY.MM.DD or yyyy.mm.dd |
2020.10.12 |
YYYY.DD.MM or YYYY.DD.MM |
2020.12.10 |
MM.DD.YYYY or mm.dd.yyyy |
10.12.2020 |
DD.MM.YYYY or DD.MM.YYYY |
12.10.2020 |
YYYY.MM.DD HH:MM:SS or yyyy.mm.dd hh:mm:ss |
2020.10.12 11:26:1 |
YYYY.DD.MM HH:MM:SS or YYYY.DD.MM hh:mm:ss |
2020.12.10 11:26:1 |
MM.DD.YYYY HH:MM:SS or mm.dd.yyyy hh:mm:ss |
10.12.2020 11:26:1 |
DD.MM.YYYY HH:MM:SS or DD.MM.YYYY hh:mm:ss |
12.10.2020 11:26:1 |
YYYY/MM/DD or yyyy/mm/dd |
2020/10/12 |
YYYY/DD/MM or YYYY/DD/MM |
2020/12/10 |
MM/DD/YYYY or mm/dd/yyyy |
10/12/2020 |
DD/MM/YYYY or DD/MM/YYYY |
12/10/2020 |
YYYY/MM/DD HH:MM:SS or yyyy/mm/dd hh:mm:ss |
2020/10/12 11:26:1 |
YYYY/DD/MM HH:MM:SS or YYYY/DD/MM hh:mm:ss |
2020/12/10 11:26:1 |
MM/DD/YYYY HH:MM:SS or mm/dd/yyyy hh:mm:ss |
10/12/2020 11:26:1 |
DD/MM/YYYY HH:MM:SS or DD/MM/YYYY hh:mm:ss |
12/10/2020 11:26:1 |
YYYY MM DD or yyyy mm dd |
2020 10 12 |
YYYY DD MM or YYYY DD MM |
2020 12 10 |
MM DD YYYY or mm dd yyyy |
10 12 2020 |
DD MM YYYY or DD MM YYYY |
12 10 2020 |
YYYY MM DD HH:MM:SS or yyyy mm dd hh:mm:ss |
2020 10 12 11:26:1 |
YYYY DD MM HH:MM:SS or YYYY DD MM hh:mm:ss |
2020 12 10 11:26:1 |
MM DD YYYY HH:MM:SS or mm dd yyyy hh:mm:ss |
10 12 2020 11:26:1 |
DD MM YYYY HH:MM:SS or DD 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 moduleconst lastSeenAgo = ; //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 //print output will be 2020-12-10"console
Future Plan
More features added soon like.