Created
April 13, 2012 01:54
-
-
Save aackerman/2372854 to your computer and use it in GitHub Desktop.
Fuzzy Time
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
Convert Unix time in seconds to a fuzzy timestamp since the current time: 4s, 9m, 2d, 1m, etc. | |
var fuzzy_time = function (a) { | |
var b = new Date, | |
c = parseInt(((b.getTime() / 1e3) - a), 10), | |
d = ""; | |
return c < 60 ? d = c + "s" : c < 120 ? d = "1m" : c < 2700 ? d = parseInt(c / 60, 10).toString() + "m" : c < 7200 ? d = "1h" : c < 86400 ? d = "" + parseInt(c / 3600, 10).toString() + "h" : c < 172800 ? d = "1d" : d = parseInt(c / 86400, 10).toString() + "d", d | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment