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

Added a method to get run dates in a date range #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/Cron/CronExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,45 @@ public function getPreviousRunDate($currentTime = 'now', $nth = 0, $allowCurrent
public function getMultipleRunDates($total, $currentTime = 'now', $invert = false, $allowCurrentDate = false)
{
$matches = array();
for ($i = 0; $i < max(0, $total); $i++) {
$guard_terminator = max(0, $total);
for ($i = 0; $i < $guard_terminator; $i++) {
Copy link
Owner

Choose a reason for hiding this comment

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

Can this just be changed to:

for ($i = 0, $c = max(0, $total); $i < $c; $i++) {
    // ...
}

Copy link
Author

Choose a reason for hiding this comment

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

Added this and the suggestion of @TheDigitalOrchard above for $max

$matches[] = $this->getRunDate($currentTime, $i, $invert, $allowCurrentDate);
}

return $matches;
}

/**
Copy link
Owner

Choose a reason for hiding this comment

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

The alignment of the comment is off here

Copy link
Author

Choose a reason for hiding this comment

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

It should be all good now. At least in my editor it shows all lined up the same.

* Get ALL run dates limited to a date range
*
* @param string|DateTime $start Start of range
Copy link

Choose a reason for hiding this comment

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

null|string|DateTime, same for line below

* @param string|DateTime $end End of range
*
* @return array Returns an array of run dates
*/
public function getRangeRunDates($start, $end)
{
$matches = array();

if (!($end instanceof DateTime)) {
$end = new DateTime($end ?: 'now');
$end->setTimezone(new DateTimeZone(date_default_timezone_get()));
}

if (!($start instanceof DateTime)) {
$start = new DateTime($start ?: 'now');
$start->setTimezone(new DateTimeZone(date_default_timezone_get()));
}

for (
$guard = $this->getNextRunDate($start, 0, true);
$guard <= $end;
$guard = $this->getNextRunDate($guard, 0, false)
)
Copy link
Owner

Choose a reason for hiding this comment

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

Can you add braces here? I don't like blocks without a wrapping brace

Copy link
Author

Choose a reason for hiding this comment

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

Done :)

$matches[] = $guard;

return $matches;
}

/**
* Get all or part of the CRON expression
Expand Down