Skip to content

Commit

Permalink
[8.x] Add yearlyOn() method to scheduler (#34728)
Browse files Browse the repository at this point in the history
* Add yearlyOn() method to scheduler

* Update ManagesFrequencies.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
u01jmg3 and taylorotwell committed Oct 7, 2020
1 parent 41305c1 commit 6d5f3d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Illuminate/Console/Scheduling/ManagesFrequencies.php
Expand Up @@ -469,6 +469,22 @@ public function yearly()
->spliceIntoPosition(4, 1);
}

/**
* Schedule the event to run yearly on a given month, day, and time.
*
* @param int $month
* @param int $day
* @param string $time
* @return $this
*/
public function yearlyOn($month = 1, $day = 1, $time = '0:0')
{
$this->dailyAt($time);

return $this->spliceIntoPosition(3, $day)
->spliceIntoPosition(4, $month);
}

/**
* Set the days of the week the command should run on.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Console/Scheduling/FrequencyTest.php
Expand Up @@ -164,6 +164,16 @@ public function testYearly()
$this->assertSame('0 0 1 1 *', $this->event->yearly()->getExpression());
}

public function testYearlyOn()
{
$this->assertSame('8 15 5 4 *', $this->event->yearlyOn(4, 5, '15:08')->getExpression());
}

public function testYearlyOnTuesdays()
{
$this->assertSame('1 9 20 7 2', $this->event->tuesdays()->yearlyOn(7, 20, '09:01')->getExpression());
}

public function testFrequencyMacro()
{
Event::macro('everyXMinutes', function ($x) {
Expand Down

0 comments on commit 6d5f3d9

Please sign in to comment.