Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cron.matchDate always returning true for day of month, when either weekday or day of month is unrestricted #271

Merged
merged 3 commits into from Apr 27, 2022
Merged
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
21 changes: 14 additions & 7 deletions src/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,19 @@ export class Cron {
const { second, minute, hour, day, month, weekday } =
extractDateElements(date)

return (
this.seconds.indexOf(second) !== -1 &&
this.minutes.indexOf(minute) !== -1 &&
this.hours.indexOf(hour) !== -1 &&
this.months.indexOf(month) !== -1 &&
(this.days.indexOf(day) !== -1 || this.weekdays.indexOf(weekday) !== -1)
)
if (
this.seconds.indexOf(second) === -1 ||
this.minutes.indexOf(minute) === -1 ||
this.hours.indexOf(hour) === -1 ||
this.months.indexOf(month) === -1
) {
return false
}

if (this.days.length !== 31 && this.weekdays.length !== 7) {
return this.days.indexOf(day) !== -1 || this.weekdays.indexOf(weekday) !== -1
}

return this.days.indexOf(day) !== -1 && this.weekdays.indexOf(weekday) !== -1
}
}