Skip to content

Commit

Permalink
[FEATURE] Implement IntlDateFormatter for SolrCoreStatus timestamps (#…
Browse files Browse the repository at this point in the history
…1394)

Co-authored-by: Sebastian Meyer <[email protected]>
  • Loading branch information
fschoelzel and sebastian-meyer authored Dec 16, 2024
1 parent bd529ae commit 2ac3a96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions Classes/Hooks/Form/FieldInformation/SolrCoreStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Kitodo\Dlf\Hooks\Form\FieldInformation;

use IntlDateFormatter;
use Kitodo\Dlf\Common\Helper;
use Kitodo\Dlf\Common\Solr\Solr;
use TYPO3\CMS\Backend\Form\AbstractNode;
Expand All @@ -37,6 +38,14 @@ class SolrCoreStatus extends AbstractNode
public function render(): array
{
$result = $this->initializeResultArray();

// Get date formatter
$dateFormatter = new IntlDateFormatter(
Helper::getLanguageService()->lang, // locale
IntlDateFormatter::MEDIUM, // dateType
IntlDateFormatter::MEDIUM // timeType
);

// Show only when editing existing records.
if ($this->data['command'] !== 'new') {
$core = $this->data['databaseRow']['index_name'];
Expand All @@ -57,8 +66,9 @@ public function render(): array
$dateTimeTo = new \DateTime("@$uptimeInSeconds");
$uptime = $dateTimeFrom->diff($dateTimeTo)->format('%a ' . Helper::getLanguageService()->getLL('flash.days') . ', %H:%I:%S');
$numDocuments = $response->getNumberOfDocuments();
$startTime = $response->getStartTime() ? strftime('%c', $response->getStartTime()->getTimestamp()) : 'N/A';
$lastModified = $response->getLastModified() ? strftime('%c', $response->getLastModified()->getTimestamp()) : 'N/A';
$startTime = $response->getStartTime() ? $dateFormatter->format($response->getStartTime()) : 'N/A';
$lastModified = $response->getLastModified() ? $dateFormatter->format($response->getLastModified()) : 'N/A';

// Create flash message.
Helper::addMessage(
sprintf(Helper::getLanguageService()->getLL('flash.coreStatus'), $startTime, $uptime, $lastModified, $numDocuments),
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/de.locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@
<target><![CDATA[Fehler!]]></target>
</trans-unit>
<trans-unit id="flash.coreStatus" approved="yes">
<source><![CDATA[Start Time: %s<br />Uptime: %s<br />Last Modified: %ss<br />Number of Documents: %u]]></source>
<source><![CDATA[Start Time: %s<br />Uptime: %s<br />Last Modified: %s<br />Number of Documents: %u]]></source>
<target><![CDATA[Startzeit: %s<br />Laufzeit: %s<br />Letzte Änderung: %s<br />Anzahl Dokumente: %u]]></target>
</trans-unit>
<trans-unit id="flash.days" approved="yes">
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Language/locallang_be.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
<source><![CDATA[Error!]]></source>
</trans-unit>
<trans-unit id="flash.coreStatus" approved="yes">
<source><![CDATA[Start Time: %s<br />Uptime: %s<br />Last Modified: %ss<br />Number of Documents: %u]]></source>
<source><![CDATA[Start Time: %s<br />Uptime: %s<br />Last Modified: %s<br />Number of Documents: %u]]></source>
</trans-unit>
<trans-unit id="flash.days" approved="yes">
<source><![CDATA[days]]></source>
Expand Down

0 comments on commit 2ac3a96

Please sign in to comment.