Skip to content

Commit

Permalink
Fix multiple dayofmonth ranges handling (#267)
Browse files Browse the repository at this point in the history
* Fix dayofmonth handling in matching loop

* Add test case
  • Loading branch information
harrisiirak authored May 1, 2022
1 parent 01c31ec commit 2c46007
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ CronExpression.prototype._findSchedule = function _findSchedule (reverse) {
var currentHour = currentDate.getHours();

// Add or subtract day if select day not match with month (according to calendar)
if (!dayOfMonthMatch && !dayOfWeekMatch) {
if (!dayOfMonthMatch && (!dayOfWeekMatch || isDayOfWeekWildcardMatch)) {
this._applyTimezoneShift(currentDate, dateMathVerb, 'Day');
continue;
}
Expand Down
48 changes: 47 additions & 1 deletion test/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,52 @@ test('day of month is wildcard, month and day of week are both set', function(t)
t.end();
});

test('day of month contains multiple ranges and day of week is wildcard', function(t) {
try {
var options = {
currentDate: new CronDate('Sat, 1 Dec 2012 14:38:53')
};
var interval = CronExpression.parse('0 0 0 2-4,7-31 * *', options);
t.ok(interval, 'Interval parsed');

var next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.ok(next.getDate() === 2, 'Day of month matches');
t.equal(next.getMonth(), 11, 'Month matches');

next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.ok(next.getDate() === 3, 'Day of month matches');
t.equal(next.getMonth(), 11, 'Month matches');

next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.ok(next.getDate() === 4, 'Day of month matches');
t.equal(next.getMonth(), 11, 'Month matches');

next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.ok(next.getDate() === 7, 'Day of month matches');
t.equal(next.getMonth(), 11, 'Month matches');

next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.ok(next.getDate() === 8, 'Day of month matches');
t.equal(next.getMonth(), 11, 'Month matches');

next = interval.next();
} catch (err) {
t.error(err, 'Interval parse error');
}

t.end();
});

test('day of month and week are both set and dow is 6,0', function(t) {
try {
var options = {
Expand Down Expand Up @@ -958,7 +1004,7 @@ test('day of month and week are both set and dow is 6,0', function(t) {
});


test('day of month and week are both set and dow is 6-7', function(t) {
test('day of month and week are both set and dow is a range with value 6-7', function(t) {
try {
var options = {
currentDate: new CronDate('Wed, 26 Dec 2012 14:38:53')
Expand Down

0 comments on commit 2c46007

Please sign in to comment.