Skip to content

fix(calendar): OR day-of-month and day-of-week when both restricted#644

Merged
FranDias merged 5 commits into
nex-crm:mainfrom
CharlieKerfoot:fix/standard-cron-treats
May 5, 2026
Merged

fix(calendar): OR day-of-month and day-of-week when both restricted#644
FranDias merged 5 commits into
nex-crm:mainfrom
CharlieKerfoot:fix/standard-cron-treats

Conversation

@CharlieKerfoot
Copy link
Copy Markdown
Contributor

@CharlieKerfoot CharlieKerfoot commented May 5, 2026

Summary

Standard cron semantics treat day-of-month and day-of-week as a union when both fields are restricted, but CronSchedule.matches in internal/calendar/cron.go:119 ANDed them. A schedule like 0 9 1 * 1 fired only when the date was both the 1st and a Monday, instead of either.

Fix

Split the day check: when only one of DOM/DOW is restricted, require that match; when both are restricted, accept the tick if either matches. Month check moved above the day logic so it still short-circuits cleanly.

Summary by CodeRabbit

  • Bug Fixes
    • Cron schedule matching corrected: when both day-of-month and day-of-week are restricted, a schedule now matches if either field matches (OR semantics); month, hour, and minute checks remain independent.
  • Tests
    • Added unit tests covering DOM/DOW combinations, DOM-only, DOW-only, wildcard days, and month short-circuit behavior.

@CharlieKerfoot CharlieKerfoot requested review from a team and FranDias as code owners May 5, 2026 00:38
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 867515c9-1a98-4c62-86ed-6a4eed9f8d27

📥 Commits

Reviewing files that changed from the base of the PR and between ef4a28e and f551c8b.

📒 Files selected for processing (1)
  • internal/calendar/cron_test.go

📝 Walkthrough

Walkthrough

Cron matching logic was updated so DaysOfMonth and DaysOfWeek use restriction flags: when both are restricted, the schedule matches if either DOM or DOW matches (OR semantics). Months remain an independent short-circuit. New unit tests exercise these scenarios with fixed 2026 UTC timestamps.

Changes

Cron Day-Matching Logic & Tests

Layer / File(s) Summary
Data Shape / Flags
internal/calendar/cron.go
Introduces local booleans domRestricted and dowRestricted to represent whether DaysOfMonth/DaysOfWeek are restricted.
Core Logic
internal/calendar/cron.go
Replaces previous early-return-on-mismatch behavior with logic that: when both DOM and DOW are restricted, matching succeeds if either matches (OR); when only one is restricted, that one must match. Months remains an independent restriction and short-circuits when restricted and not matching.
Tests
internal/calendar/cron_test.go
Adds table-driven tests validating: DOM+ DOW OR semantics, DOM-only matching, DOW-only matching, wildcard day behavior (every day), and month restriction short-circuiting using deterministic 2026 UTC timestamps.
Module / Metadata
go.mod
Module file present; no exported API changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nudged the clock at dawn's first light,
Two strict days loosened, one may be right.
Months still stand guard, hours hum true,
A softer match for schedules anew. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: correcting the logic to OR day-of-month and day-of-week when both are restricted, which is exactly what the changeset implements.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/calendar/cron.go`:
- Around line 122-137: The cron DOM/DOW semantics change needs unit tests to
prevent regressions: add a table-driven test file
(internal/calendar/cron_test.go) that uses ParseCron to build schedules and
calls cs.matches(time) for the following cases: the OR case ("0 9 1 * 1")
verifying it fires on the 1st and on Mondays but not other days or wrong hours;
a DOM-only spec ("0 9 15 * *") confirming weekday is ignored; a DOW-only spec
("0 9 * * 1") confirming day-of-month is ignored; a wildcard spec ("0 9 * * *")
confirming it fires every day at 09:00; and a month-restricted case showing
month short-circuits regardless of day fields. Ensure each scenario is
table-driven and asserts cs.matches returns the expected boolean.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 26662df9-4e54-4330-ac90-042f7e1ad276

📥 Commits

Reviewing files that changed from the base of the PR and between 00c3418 and 0c6c469.

📒 Files selected for processing (1)
  • internal/calendar/cron.go

Comment thread internal/calendar/cron.go
@najmuzzaman-mohammad najmuzzaman-mohammad force-pushed the fix/standard-cron-treats branch from 0c6c469 to 28ff949 Compare May 5, 2026 10:35
FranDias added 2 commits May 5, 2026 09:41
Pin the new behavior so future regressions to AND semantics are caught:
the canonical "0 9 1 * 1" OR case, DOM-only and DOW-only specs ignoring
the unrestricted axis, an unrestricted-day wildcard, and a
month-restricted spec confirming month still short-circuits regardless
of day fields.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/calendar/cron_test.go`:
- Around line 11-35: TestMatches_DOMandDOW_ORWhenBothRestricted is missing a
case where both day-of-month and day-of-week match; update that test (after
ParseCron and before the loop) to include a case in the cases slice with a time
that is both the 1st of the month and a Monday at 09:00 UTC (so
sched.matches(...) should return true), referencing the existing test function
TestMatches_DOMandDOW_ORWhenBothRestricted and the sched.matches method to
ensure the OR-path where both DOM and DOW are true is explicitly exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9f578637-39b4-4a42-9c8a-c2608ecd5786

📥 Commits

Reviewing files that changed from the base of the PR and between 28ff949 and ef4a28e.

📒 Files selected for processing (1)
  • internal/calendar/cron_test.go

Comment thread internal/calendar/cron_test.go
@FranDias FranDias merged commit 1892c9a into nex-crm:main May 5, 2026
16 of 17 checks passed
@FranDias
Copy link
Copy Markdown
Contributor

FranDias commented May 5, 2026

@CharlieKerfoot TY 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants