I am trying to pull server data into Jade and then use the data to run through a function in order to determine what class to automatically select. This is used on tables to auto colour cells, depending on the value of the cell.
function to run the returned data through (date diff):
function inDays(date1,date2) {
var date1=date1.split('/');
var date2=date2.split('/');
var d1=new Date(date1[1]+'/'+date1[0]+'/'+date1[2]);
console.log(d1);
var d2=new Date(date2[1]+'/'+date2[0]+'/'+date2[2]);
console.log(d2);
var t2=d2.getTime();
var t1=d1.getTime();
var days=parseInt((t2-t1)/(24*3600*1000));
return days
}
desired usage:
td(class!='<%- #{inDays(<%= dateCompareAgainst %>, <%= date %>)} < 5 ? "green" : "orange"') <%= date %>
this however does not work.
when I put the following:
td(class='#{inDays(<%= dateCompareAgainst %>, <%= date %>)}') <%= date %>
it shows the two dates in the class as expected. I'm at a loss on how to do this correctly, any help would be appreciated.