Crunz\Event::on PHP Method

on() public method

Schedule the event to run on a certain date
public on ( string $date )
$date string
    public function on($date)
    {
        $date = date_parse($date);
        $segments = array_only($date, array_flip($this->fieldsPosition));
        if ($date['year']) {
            $this->skip(function () use($segments) {
                return (int) date('Y') != $segments['year'];
            });
        }
        foreach ($segments as $key => $value) {
            if ($value != false) {
                $this->spliceIntoPosition($this->fieldsPosition[$key], (int) $value);
            }
        }
        return $this;
    }

Usage Example

Example #1
0
 /**
  * @group cronCompile
  */
 public function testLowLevelMethods()
 {
     $e = new Event($this->id, 'php foo');
     $this->assertEquals('30 1 11 4 * *', $e->on('01:30 11-04-2016')->getExpression());
     $e = new Event($this->id, 'php bar');
     $this->assertEquals('45 13 * * * *', $e->on('13:45')->getExpression());
     $e = new Event($this->id, 'php foo');
     $this->assertEquals('45 13 * * * *', $e->at('13:45')->getExpression());
     $e = new Event($this->id, 'php bar');
     $e->minute([12, 24, 35])->hour('1-5', 4, 8)->dayOfMonth(1, 6, 12, 19, 25)->month('1-8')->dayOfWeek('mon,wed,thu');
     $this->assertEquals('12,24,35 1-5,4,8 1,6,12,19,25 1-8 mon,wed,thu *', $e->getExpression());
     $e = new Event($this->id, 'php foo');
     $this->assertEquals('45 13 * * * *', $e->cron('45 13 * * * *')->getExpression());
     $e = new Event($this->id, 'php foo');
     $this->assertTrue($e->isDue());
 }