Skip to content

Commit

Permalink
Removing hacks in sendAt that were needed when _getNextDateFrom wasn'…
Browse files Browse the repository at this point in the history
…t behaving properly
  • Loading branch information
jodevsa committed Aug 13, 2018
1 parent 2e572fd commit 98dad71
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions lib/cron.js
Expand Up @@ -124,16 +124,9 @@
return date;
}

//add 1 second so next time isn't now (can cause timeout to be 0 or negative number)
var now = new Date();
var targetSecond = date.seconds();
var diff = Math.abs(targetSecond - now.getSeconds())
// there was a problem when `date` is 1424777177999 and `now` is 1424777178000
// 1 ms diff but this is another second...
if ( diff == 0 || (diff == 1 && now.getMilliseconds() <= date.milliseconds() ) ) {
//console.log('add 1 second?');
date = date.add(1, 's');
}

//If the i argument is not given, return the next send time
if (isNaN(i) || i < 0) {
Expand All @@ -146,8 +139,7 @@
for (; i > 0; i--) {
date = this._getNextDateFrom(date);
dates.push(moment(date));
if (i > 1)
date.add(1,'s');

}

return dates;
Expand Down Expand Up @@ -272,13 +264,12 @@

if(date.valueOf()==start){
date.seconds(date.seconds()+1);
continue;
}

break;
}
if(origDate.valueOf()==start){
date.seconds(date.seconds()-1);
}

return date;
},

Expand Down

0 comments on commit 98dad71

Please sign in to comment.