Skip to content

Commit 9be49b4

Browse files
[4.x] Improved Timezone Handling (#197)
* Take the "display timezone" into account when setting Carbon string format * Use `Statamic::displayTimezone()`
1 parent 08e44b1 commit 9be49b4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Generator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ protected function makeContentGenerationClosures($pages, $request)
271271
$oldCarbonFormat = $this->getToStringFormat();
272272

273273
if ($this->shouldSetCarbonFormat($page)) {
274-
Carbon::setToStringFormat(Statamic::dateFormat());
274+
Date::setToStringFormat(function (Carbon $date) {
275+
return $date->setTimezone(Statamic::displayTimezone())->format(Statamic::dateFormat());
276+
});
275277
}
276278

277279
$this->updateCurrentSite($page->site());
@@ -489,7 +491,7 @@ protected function shouldRejectPage($page, $outputError = false)
489491
*
490492
* @throws \ReflectionException
491493
*/
492-
protected function getToStringFormat(): ?string
494+
protected function getToStringFormat(): string|\Closure|null
493495
{
494496
$reflection = new ReflectionClass($date = Date::now());
495497

0 commit comments

Comments
 (0)