Skip to content

Commit

Permalink
[11.x] Apply default timezone when casting unix timestamps (#50751)
Browse files Browse the repository at this point in the history
* [11.x] Apply default timezone when casting unix timestamps

* Add additional date_default_timezone_get calls

---------

Co-authored-by: Sergey Danilchenko <s.danilchenko@ttbooking.ru>
Co-authored-by: Dries Vints <dries@vints.be>
  • Loading branch information
3 people authored Mar 25, 2024
1 parent eb6fc3c commit 8c61f50
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Bus/DatabaseBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ protected function toBatch($batch)
(int) $batch->failed_jobs,
(array) json_decode($batch->failed_job_ids, true),
$this->unserialize($batch->options),
CarbonImmutable::createFromTimestamp($batch->created_at),
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at) : $batch->cancelled_at,
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at) : $batch->finished_at
CarbonImmutable::createFromTimestamp($batch->created_at, date_default_timezone_get()),
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at, date_default_timezone_get()) : $batch->cancelled_at,
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at, date_default_timezone_get()) : $batch->finished_at
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Bus/DynamoBatchRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ protected function toBatch($batch)
(int) $batch->failed_jobs,
$batch->failed_job_ids,
$this->unserialize($batch->options) ?? [],
CarbonImmutable::createFromTimestamp($batch->created_at),
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at) : $batch->cancelled_at,
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at) : $batch->finished_at
CarbonImmutable::createFromTimestamp($batch->created_at, date_default_timezone_get()),
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at, date_default_timezone_get()) : $batch->cancelled_at,
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at, date_default_timezone_get()) : $batch->finished_at
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ protected function asDateTime($value)
// and format a Carbon object from this timestamp. This allows flexibility
// when defining your date fields as they might be UNIX timestamps here.
if (is_numeric($value)) {
return Date::createFromTimestamp($value);
return Date::createFromTimestamp($value, date_default_timezone_get());
}

// If the value is in simply year, month, day format, we will instantiate the
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Middleware/SetCacheHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function handle($request, Closure $next, $options = [])

if (isset($options['last_modified'])) {
if (is_numeric($options['last_modified'])) {
$options['last_modified'] = Carbon::createFromTimestamp($options['last_modified']);
$options['last_modified'] = Carbon::createFromTimestamp($options['last_modified'], date_default_timezone_get());
} else {
$options['last_modified'] = Carbon::parse($options['last_modified']);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function all()
'payload' => $result['payload']['S'],
'exception' => $result['exception']['S'],
'failed_at' => Carbon::createFromTimestamp(
(int) $result['failed_at']['N']
(int) $result['failed_at']['N'], date_default_timezone_get()
)->format(DateTimeInterface::ISO8601),
];
})->all();
Expand Down Expand Up @@ -152,7 +152,7 @@ public function find($id)
'payload' => $result['Item']['payload']['S'],
'exception' => $result['Item']['exception']['S'],
'failed_at' => Carbon::createFromTimestamp(
(int) $result['Item']['failed_at']['N']
(int) $result['Item']['failed_at']['N'], date_default_timezone_get()
)->format(DateTimeInterface::ISO8601),
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static function for($duration)
public static function until($timestamp)
{
if (is_numeric($timestamp)) {
$timestamp = Carbon::createFromTimestamp($timestamp);
$timestamp = Carbon::createFromTimestamp($timestamp, date_default_timezone_get());
}

return new static(Carbon::now()->diff($timestamp));
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public function assertCookieExpired($cookieName)
"Cookie [{$cookieName}] not present on response."
);

$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime());
$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime(), date_default_timezone_get());

PHPUnit::assertTrue(
$cookie->getExpiresTime() !== 0 && $expiresAt->lessThan(Carbon::now()),
Expand All @@ -455,7 +455,7 @@ public function assertCookieNotExpired($cookieName)
"Cookie [{$cookieName}] not present on response."
);

$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime());
$expiresAt = Carbon::createFromTimestamp($cookie->getExpiresTime(), date_default_timezone_get());

PHPUnit::assertTrue(
$cookie->getExpiresTime() === 0 || $expiresAt->greaterThan(Carbon::now()),
Expand Down

0 comments on commit 8c61f50

Please sign in to comment.