crunzphp / crunz

A PHP-based job scheduler
MIT License
176 stars 16 forks source link

Getter for from, to task's parameters #59

Closed lucatacconi closed 10 months ago

lucatacconi commented 11 months ago

In the Event.php class there are some public variables of the class and some public methods such as getExpression(), getId() which are very useful if you integrate the class and want to have details on the task you want to analyze.

Unfortunately there is no way to determine if the task has a lifetime configured by "from", "to" or "between" method. Could be useful to have some getters for "from" and "to" configurations or have public variables to read that.

Theoretically the change could be quite simple.

You can add the variable "from" and "to" to the top of Event.php file with something like that:

/**
* Lifetime from.
*
* @var \DateTime|string
*/
public $from;

/**
* Lifetime to.
*
* @var \DateTime|string
*/
public $to;

and then modify class method from and to at line 448 and 460 with something like that:

/**
* Check if event should be on.
*
* @param string $datetime
*
* @return self
*/
public function from($datetime)
{
    $this->from = $datetime;
    return $this->skip(fn () => $this->notYet($datetime));
}

/**
* Check if event should be off.
*
* @param string $datetime
*
* @return self
*/
public function to($datetime)
{
    $this->to = $datetime;
    return $this->skip(fn () => $this->past($datetime));
}
PabloKowalczyk commented 10 months ago

Fixed by #68