Skip to content

Commit 0deb346

Browse files
authored
Merge pull request #15 from yrambler2001/master
Fixed failing schedule().next() #14
2 parents 53c5a89 + 0159395 commit 0deb346

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Assuming you are using [browserify][], [webpack][], [rollup][], or another bundl
8989
| -------------- | -------------------------- |
9090
| **BunKat** | |
9191
| **Nick Baugh** | <http://niftylettuce.com/> |
92+
| **yrambler2001** | <https://yrambler2001.me/> |
9293

9394

9495
## License

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
},
1010
"contributors": [
1111
"BunKat <[email protected]>",
12-
"Nick Baugh <[email protected]> (http://niftylettuce.com/)"
12+
"Nick Baugh <[email protected]> (http://niftylettuce.com/)",
13+
"yrambler2001 <[email protected]> (https://yrambler2001.me/)"
1314
],
1415
"devDependencies": {
1516
"@babel/cli": "^7.10.5",

src/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,11 @@ later.compile = function (schedDef) {
841841
function compareFn(dir) {
842842
return dir === 'next'
843843
? function (a, b) {
844+
if (!a || !b) return true;
844845
return a.getTime() > b.getTime();
845846
}
846847
: function (a, b) {
848+
if (!a || !b) return true;
847849
return b.getTime() > a.getTime();
848850
};
849851
}
@@ -1148,10 +1150,12 @@ later.schedule = function (sched) {
11481150
function compareFn(dir) {
11491151
return dir === 'next'
11501152
? function (a, b) {
1151-
return !b || a.getTime() > b.getTime();
1153+
if (!a || !b) return true;
1154+
return a.getTime() > b.getTime();
11521155
}
11531156
: function (a, b) {
1154-
return !a || b.getTime() > a.getTime();
1157+
if (!a || !b) return true;
1158+
return b.getTime() > a.getTime();
11551159
};
11561160
}
11571161

test/core/schedule-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ describe('Schedule', function () {
6666
const s = { schedules: [{ Y: [2017] }] };
6767
should.equal(schedule(s).next(1, d, e), later.NEVER);
6868
});
69+
70+
it('should return next schedule if previous schedule has next date later.NEVER', function () {
71+
const d = new Date('2013-03-21T00:00:05Z');
72+
const s = { schedules: [{ Y: [2012] }, { Y: [2017] }] };
73+
schedule(s).next(1, d).should.eql(new Date('2017-01-01T00:00:00Z'));
74+
});
6975
});
7076

7177
describe('prev', function () {

0 commit comments

Comments
 (0)