Skip to content

Commit

Permalink
Merge pull request #15 from yrambler2001/master
Browse files Browse the repository at this point in the history
Fixed failing schedule().next() #14
  • Loading branch information
titanism committed Nov 28, 2023
2 parents 53c5a89 + 0159395 commit 0deb346
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Assuming you are using [browserify][], [webpack][], [rollup][], or another bundl
| -------------- | -------------------------- |
| **BunKat** | |
| **Nick Baugh** | <http://niftylettuce.com/> |
| **yrambler2001** | <https://yrambler2001.me/> |


## License
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"contributors": [
"BunKat <bill@levelstory.com>",
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)"
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com/)",
"yrambler2001 <yrambler2001@gmail.com> (https://yrambler2001.me/)"
],
"devDependencies": {
"@babel/cli": "^7.10.5",
Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
Expand Down Expand Up @@ -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();
};
}

Expand Down
6 changes: 6 additions & 0 deletions test/core/schedule-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 0deb346

Please sign in to comment.