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 mismatch condition from vixie cron #365

Merged
merged 1 commit into from
Dec 12, 2024
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
19 changes: 10 additions & 9 deletions src/pg_cron.c
Original file line number Diff line number Diff line change
Expand Up @@ -984,17 +984,18 @@ ShouldRunTask(entry *schedule, TimestampTz currentTime, bool doWild,
* so cur_tm cannot be used after this point.
*/
struct pg_tm* tomorrow_tm = pg_localtime(&tomorrowTime_t, pg_tzset(cron_timezone));
bool lastdom = (schedule->flags & DOM_LAST) != 0 && tomorrow_tm->tm_mday == 1;
bool thisdom = lastdom || bit_test(schedule->dom, dayOfMonth) != 0;
bool is_lastdom = tomorrow_tm->tm_mday == 1;
bool thisdom = bit_test(schedule->dom, dayOfMonth) != 0 || (is_lastdom && (schedule->flags & DOM_LAST) != 0);
bool thisdow = bit_test(schedule->dow, dayOfWeek);

if (bit_test(schedule->minute, minute) &&
bit_test(schedule->hour, hour) &&
bit_test(schedule->month, month) &&
( (schedule->flags & (DOM_STAR|DOW_STAR)) != 0
? (thisdom && thisdow) : (thisdom) || thisdow)) {
if ((doNonWild && !(schedule->flags & (MIN_STAR|HR_STAR)))
|| (doWild && (schedule->flags & (MIN_STAR|HR_STAR))))
bit_test(schedule->hour, hour) &&
bit_test(schedule->month, month) &&
((schedule->flags & (DOM_STAR | DOW_STAR)) != 0
? (thisdom && thisdow)
: (thisdom || thisdow)))
{
if ((doNonWild && (schedule->flags & (MIN_STAR | HR_STAR)) == 0) ||
(doWild && (schedule->flags & (MIN_STAR | HR_STAR)) != 0))
{
return true;
}
Expand Down