Last active
August 29, 2015 13:57
-
-
Save nolanamy/9648537 to your computer and use it in GitHub Desktop.
Pretty dates
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
getDayName = function(day) | |
{ | |
return {0:"Sunday",1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday"}[day]; | |
}; | |
getDayDiffString = function(now, before) | |
{ | |
if((now - before) < 1000*60*60*24*5) | |
{ | |
var dayDiff = now.getDay() - before.getDay(); | |
if(dayDiff == 0) | |
{ | |
return "Today" | |
} | |
else if(dayDiff == 1 || dayDiff == -1) | |
{ | |
return "Yesterday"; | |
} | |
else | |
{ | |
return getDayName(before.getDay()) | |
} | |
} | |
else | |
{ | |
return before.toDateString(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes date is in the past...