Skip to content

Commit

Permalink
fix issue when cronTime _getNextDateFrom not calculate correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
immanuel192 committed Aug 10, 2018
1 parent cfea445 commit 877ecee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/cron.js
Expand Up @@ -183,6 +183,13 @@
*/
_getNextDateFrom: function(start) {
var date = moment(start);
if (!this.realDate) {
const milliseconds = (start.milliseconds && start.milliseconds()) || (start.getMilliseconds && start.getMilliseconds()) || 0;
if (milliseconds > 0) {
date.milliseconds(0);
date.seconds(date.seconds() + 1);
}
}

if (date.toString() == 'Invalid date') {
console.log('ERROR: You specified an invalid date.');
Expand Down
12 changes: 12 additions & 0 deletions tests/test-crontime.js
Expand Up @@ -190,4 +190,16 @@ describe('crontime', function() {
}).to.throw(Error);
});
});

it('should strip off millisecond', ()=>{
const cronTime = new cron.CronTime('0 */10 * * * *');
const x = cronTime._getNextDateFrom(new Date("2018-08-10T02:20:00.999Z"));
expect(x.toISOString()).to.equal('2018-08-10T02:30:00.000Z');
});

it('should strip off millisecond (2)', ()=>{
const cronTime = new cron.CronTime('0 */10 * * * *');
const x = cronTime._getNextDateFrom(new Date("2018-08-10T02:19:59.999Z"));
expect(x.toISOString()).to.equal('2018-08-10T02:20:00.000Z');
});
});

0 comments on commit 877ecee

Please sign in to comment.