From bc1a6f43b8fec7383002bcebe003c63425d836b3 Mon Sep 17 00:00:00 2001 From: Alec Smecher Date: Wed, 28 Aug 2024 17:26:34 -0700 Subject: [PATCH] pkp/pkp-lib#9303 Use Carbon for translating dates instead of date() --- classes/components/forms/publication/PublishForm.php | 6 ++++-- controllers/grid/issues/IssueGridCellProvider.php | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/classes/components/forms/publication/PublishForm.php b/classes/components/forms/publication/PublishForm.php index df9ce7a3d53..113748bb69f 100644 --- a/classes/components/forms/publication/PublishForm.php +++ b/classes/components/forms/publication/PublishForm.php @@ -22,6 +22,7 @@ use PKP\components\forms\FormComponent; use PKP\core\Core; use PKP\core\PKPString; +use PKP\facades\Locale; define('FORM_PUBLISH', 'publish'); @@ -72,12 +73,13 @@ public function __construct($action, $publication, $submissionContext, $requirem // If a publication date has already been set and the date has passed this will // be published immediately regardless of the issue assignment if ($publication->getData('datePublished') && $publication->getData('datePublished') <= Core::getCurrentDate()) { - $timestamp = strtotime($publication->getData('datePublished')); $dateFormatLong = PKPString::convertStrftimeFormat($submissionContext->getLocalizedDateFormatLong()); $msg = __( 'publication.publish.confirmation.datePublishedInPast', [ - 'datePublished' => date($dateFormatLong, $timestamp), + 'datePublished' => (new \Carbon\Carbon($publication->getData('datePublished'))) + ->locale(Locale::getLocale()) + ->translatedFormat($dateFormatLong), ] ); $submitLabel = __('publication.publish'); diff --git a/controllers/grid/issues/IssueGridCellProvider.php b/controllers/grid/issues/IssueGridCellProvider.php index 8a124dd87b6..df8ddff50c3 100644 --- a/controllers/grid/issues/IssueGridCellProvider.php +++ b/controllers/grid/issues/IssueGridCellProvider.php @@ -22,6 +22,7 @@ use PKP\controllers\grid\GridColumn; use PKP\controllers\grid\GridHandler; use PKP\core\PKPString; +use PKP\facades\Locale; use PKP\linkAction\LinkAction; use PKP\linkAction\request\AjaxModal; @@ -92,7 +93,7 @@ public function getTemplateVarsFromRowColumn($row, $column) if ($datePublished) { $datePublished = strtotime($datePublished); } - return ['label' => $datePublished ? date($this->dateFormatShort, $datePublished) : '']; + return ['label' => $datePublished ? (new \Carbon\Carbon($datePublished))->locale(Locale::getLocale())->translatedFormat($this->dateFormatShort) : '']; case 'numArticles': return ['label' => $issue->getNumArticles()]; default: assert(false);