Skip to content

Commit 42add11

Browse files
authored
fix mismatch condition from vixie cron (#365)
1 parent 7addef9 commit 42add11

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/pg_cron.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -984,17 +984,18 @@ ShouldRunTask(entry *schedule, TimestampTz currentTime, bool doWild,
984984
* so cur_tm cannot be used after this point.
985985
*/
986986
struct pg_tm* tomorrow_tm = pg_localtime(&tomorrowTime_t, pg_tzset(cron_timezone));
987-
bool lastdom = (schedule->flags & DOM_LAST) != 0 && tomorrow_tm->tm_mday == 1;
988-
bool thisdom = lastdom || bit_test(schedule->dom, dayOfMonth) != 0;
987+
bool is_lastdom = tomorrow_tm->tm_mday == 1;
988+
bool thisdom = bit_test(schedule->dom, dayOfMonth) != 0 || (is_lastdom && (schedule->flags & DOM_LAST) != 0);
989989
bool thisdow = bit_test(schedule->dow, dayOfWeek);
990-
991990
if (bit_test(schedule->minute, minute) &&
992-
bit_test(schedule->hour, hour) &&
993-
bit_test(schedule->month, month) &&
994-
( (schedule->flags & (DOM_STAR|DOW_STAR)) != 0
995-
? (thisdom && thisdow) : (thisdom) || thisdow)) {
996-
if ((doNonWild && !(schedule->flags & (MIN_STAR|HR_STAR)))
997-
|| (doWild && (schedule->flags & (MIN_STAR|HR_STAR))))
991+
bit_test(schedule->hour, hour) &&
992+
bit_test(schedule->month, month) &&
993+
((schedule->flags & (DOM_STAR | DOW_STAR)) != 0
994+
? (thisdom && thisdow)
995+
: (thisdom || thisdow)))
996+
{
997+
if ((doNonWild && (schedule->flags & (MIN_STAR | HR_STAR)) == 0) ||
998+
(doWild && (schedule->flags & (MIN_STAR | HR_STAR)) != 0))
998999
{
9991000
return true;
10001001
}

0 commit comments

Comments
 (0)