Created
August 14, 2008 21:02
-
-
Save jessehattabaugh/5491 to your computer and use it in GitHub Desktop.
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
function niceDate(date) { | |
if(typeof date == 'object') { | |
if(Date.today().compareTo(date) == -1) return 'today' | |
else if(Date.today().add({days:-1}).compareTo(date) == -1) return 'yesterday' | |
else return date.toString('MM/dd/yy') | |
} else return '02/24/82' | |
} | |
function niceTime(date) { | |
if(typeof date == 'object') { | |
if(date > (1).minutes().ago()) | |
return new Date(new Date() - date).toString('s')+" seconds ago" | |
else if(date > (1).hours().ago()) | |
return new Date(new Date() - date).toString('m')+" minutes ago" | |
else if(date > (1).days().ago()) | |
return 'today at '+date.toString('h:mm') | |
else if(Date.today().add({days:-1}).compareTo(date) == -1) | |
return 'yesterday at '+date.toString('h:mm') | |
else | |
return date.toString('MM/dd/yy h:mm') | |
} else return '02/24/82' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment