Skip to content

issue with range() #12

Description

@avest

There is an issue with the range() call in Validator.php.

you will get an error if you run:
Expression::isDue('5/20 * * * *', '2018-08-13 00:24:00');

Here is my fix:

public function inStep($value, $offset)
{
	if (\strpos($offset, '*/') !== false || \strpos($offset, '0/') !== false)
	{
		$parts = \explode('/', $offset, 2);

		return $value % $parts[1] === 0;
	}

	$parts = \explode('/', $offset, 2);

	$subparts = \explode('-', $parts[0], 2) + [1 => $value];

	$range_start = $subparts[0];

	$range_end = $subparts[1];

	$range_step = $parts[1];

	$range_max = $range_start + $range_step;

	$range = array($range_start);
	if ($range_end >= $range_max)
	{
		$range = \range($subparts[0], $subparts[1], $parts[1]);
	}

	$in_range = false;
	if ($range)
	{
		$in_range = \in_array($value, $range);
	}

	//return ($subparts[0] <= $value && $value <= $subparts[1] && $parts[1])
	//	? \in_array($value, \range($subparts[0], $subparts[1], $parts[1]))
	//	: false;
	return ($subparts[0] <= $value && $value <= $subparts[1] && $parts[1])
		? $in_range
		: false;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions