Created
July 21, 2014 00:35
This file contains hidden or 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
function relativeTime(pastdate) { | |
var delta = dateDiff("s", pastDate, now()); | |
if(delta < 60) { | |
return "less than a minute ago"; | |
} else if(delta < 120) { | |
return "about a minute ago"; | |
} else if(delta < (45*60)) { | |
return round(delta/60) & " minutes ago"; | |
} else if(delta < (90*60)) { | |
return "about an hour ago"; | |
} else if(delta < (24*60*60)) { | |
return round(delta/3600) & " hours ago"; | |
} else if(delta < (48*60*60)) { | |
return "1 day ago"; | |
} else if(delta < (7*48*60*60)) { | |
return round(delta/86400) & " days ago"; | |
} else { | |
return round(delta/ (86400*7)) & " weeks ago"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment