Skip to content

Commit

Permalink
[1.x] Ensure run at is always returned to the front end in UTC (#425)
Browse files Browse the repository at this point in the history
* ensure run at is always returned to the front end in UTC

* Fix code styling

---------

Co-authored-by: timacdonald <[email protected]>
  • Loading branch information
timacdonald and timacdonald authored Nov 29, 2024
1 parent 17353de commit 8e0107f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Livewire/Concerns/RemembersQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ trait RemembersQueries
public function remember(callable $query, string $key = '', DateTimeInterface|DateInterval|Closure|int|null $ttl = 5): array
{
return App::make(CacheStoreResolver::class)->store()->remember('laravel:pulse:'.static::class.':'.$key.':'.$this->period, $ttl, function () use ($query) {
$start = CarbonImmutable::now()->toDateTimeString();
$start = CarbonImmutable::now('UTC')->toDateTimeString();

[$value, $duration] = Benchmark::value(fn () => $query($this->periodAsInterval()));

Expand Down
15 changes: 15 additions & 0 deletions tests/Feature/Livewire/RemembersQueriesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

use Illuminate\Support\Carbon;
use Laravel\Pulse\Livewire\SlowQueries;
use Livewire\Livewire;

it('always returns the run at date in UTC time', function () {
date_default_timezone_set('Australia/Melbourne');
Carbon::setTestNow(Carbon::createFromFormat('Y-m-d H:i:s', '2000-01-01 13:00:00', 'UTC'));

Livewire::test(SlowQueries::class, ['lazy' => false, 'disableHighlighting' => true])
->assertSeeHtml(<<<'HTML'
Run at: ${formatDate(&#039;2000-01-01 13:00:00&#039;)}
HTML);
});

0 comments on commit 8e0107f

Please sign in to comment.