Skip to content

Commit

Permalink
Sort input atoms in ascending order. Fixes #179
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisiirak committed May 20, 2020
1 parent fc44dab commit 110a823
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ CronExpression._parseField = function _parseField (field, value, constraints) {
}
}

var atoms = val.split(',');
var atoms = val
.split(',')
.sort(function(a, b) {
return a.localeCompare(b);
});

if (atoms.length > 1) {
for (var i = 0, c = atoms.length; i < c; i++) {
handleResult(parseRepeat(atoms[i]));
Expand Down
15 changes: 15 additions & 0 deletions test/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,21 @@ test('day and date in week should matches', function(t){
t.end();
});

test('should sort ranges and values in ascending order', function(t) {
var interval = CronExpression.parse('0 12,13,10,1-3 * * *');
t.ok(interval, 'Interval parsed');

var hours = [ 1, 2, 3, 10, 12, 13 ];
for (var i in hours) {
next = interval.next();

t.ok(next, 'Found next scheduled interval');
t.equal(next.getHours(), hours[i], 'Hours matches');
}

t.end();
});

test('valid ES6 iterator should be returned if iterator options is set to true', function(t) {
try {
var options = {
Expand Down

0 comments on commit 110a823

Please sign in to comment.