Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save firefly05/5799075 to your computer and use it in GitHub Desktop.
Save firefly05/5799075 to your computer and use it in GitHub Desktop.
Traverse document for any element that has a due date. Then compare that date to today's date. Use the difference for whatever purpose you like. My original, color the table cells yellow if the item is due in two days or less
// get the current date
var now = new Date();
var curr_date = now.getDate();
var curr_month = now.getMonth() + 1;
var curr_year = now.getFullYear();
// format current date as it is in Redmine so we can do the math
var now = curr_month + '/' + curr_date + '/' + curr_year;
var now
console.log(now);
// find each table cell with a due date
$('.due_date').each(function(){
//find due date of this row
var date1 = new Date(now);
var date2 = new Date($(this).text());
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
// if it is due within two days, add due soon class
if(diffDays <= 2) {
$(this).parent().css('background-color','#ffffdd');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment