I have defined a set of rules.
var rules = [
{
time : "12:00:00 pm",
time1 : "01:00:00 pm",
value:0
},
{
time : "01:00:00 pm",
time1 : "02:00:00 pm",
value:0
},
{
time : "02:00:00 pm",
time1 : "03:00:00 pm",
value:0
},
{
time : "03:00:00 pm",
time1 : "04:00:00 pm",
value:0
}, {
time : "04:00:00 pm",
time1 : "05:00:00 pm",
value:0
}
]
module.exports = rules;
Now I have got an array of data which consists of time I want to compare the dats with these rules and accordingly increment the value of status in the rules array. I am using moment.Js to compare but its isAfter() and isBefore functions are not working for me as they should.
_.each(data, function(data){
// this comes from database where data.start_time consists of time
console.log(data.start_time); // Mon Oct 03 2016 12:40:36 GMT+0530 (India Standard Time)
var d = moment(data.start_time).format("hh:mm:ss a");
console.log(d); //12:40:36 pm
_.each(rules, function(rule){
console.log(rule.time); //12:00:00 pm
if(moment(d).isAfter(rule.time))
{
// Not able to reach here tried both isAfter
// isBefore everything.
console.log("sasa");
}
})
});
Also if there is any faster or better way to do these kind of comparision please can you leave a gist below. I will check that out too.