Skip to content

Conversation

@jmrozanec
Copy link
Owner

This commit introduces a new overlap method to the Cron interface and its implementation in SingleCron.

The overlap method allows checking if two cron expressions will have any common execution times. It works by:

  1. Getting ExecutionTime instances for both cron expressions.
  2. Defining a one-year window from the current time for the check.
  3. Iterating through the execution times of the first cron within this window.
  4. For each execution time, it checks if this time is a valid execution time for the second cron expression using ExecutionTime.isMatch().

Unit tests have been added in SingleCronTest.java to cover various scenarios, including:

  • The specific case from the motivating issue (daily vs. weekly at the same time).
  • Non-overlapping expressions.
  • Expressions overlapping on specific dates.
  • Always overlapping expressions (e.g., every minute).
  • Other edge cases to ensure robustness.

This commit introduces a new `overlap` method to the `Cron` interface and its implementation in `SingleCron`.

The `overlap` method allows checking if two cron expressions will have any common execution times. It works by:
1. Getting `ExecutionTime` instances for both cron expressions.
2. Defining a one-year window from the current time for the check.
3. Iterating through the execution times of the first cron within this window.
4. For each execution time, it checks if this time is a valid execution time for the second cron expression using `ExecutionTime.isMatch()`.

Unit tests have been added in `SingleCronTest.java` to cover various scenarios, including:
- The specific case from the motivating issue (daily vs. weekly at the same time).
- Non-overlapping expressions.
- Expressions overlapping on specific dates.
- Always overlapping expressions (e.g., every minute).
- Other edge cases to ensure robustness.
@jmrozanec jmrozanec merged commit 1ae4cad into master May 24, 2025
1 check failed
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