Skip to content

Commit

Permalink
Fix defaultTimezone not respected in scheduled Events
Browse files Browse the repository at this point in the history
Co-Authored-By: Stephen Odoardi <sodoardi@users.noreply.github.com>
  • Loading branch information
GrahamCampbell and sodoardi committed Aug 12, 2020
1 parent 0001ade commit 00eeef9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Console/Scheduling/CallbackEvent.php
Expand Up @@ -28,11 +28,12 @@ class CallbackEvent extends Event
* @param \Illuminate\Console\Scheduling\EventMutex $mutex
* @param string $callback
* @param array $parameters
* @param \DateTimeZone|string|null $timezone
* @return void
*
* @throws \InvalidArgumentException
*/
public function __construct(EventMutex $mutex, $callback, array $parameters = [])
public function __construct(EventMutex $mutex, $callback, array $parameters = [], $timezone = null)
{
if (! is_string($callback) && ! is_callable($callback)) {
throw new InvalidArgumentException(
Expand All @@ -43,6 +44,7 @@ public function __construct(EventMutex $mutex, $callback, array $parameters = []
$this->mutex = $mutex;
$this->callback = $callback;
$this->parameters = $parameters;
$this->timezone = $timezone;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/Schedule.php
Expand Up @@ -91,7 +91,7 @@ public function __construct($timezone = null)
public function call($callback, array $parameters = [])
{
$this->events[] = $event = new CallbackEvent(
$this->eventMutex, $callback, $parameters
$this->eventMutex, $callback, $parameters, $this->timezone
);

return $event;
Expand Down
13 changes: 13 additions & 0 deletions tests/Console/ConsoleEventSchedulerTest.php
Expand Up @@ -117,6 +117,19 @@ public function testCreateNewArtisanCommandUsingCommandClass()
$binary = $escape.PHP_BINARY.$escape;
$this->assertEquals($binary.' artisan foo:bar --force', $events[0]->command);
}

public function testCallCreatesNewJobWithTimezone()
{
$schedule = new Schedule('UTC');
$schedule->call('path/to/command');
$events = $schedule->events();
$this->assertSame('UTC', $events[0]->timezone);

$schedule = new Schedule('Asia/Tokyo');
$schedule->call('path/to/command');
$events = $schedule->events();
$this->assertSame('Asia/Tokyo', $events[0]->timezone);
}
}

class FooClassStub
Expand Down

0 comments on commit 00eeef9

Please sign in to comment.