Skip to content

Commit 4b16aa9

Browse files
authored
CronFieldCollection.from should allow passing in special chars (#387)
1 parent d88c64c commit 4b16aa9

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/fields/CronField.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export abstract class CronField {
9898
};
9999
this.#values = values.sort(CronField.sorter);
100100
this.#wildcard = this.options.wildcard !== undefined ? this.options.wildcard : this.#isWildcardValue();
101-
this.#hasLastChar = this.options.rawValue.includes('L');
102-
this.#hasQuestionMarkChar = this.options.rawValue.includes('?');
101+
this.#hasLastChar = this.options.rawValue.includes('L') || values.includes('L');
102+
this.#hasQuestionMarkChar = this.options.rawValue.includes('?') || values.includes('?');
103103
}
104104

105105
/**

src/fields/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type SixtyRange = IntRange<RangeFrom<0>, 59>; // 0-59 - inclusive
99
export type HourRange = IntRange<RangeFrom<0>, 23>; // 0-23 - inclusive
1010
export type DayOfMonthRange = IntRange<RangeFrom<1>, 31> | 'L'; // 1-31 - inclusive
1111
export type MonthRange = IntRange<RangeFrom<1>, 12>; // 1-12 - inclusive
12-
export type DayOfWeekRange = IntRange<RangeFrom<0>, 7>; // 0-7 - inclusive
12+
export type DayOfWeekRange = IntRange<RangeFrom<0>, 7> | 'L'; // 0-7 - inclusive
1313
export type CronFieldType = SixtyRange[] | HourRange[] | DayOfMonthRange[] | MonthRange[] | DayOfWeekRange[];
1414
export type CronChars = 'L' | 'W';
1515
export type CronMin = 0 | 1;

tests/CronFieldCollection.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ describe('CronFieldCollection', () => {
333333
expect(result.minute.values).toEqual([30]);
334334
});
335335

336+
test('should handle special characters (L)', () => {
337+
const result = CronFieldCollection.from(base, {
338+
dayOfMonth: ['L'],
339+
dayOfWeek: ['L'],
340+
});
341+
expect(result.dayOfMonth).not.toBe(base.dayOfMonth);
342+
expect(result.dayOfMonth.values).toEqual(['L']);
343+
expect(result.dayOfWeek).not.toBe(base.dayOfWeek);
344+
expect(result.dayOfWeek.values).toEqual(['L']);
345+
expect(result.stringify(true)).toEqual('0 0 12 L 1 L');
346+
});
347+
336348
test('should handle mix of CronField instances and raw values', () => {
337349
const newHour = new CronHour([15]);
338350

0 commit comments

Comments
 (0)