Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/to-human.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ export function toHuman(expression: string): string {
if (parts.length !== 5 && parts.length !== 6) {
throw new CronTranslateError(`Expected a 5- or 6-field cron expression, got ${parts.length} fields.`);
}
const [sec, min, hour, dom, monthRaw, dowRaw] = parts.length === 6
? parts
: ['0', ...parts];
// `?` (Quartz "no specific value") means no constraint on the field, same as `*`.
const fields = (parts.length === 6 ? parts : ['0', ...parts]).map((f) => (f === '?' ? '*' : f));
const [sec, min, hour, dom, monthRaw, dowRaw] = fields;
const month = mapNames(monthRaw, MONTH_NUMS);
const dow = mapNames(dowRaw, DOW_NUMS);

Expand Down
11 changes: 11 additions & 0 deletions test/to-human.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ describe('toHuman — accepts month/weekday names in input', () => {
});
});

describe('toHuman — treats ? (Quartz no-value) like *', () => {
const cases: [string, string][] = [
['0 0 9 ? * MON', 'at 9am on monday'],
['0 0 9 15 * ?', 'at 9am on day 15'],
['0 0 0 ? * 1-5', 'on monday to friday'],
];
it.each(cases)('%s => %s', (cron, expected) => {
expect(toHuman(cron)).toBe(expected);
});
});

describe('toHuman — rejects malformed input', () => {
it.each(['', 'a b c', '1 2 3 4 5 6 7'])('rejects %j', (bad) => {
expect(() => toHuman(bad)).toThrow();
Expand Down
Loading