cron-parser
Advanced tools
Comparing version 4.7.1 to 4.8.0
@@ -5,3 +5,3 @@ { | ||
"description": "Node.js library for parsing crontab instructions", | ||
"version": "4.7.1", | ||
"version": "4.8.0", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "cron", |
@@ -17,23 +17,30 @@ 'use strict'; | ||
} | ||
var resultArr = []; | ||
var result = []; | ||
for (var i = 0, l = ranges.length; i < l; ++i) { | ||
var range = ranges[i]; | ||
if (range.count === 1) { | ||
resultArr.push(range.start); | ||
result.push(range.start); | ||
continue; | ||
} | ||
var step = range.step; | ||
if (range.step === 1) { | ||
result.push(range.start + '-' + range.end); | ||
continue; | ||
} | ||
var multiplier = range.start == 0 ? range.count - 1 : range.count; | ||
if (range.step * multiplier > range.end) { | ||
result.push(arr.join(',')); | ||
} else if (range.end === max - range.step + 1) { | ||
result.push(range.start + '/' + range.step); | ||
} else { | ||
var step = range.step; | ||
if (step === 1) { | ||
resultArr.push(range.start + '-' + range.end); | ||
} else { | ||
if (range.end === max - step + 1) { | ||
resultArr.push(range.start + '/' + step); | ||
} else { | ||
resultArr.push(range.start + '-' + range.end + '/' + step); | ||
} | ||
} | ||
result.push(range.start + '-' + range.end + '/' + range.step); | ||
} | ||
} | ||
return resultArr.join(','); | ||
return result.join(','); | ||
} | ||
module.exports = stringifyField; |
{ | ||
"name": "cron-parser", | ||
"version": "4.7.1", | ||
"version": "4.8.0", | ||
"description": "Node.js library for parsing crontab instructions", | ||
@@ -63,5 +63,5 @@ "main": "lib/parser.js", | ||
"eslint": "^8.27.0", | ||
"sinon": "^14.0.2", | ||
"sinon": "^15.0.1", | ||
"tap": "^16.3.3", | ||
"tsd": "^0.24.1" | ||
"tsd": "^0.26.0" | ||
}, | ||
@@ -68,0 +68,0 @@ "engines": { |
cron-parser | ||
================ | ||
[](https://travis-ci.com/harrisiirak/cron-parser) | ||
[](https://github.com/harrisiirak/cron-parser/actions/workflows/push.yml) | ||
[](http://badge.fury.io/js/cron-parser) | ||
@@ -166,3 +166,3 @@ | ||
``` | ||
0 0 * * * 1L | ||
0 0 0 * * 1L | ||
``` | ||
@@ -175,3 +175,3 @@ | ||
``` | ||
0 0 * * * 1,3L | ||
0 0 0 * * 1,3L | ||
``` |
@@ -118,2 +118,34 @@ 'use strict'; | ||
test('stringify cron expression with multiple values and retain original value', function (t) { | ||
try { | ||
var expected = '0 * * * * 1,3,5'; | ||
var interval = CronParser.parseExpression('* * * * 1,3,5', {}); | ||
var str = interval.stringify(true); | ||
t.equal(str, expected); | ||
str = CronParser.fieldsToExpression(interval.fields).stringify(true); | ||
t.equal(str, expected); | ||
} catch (err) { | ||
t.error(err, 'Parse read error'); | ||
} | ||
t.end(); | ||
}); | ||
test('stringify cron expression with multiple values and convert value to range step', function (t) { | ||
try { | ||
var expected = '0 * * * * 0-6/2'; | ||
var interval = CronParser.parseExpression('* * * * 0,2,4,6', {}); | ||
var str = interval.stringify(true); | ||
t.equal(str, expected); | ||
str = CronParser.fieldsToExpression(interval.fields).stringify(true); | ||
t.equal(str, expected); | ||
} catch (err) { | ||
t.error(err, 'Parse read error'); | ||
} | ||
t.end(); | ||
}); | ||
test('stringify cron expression with star range step (discard seconds)', function (t) { | ||
@@ -136,3 +168,2 @@ try { | ||
test('stringify cron expression with semi range step', function (t) { | ||
try { | ||
@@ -262,3 +293,3 @@ var expected = '0 5/5 * * * *'; | ||
test('stringify cron expression with wildcard day of month and month rangee', function (t) { | ||
test('stringify cron expression with wildcard day of month and month range', function (t) { | ||
try { | ||
@@ -265,0 +296,0 @@ var expected = '* * * 4-6 *'; |
152043
4324
2