Skip to content

Commit e0bda7e

Browse files
authored
Parse field for day of week should allow 0 or SUN values (#366)
* fix: parse field for day of week should allow 0 values and not throw error * test: add test case of single day of week string
1 parent 88ee899 commit e0bda7e

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/CronExpressionParser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class CronExpressionParser {
181181
value = value.replace(/[a-z]{3}/gi, (match) => {
182182
match = match.toLowerCase();
183183
const replacer = Months[match as keyof typeof Months] || DayOfWeek[match as keyof typeof DayOfWeek];
184-
if (!replacer) {
184+
if (replacer === undefined) {
185185
throw new Error(`Validation error, cannot resolve alias "${match}"`);
186186
}
187187
return replacer.toString();

tests/CronExpressionParser.test.ts

+11
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,17 @@ describe('CronExpressionParser', () => {
489489
expect(next.getMinutes()).toEqual(40);
490490
});
491491

492+
test('using day of week string', () => {
493+
const interval = CronExpressionParser.parse('15 10 * * SUN');
494+
const intervals = interval.take(8);
495+
for (const next of intervals) {
496+
const day = next.getDay();
497+
expect(day === 0).toBeTruthy();
498+
expect(next.getHours()).toEqual(10);
499+
expect(next.getMinutes()).toEqual(15);
500+
}
501+
});
502+
492503
test('using days of week strings', () => {
493504
const interval = CronExpressionParser.parse('15 10 * * MON-TUE');
494505
const intervals = interval.take(8);

0 commit comments

Comments
 (0)