I have an issue where I am not sure how to calculate if it is one hour or less between a dispatch date and the current time using the JS Date object. what I have done so far is I converted the entity.dispatchDate string into a Date object, however this case that I have written so far returns true whenever todaysDate date object is equal to or greater than the dispatch date. What I think I have to do is first of all, not use 1 hour but instead use minutes, as I need to account for every scenario that is within that hour - e.g. if its one hour before, 15 minutes, or 30 minutes to return true. What I have written so far:
// OPTIONS
const hoursBeforeSendout = 1;
// END OF OPTIONS
if(!entity.dispatchDate) {
return false;
}
var sendDate = new Date(Date.parse(entity.dispatchDate));
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + (h*60*60*1000));
return this;
}
var todaysDate = new Date();
todaysDate.addHours(hoursBeforeSendout);
if(todaysDate >= sendDate) {
return true;
}
return false;
I would appreciate any input here on what the best approach would be