Created
June 21, 2013 22:46
-
-
Save jmparsons/5834894 to your computer and use it in GitHub Desktop.
Simple coffeescript method to convert a unix timestamp to a twitter date.
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
twd = (time) -> | |
date = new Date(time * 1e3) | |
diff = ((+new Date - date.getTime()) / 1e3) | |
ddiff = Math.floor(diff / 86400) | |
d = date.getDate() | |
m = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[date.getMonth()] | |
y = date.getFullYear().toString().slice(2) | |
return if isNaN(ddiff) or ddiff < 0 | |
ddiff is 0 and (diff < 60 and Math.floor(diff) + "s" or diff < 3600 and Math.floor(diff / 60) + "m" or diff < 86400 and Math.floor(diff / 3600) + "h") or ddiff < 365 and d + " " + m or ddiff >= 365 and d + " " + m + " " + y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment