Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Apply default timezone when casting unix timestamps #50751

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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