Skip to content

Commit 8c61f50

Browse files
daniserSergey Danilchenkodriesvints
authored
[11.x] Apply default timezone when casting unix timestamps (#50751)
* [11.x] Apply default timezone when casting unix timestamps * Add additional date_default_timezone_get calls --------- Co-authored-by: Sergey Danilchenko <[email protected]> Co-authored-by: Dries Vints <[email protected]>
1 parent eb6fc3c commit 8c61f50

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

src/Illuminate/Bus/DatabaseBatchRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ protected function toBatch($batch)
374374
(int) $batch->failed_jobs,
375375
(array) json_decode($batch->failed_job_ids, true),
376376
$this->unserialize($batch->options),
377-
CarbonImmutable::createFromTimestamp($batch->created_at),
378-
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at) : $batch->cancelled_at,
379-
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at) : $batch->finished_at
377+
CarbonImmutable::createFromTimestamp($batch->created_at, date_default_timezone_get()),
378+
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at, date_default_timezone_get()) : $batch->cancelled_at,
379+
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at, date_default_timezone_get()) : $batch->finished_at
380380
);
381381
}
382382

src/Illuminate/Bus/DynamoBatchRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ protected function toBatch($batch)
411411
(int) $batch->failed_jobs,
412412
$batch->failed_job_ids,
413413
$this->unserialize($batch->options) ?? [],
414-
CarbonImmutable::createFromTimestamp($batch->created_at),
415-
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at) : $batch->cancelled_at,
416-
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at) : $batch->finished_at
414+
CarbonImmutable::createFromTimestamp($batch->created_at, date_default_timezone_get()),
415+
$batch->cancelled_at ? CarbonImmutable::createFromTimestamp($batch->cancelled_at, date_default_timezone_get()) : $batch->cancelled_at,
416+
$batch->finished_at ? CarbonImmutable::createFromTimestamp($batch->finished_at, date_default_timezone_get()) : $batch->finished_at
417417
);
418418
}
419419

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ protected function asDateTime($value)
14591459
// and format a Carbon object from this timestamp. This allows flexibility
14601460
// when defining your date fields as they might be UNIX timestamps here.
14611461
if (is_numeric($value)) {
1462-
return Date::createFromTimestamp($value);
1462+
return Date::createFromTimestamp($value, date_default_timezone_get());
14631463
}
14641464

14651465
// If the value is in simply year, month, day format, we will instantiate the

src/Illuminate/Http/Middleware/SetCacheHeaders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function handle($request, Closure $next, $options = [])
5656

5757
if (isset($options['last_modified'])) {
5858
if (is_numeric($options['last_modified'])) {
59-
$options['last_modified'] = Carbon::createFromTimestamp($options['last_modified']);
59+
$options['last_modified'] = Carbon::createFromTimestamp($options['last_modified'], date_default_timezone_get());
6060
} else {
6161
$options['last_modified'] = Carbon::parse($options['last_modified']);
6262
}

src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function all()
119119
'payload' => $result['payload']['S'],
120120
'exception' => $result['exception']['S'],
121121
'failed_at' => Carbon::createFromTimestamp(
122-
(int) $result['failed_at']['N']
122+
(int) $result['failed_at']['N'], date_default_timezone_get()
123123
)->format(DateTimeInterface::ISO8601),
124124
];
125125
})->all();
@@ -152,7 +152,7 @@ public function find($id)
152152
'payload' => $result['Item']['payload']['S'],
153153
'exception' => $result['Item']['exception']['S'],
154154
'failed_at' => Carbon::createFromTimestamp(
155-
(int) $result['Item']['failed_at']['N']
155+
(int) $result['Item']['failed_at']['N'], date_default_timezone_get()
156156
)->format(DateTimeInterface::ISO8601),
157157
];
158158
}

src/Illuminate/Support/Sleep.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static function for($duration)
9292
public static function until($timestamp)
9393
{
9494
if (is_numeric($timestamp)) {
95-
$timestamp = Carbon::createFromTimestamp($timestamp);
95+
$timestamp = Carbon::createFromTimestamp($timestamp, date_default_timezone_get());
9696
}
9797

9898
return new static(Carbon::now()->diff($timestamp));

src/Illuminate/Testing/TestResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public function assertCookieExpired($cookieName)
432432
"Cookie [{$cookieName}] not present on response."
433433
);
434434

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

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

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

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

0 commit comments

Comments
 (0)