From 88607dc9e2992de6a34b53d97645e305c2bc9312 Mon Sep 17 00:00:00 2001 From: simon <31130607+forgive38@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:52:42 +0100 Subject: [PATCH 1/3] pkp/pkp-lib#10579 set timezone in Carbon date in ReviewAssignmentEmailVariable --- classes/mail/variables/ReviewAssignmentEmailVariable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/mail/variables/ReviewAssignmentEmailVariable.php b/classes/mail/variables/ReviewAssignmentEmailVariable.php index b6920350a2f..3fcb334b415 100644 --- a/classes/mail/variables/ReviewAssignmentEmailVariable.php +++ b/classes/mail/variables/ReviewAssignmentEmailVariable.php @@ -90,7 +90,7 @@ protected function formatDate(string $date, string $locale, Context $context): ? $format = PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort($locale)); - return (new \Carbon\Carbon($time))->locale($locale)->translatedFormat($format); + return (new \Carbon\Carbon($time))->setTimezone(date_default_timezone_get()->locale($locale)->translatedFormat($format); } protected function getRecommendation(string $locale): string From fa51789efc9ff16ec9cc4b3d18a0064022fbd702 Mon Sep 17 00:00:00 2001 From: simon <31130607+forgive38@users.noreply.github.com> Date: Tue, 5 Nov 2024 16:55:39 +0100 Subject: [PATCH 2/3] update --- classes/mail/variables/ReviewAssignmentEmailVariable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/mail/variables/ReviewAssignmentEmailVariable.php b/classes/mail/variables/ReviewAssignmentEmailVariable.php index 3fcb334b415..4b094615385 100644 --- a/classes/mail/variables/ReviewAssignmentEmailVariable.php +++ b/classes/mail/variables/ReviewAssignmentEmailVariable.php @@ -90,7 +90,7 @@ protected function formatDate(string $date, string $locale, Context $context): ? $format = PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort($locale)); - return (new \Carbon\Carbon($time))->setTimezone(date_default_timezone_get()->locale($locale)->translatedFormat($format); + return (new \Carbon\Carbon($time))->setTimezone(date_default_timezone_get())->locale($locale)->translatedFormat($format); } protected function getRecommendation(string $locale): string From dfb5b47706a18da28c4f1f01cadee293cd40ad19 Mon Sep 17 00:00:00 2001 From: simon <31130607+forgive38@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:56:54 +0100 Subject: [PATCH 3/3] pkp/pkp-lib#10579 use Carbon to parse date string --- .../mail/variables/ReviewAssignmentEmailVariable.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/classes/mail/variables/ReviewAssignmentEmailVariable.php b/classes/mail/variables/ReviewAssignmentEmailVariable.php index 4b094615385..b8ad75d4052 100644 --- a/classes/mail/variables/ReviewAssignmentEmailVariable.php +++ b/classes/mail/variables/ReviewAssignmentEmailVariable.php @@ -82,15 +82,13 @@ public function values(string $locale): array protected function formatDate(string $date, string $locale, Context $context): ?string { - $time = strtotime($date); - - if ($time === -1 || $time === false) { + try { + $carbonDate = (new \Carbon\Carbon($date)); + $format = PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort($locale)); + return $carbonDate->locale($locale)->translatedFormat($format); + } catch (\Carbon\Exceptions\InvalidFormatException $exp) { return null; } - - $format = PKPString::convertStrftimeFormat($context->getLocalizedDateFormatShort($locale)); - - return (new \Carbon\Carbon($time))->setTimezone(date_default_timezone_get())->locale($locale)->translatedFormat($format); } protected function getRecommendation(string $locale): string