Skip to content

Commit f440cb9

Browse files
committed
feat: add "from through" feature #6
1 parent dd42ecb commit f440cb9

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const dayParser = (pattern, string) => {
4848
};
4949

5050
const dateParser = (pattern, string) => {
51+
const from = /from\s([0-9]{1,2})\sthrough\s([0-9]{1,2})/.exec(string);
5152
const full =
5253
/(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) ([0-9]{1,2})/.exec(
5354
string
@@ -83,6 +84,11 @@ const dateParser = (pattern, string) => {
8384
}
8485
}
8586

87+
if (!full && from) {
88+
pattern[3] = `${from[1]}-${from[2]}`;
89+
pattern[5] = '*';
90+
}
91+
8692
return pattern;
8793
};
8894

test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const test = (check, should) => {
99
if (expr !== null) {
1010
const checkexpr = cron.validate(expr);
1111
if (!checkexpr) {
12-
throw new Error('Cron Expression invalid');
12+
throw new Error(`Expression invalid - ${expr}`);
1313
}
1414
}
1515
assert.equal(expr, should);
@@ -45,6 +45,12 @@ test(
4545
'0 30 9 * 1,2,3 1,2,6'
4646
);
4747
test('on jan feb every 45 minutes', '0 */45 * * 1,2 *');
48+
test(
49+
'every 15 minutes from 5 through 15 of december and january',
50+
'0 */15 * 5-15 1,12 *'
51+
);
52+
//test('every week in 15 minute intervals on january', '0 */15 * */7 1 *');
53+
//test('every week on january', '0 0 0 */7 1 *');
4854

4955
if (process.env.TESTWATCH) {
5056
process.stdout.write('\u001b[3J\u001b[2J\u001b[1J');

0 commit comments

Comments
 (0)