Skip to content

Instantly share code, notes, and snippets.

@nolanamy
Last active August 29, 2015 13:57
Show Gist options
  • Save nolanamy/9648537 to your computer and use it in GitHub Desktop.
Save nolanamy/9648537 to your computer and use it in GitHub Desktop.
Pretty dates
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();
}
};
@nolanamy
Copy link
Author

Assumes date is in the past...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment