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

Add getRunDatesUntil method for generating multiple run dates until a specified end date #201

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

le-pepe
Copy link

@le-pepe le-pepe commented Feb 18, 2025

Summary

A new getRunDatesUntil method is added to generate execution dates based on a cron expression, limited by a specified end date. The method also allows setting a maximum number of iterations, including the current date, and handling time zones for date calculations.

Details

  • The new method accepts an end date ($until), a maximum number of occurrences ($limit), and a reference time ($currentTime) to calculate the execution dates.
  • It includes an option to include or exclude the current date in the results ($allowCurrentDate).
  • The method uses the determineTimeZone function to manage time zones, which can either be specified or dynamically determined from $currentTime.
  • If the $limit parameter is set to 0, the method defaults to $this->maxIterationCount.

Behavior

  • The method returns an array of DateTimeInterface objects representing the calculated execution dates.
  • If the end date is reached or the iteration limit is met, the process stops, and no further dates are added.

Tests

  • Tests have been added to verify the correct generation of run dates, both with allowCurrentDate enabled and disabled.
  • It has also been validated that the date limit and the end date are correctly respected.

…ltiple execution dates until a specified end date

test(CronExpressionTest.php): add unit tests for getRunDatesUntil method to ensure correct date calculations and edge case handling
…unDatesUntil method to ensure proper exception handling
… it is an integer

test(CronExpressionTest.php): add unit test for invalid limit parameter in getRunDatesUntil method to ensure proper exception handling
@mabar
Copy link

mabar commented Feb 18, 2025

Looks like solution for #1, nice :)

feat(CronExpression): add type hints to getRunDateUntil method parameters

Co-authored-by: Marek Bartoš <[email protected]>
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.

3 participants