I have defined a set of rules.
var rules = [
time : "12:00:00 pm",
time1 : "01:00:00 pm",
time : "01:00:00 pm",
time1 : "02:00:00 pm",
time : "02:00:00 pm",
time1 : "03:00:00 pm",
time : "03:00:00 pm",
time1 : "04:00:00 pm",
time : "04:00:00 pm",
time1 : "05:00:00 pm",
module.exports = rules;
// 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
console.log(rule.time); //12:00:00 pm
// Not able to reach here tried both isAfter
// isBefore everything.
I tried to debug your code and have some observations -
moment(d).isAfter - here, moment(d) does not have a method called "isAfter". This is a strange thing as it should have this method as per the documentation. I had to call the prototype method like below -
var protoType = moment(start_time).__proto__; var isafter = protoType.isAfter(rule.time);
But, this led me to another issue - Maximum call stack size exceeded (Stack Overflowed ;p).
So, based on the observations, I would suggest you to not rip off the date part from the date by formatting it before comparing, since I guess it is required.