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

Implemented dynamic maxIterationCount for getRunDate() #89

Merged
merged 2 commits into from
Jan 26, 2016

Conversation

tobias-kuendig
Copy link
Contributor

I have implemented a maxIterationCount property that is used as the limit to bail on an impossible date in getRunDate().

When generating run dates that lie further in the future, the hard coded 1000 iterations aren't always enough (see Issue #66).
To work around this, you can now set the maxIterationCount via the setter method setMaxIterationCount.

@@ -36,7 +36,10 @@ public function isSatisfiedBy(\DateTime $date, $value)
$tdate = clone $date;
$tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
while ($tdate->format('w') != $weekday) {
$tdate->setDate($currentYear, $currentMonth, --$lastDayOfMonth);
$tdateClone = new \DateTime();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason the day of $tdate stays the same when using setDate();. This leads to an infinite loop since $tdate->format('w') is unchanged. This is not the most beautiful workaround, but it works.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this change belongs in this PR. Can you remove it please?

@tobias-kuendig
Copy link
Contributor Author

I have reverted the changes.

@@ -275,6 +275,21 @@ public function testProvidesMultipleRunDates()
new DateTime('2008-11-09 00:04:00'),
new DateTime('2008-11-09 00:06:00')
), $cron->getMultipleRunDates(4, '2008-11-09 00:00:00', false, true));

// Fails with the default 1000 iteration limit
$cron = CronExpression::factory('0 0 12 1 * */2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you break this out into it's own test?

@tobias-kuendig
Copy link
Contributor Author

@dragonmantank I have moved the code to a separate test.

dragonmantank added a commit that referenced this pull request Jan 26, 2016
Implemented dynamic maxIterationCount for getRunDate()
@dragonmantank dragonmantank merged commit 25ea4b5 into mtdowling:master Jan 26, 2016
loneregister pushed a commit to loneregister/cron-expression that referenced this pull request Sep 5, 2023
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