Skip to content

Commit

Permalink
adding tests and fixing a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jodevsa committed Aug 13, 2018
1 parent 98dad71 commit 61d26e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/cron.js
Expand Up @@ -176,6 +176,7 @@

_getNextDateFrom: function(start,zone) {
var date;
var firstDate=moment(start).valueOf();
if(zone){
date=moment(start).tz(zone);
}
Expand Down Expand Up @@ -262,7 +263,7 @@
continue;
}

if(date.valueOf()==start){
if(date.valueOf() === firstDate){
date.seconds(date.seconds()+1);
continue;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/test-crontime.js
Expand Up @@ -202,4 +202,26 @@ describe('crontime', function () {
var x = cronTime._getNextDateFrom(new Date("2018-08-10T02:19:59.999Z"));
expect(x.toISOString()).to.equal('2018-08-10T02:20:00.000Z');
});

it('should generete the right next days when cron is set to every minute', function () {
var cronTime = new cron.CronTime('* * * * *');
var min=60000;
var previousDate=new Date(Date.UTC(2018,5,3,0,0));
for(var i=0;i<25;i++){
var nextDate = cronTime._getNextDateFrom(previousDate);
expect(nextDate.valueOf()).to.equal(previousDate.valueOf()+min)
previousDate=nextDate;
}
});

it('should generete the right next days when cron is set to every 15 min', function () {
var cronTime = new cron.CronTime('*/15 * * * *');
var min=60000*15;
var previousDate=new Date(Date.UTC(2016,6,3,0,0));
for(var i=0;i<25;i++){
var nextDate = cronTime._getNextDateFrom(previousDate);
expect(nextDate.valueOf()).to.equal(previousDate.valueOf()+min)
previousDate=nextDate;
}
});
});

0 comments on commit 61d26e1

Please sign in to comment.