From fe30d9d533c5cc151a598df5daa71d226022c071 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Wed, 28 Jul 2021 11:07:37 +0300 Subject: [PATCH 1/2] test: added failing schedule().next() test #14 --- test/core/schedule-test.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 () { From 4b5c6f67d2ab30163e6b0995e11239230c6953ee Mon Sep 17 00:00:00 2001 From: Yuriy Date: Wed, 28 Jul 2021 11:24:28 +0300 Subject: [PATCH 2/2] fix: fixed failing schedule().next() #14 --- README.md | 1 + package.json | 5 +++-- src/index.js | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3706ee5..067457a 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 12a0d33..cd396b5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@breejs/later", "description": "Maintained fork of later. Determine later (or previous) occurrences of recurring schedules", - "version": "4.0.2", + "version": "4.0.3", "author": "BunKat ", "bugs": { "url": "https://github.com/breejs/later/issues", @@ -9,7 +9,8 @@ }, "contributors": [ "BunKat ", - "Nick Baugh (http://niftylettuce.com/)" + "Nick Baugh (http://niftylettuce.com/)", + "yrambler2001 (https://yrambler2001.me/)" ], "dependencies": {}, "devDependencies": { diff --git a/src/index.js b/src/index.js index 85e067b..5ddfd6b 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(); }; }