Skip to content

Commit

Permalink
pkp/pkp-lib#9303 Use Carbon for translating dates instead of date()
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Sep 6, 2024
1 parent 6aba5f0 commit bc1a6f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions classes/components/forms/publication/PublishForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion controllers/grid/issues/IssueGridCellProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc1a6f4

Please sign in to comment.