Skip to content

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

Open
le-pepe wants to merge 4 commits into
dragonmantank:masterfrom
le-pepe:master
Open

Add getRunDatesUntil method for generating multiple run dates until a specified end date#201
le-pepe wants to merge 4 commits into
dragonmantank:masterfrom
le-pepe:master

Conversation

@le-pepe

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

Copy link
Copy Markdown

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
Comment thread src/Cron/CronExpression.php
@mabar

mabar commented Feb 18, 2025

Copy link
Copy Markdown

Looks like solution for #1, nice :)

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

Co-authored-by: Marek Bartoš <bartos.developer152@gmail.com>
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