diff --git a/README.md b/README.md index 080e031..3f4c4a0 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Assuming you are using [browserify][], [webpack][], [rollup][], or another bundl | -------------- | -------------------------- | | **BunKat** | | | **Nick Baugh** | | +| **yrambler2001** | | ## License diff --git a/package.json b/package.json index e35a872..278fc88 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ }, "contributors": [ "BunKat ", - "Nick Baugh (http://niftylettuce.com/)" + "Nick Baugh (http://niftylettuce.com/)", + "yrambler2001 (https://yrambler2001.me/)" ], "devDependencies": { "@babel/cli": "^7.10.5", diff --git a/src/index.js b/src/index.js index 7d494ac..cd2650b 100644 --- a/src/index.js +++ b/src/index.js @@ -841,9 +841,11 @@ later.compile = function (schedDef) { function compareFn(dir) { return dir === 'next' ? function (a, b) { + if (!a || !b) return true; return a.getTime() > b.getTime(); } : function (a, b) { + if (!a || !b) return true; return b.getTime() > a.getTime(); }; } @@ -1148,10 +1150,12 @@ later.schedule = function (sched) { function compareFn(dir) { return dir === 'next' ? function (a, b) { - return !b || a.getTime() > b.getTime(); + if (!a || !b) return true; + return a.getTime() > b.getTime(); } : function (a, b) { - return !a || b.getTime() > a.getTime(); + if (!a || !b) return true; + return b.getTime() > a.getTime(); }; } diff --git a/test/core/schedule-test.js b/test/core/schedule-test.js index 25b3424..fd03b1e 100644 --- a/test/core/schedule-test.js +++ b/test/core/schedule-test.js @@ -66,6 +66,12 @@ describe('Schedule', function () { const s = { schedules: [{ Y: [2017] }] }; should.equal(schedule(s).next(1, d, e), later.NEVER); }); + + it('should return next schedule if previous schedule has next date later.NEVER', function () { + const d = new Date('2013-03-21T00:00:05Z'); + const s = { schedules: [{ Y: [2012] }, { Y: [2017] }] }; + schedule(s).next(1, d).should.eql(new Date('2017-01-01T00:00:00Z')); + }); }); describe('prev', function () {