Created
August 13, 2014 18:44
-
-
Save jforaker/d6f38632926055dcf631 to your computer and use it in GitHub Desktop.
Parse due dates with moment.js
This file contains hidden or 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
dues: function (expiresdate){ | |
var now = moment(), | |
due = moment(expiresdate).format("YYYY-MM-DD"), | |
todayMoment = moment().format("YYYY-MM-DD"), | |
dueFormatted = moment(expiresdate).format("MMMM Do YYYY"), | |
tmrw, yest, | |
dueInfo = { | |
color: '', | |
text: '' | |
}; | |
tmrw = moment(now.add('days', 1)).format("MMMM Do YYYY"); | |
yest = moment(now.subtract('days', 2)).format("MMMM Do YYYY"); | |
if(todayMoment == due){ | |
dueInfo.text = 'Due today'; | |
dueInfo.color = 'blue'; | |
}else{ | |
if(moment(due).isBefore(todayMoment)){ | |
dueInfo.color = 'red'; | |
if(dueFormatted === yest){ | |
dueInfo.text = "Due yesterday" + " " + dueFormatted; | |
}else{ | |
dueInfo.text = "Due " + dueFormatted; | |
} | |
}else{ | |
dueInfo.color = 'blue'; | |
if(dueFormatted == tmrw){ | |
dueInfo.text = "Due tomorrow: " + dueFormatted; | |
}else{ | |
dueInfo.text = "Due on " + dueFormatted; | |
} | |
} | |
} | |
return dueInfo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment