Created
April 14, 2020 04:43
-
-
Save himalay/a77cb4582ec4c6c373fa6e5a16568d2a to your computer and use it in GitHub Desktop.
timeago #js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/odyniec/tinyAgo-js/ | |
function ago(val) { | |
val = 0 | (Date.now() - val) / 1000; | |
var unit, length = { second: 60, minute: 60, hour: 24, day: 7, week: 4.35, | |
month: 12, year: 10000 }, result; | |
for (unit in length) { | |
result = val % length[unit]; | |
if (!(val = 0 | val / length[unit])) | |
return result + ' ' + (result-1 ? unit + 's' : unit); | |
} | |
} | |
// minified | |
function ago(v){v=0|(Date.now()-v)/1e3;var a,b={second:60,minute:60,hour:24,day:7,week:4.35,month:12,year:1e4},c;for(a in b){c=v%b[a];if(!(v=0|v/b[a]))return c+' '+(c-1?a+'s':a)}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment