Created
December 3, 2012 18:57
-
-
Save SideQuestDIY/4197107 to your computer and use it in GitHub Desktop.
moment.js - displayEventDate
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
<html> | |
<head> | |
<script src="https://raw.github.com/timrwood/moment/master/moment.js"></script> | |
<script type="text/javascript"> | |
function displayEventDate(startDate, endDate, alertDate){ | |
startDate = moment.unix(startDate); | |
endDate = moment.unix(endDate); | |
var theEventDate = null; | |
//Same Day? | |
if(startDate.diff(endDate, 'days') === 0){ | |
theEventDate = startDate.format('MMMM Do, YYYY'); | |
} else { | |
//Diff Day, Same Year? | |
if(startDate.format('YYYY') === endDate.format('YYYY')){ | |
//Diff Day, Same Year, Same Month? | |
if(startDate.format('M') === endDate.format('M')){ | |
theEventDate = startDate.format('MMMM Do') + ' - ' + endDate.format('Do, YYYY'); | |
} else { | |
//Diff Day, Same Year, Diff Month | |
theEventDate = startDate.format('MMMM Do') + ' - ' + endDate.format('MMMM Do, YYYY'); | |
} | |
} else { | |
//Diff Day, Diff Year | |
theEventDate = startDate.format('MMMM Do, YYYY') + ' - ' + endDate.format('MMMM Do, YYYY'); | |
} | |
} | |
return theEventDate; | |
} | |
//displayEventDate('1318681876','1318681876'); // October 15th, 2011 | |
//displayEventDate('1318681876','1318781876'); // October 15th - 16th, 2011 | |
//displayEventDate('1320085943','1320172343'); // October 31st - November 1th, 2011 | |
//displayEventDate('1325288163','1325547363'); // Dec 30, 2011 - Jan 2, 2012 | |
</script> | |
</head> | |
<body> | |
<h1> | |
<script type="text/javascript"> | |
document.write(displayEventDate('1318681876','1318781876')); | |
</script> | |
</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment