From 47c94597db93551cb19f4b4a97ce454fc3f28274 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 4 Mar 2025 15:39:50 +0000 Subject: [PATCH] Take the "display timezone" into account when setting Carbon string format --- src/Generator.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index daadae5..e5429df 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -271,7 +271,9 @@ protected function makeContentGenerationClosures($pages, $request) $oldCarbonFormat = $this->getToStringFormat(); if ($this->shouldSetCarbonFormat($page)) { - Carbon::setToStringFormat(Statamic::dateFormat()); + Date::setToStringFormat(function (Carbon $date) { + return $date->setTimezone(config('statamic.system.display_timezone'))->format(Statamic::dateFormat()); + }); } $this->updateCurrentSite($page->site()); @@ -489,7 +491,7 @@ protected function shouldRejectPage($page, $outputError = false) * * @throws \ReflectionException */ - protected function getToStringFormat(): ?string + protected function getToStringFormat(): string|\Closure|null { $reflection = new ReflectionClass($date = Date::now());