From 6c7eec873ab6a58165aafaf0956fc9316f46e519 Mon Sep 17 00:00:00 2001 From: Ralf Claussnitzer Date: Fri, 14 Jun 2024 14:52:24 +0200 Subject: [PATCH] Fix timestamp precision handling on PHP 7.3 PHP 7 cannot handle timestame precision with more than six digits as delivered by Fedora 6.5. This commit truncates the microsecond part down this limit for `created` and `lastModified` repository properties. Resolves https://git.slub-dresden.de/kitodo-publication/issues/-/issues/1910 --- Classes/Domain/Model/Document.php | 5 ++- Classes/Helper/DateTimePrecision.php | 31 ++++++++++++++ Tests/Unit/Helper/DateTimePrecisionTest.php | 46 +++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 Classes/Helper/DateTimePrecision.php create mode 100644 Tests/Unit/Helper/DateTimePrecisionTest.php diff --git a/Classes/Domain/Model/Document.php b/Classes/Domain/Model/Document.php index 3fa2dcbd..529b5feb 100644 --- a/Classes/Domain/Model/Document.php +++ b/Classes/Domain/Model/Document.php @@ -16,6 +16,7 @@ use EWW\Dpf\Domain\Workflow\DocumentWorkflow; use EWW\Dpf\Services\Api\InternalFormat; +use EWW\Dpf\Helper\DateTimePrecision; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; /** @@ -768,7 +769,7 @@ public function getRemoteLastModDate() */ public function setRemoteLastModDate($remoteLastModDate) { - $this->remoteLastModDate = $remoteLastModDate; + $this->remoteLastModDate = DateTimePrecision::reducePrecision($remoteLastModDate); } /** @@ -1018,7 +1019,7 @@ public function getCreationDate(): string */ public function setCreationDate(string $creationDate): void { - $this->creationDate = $creationDate; + $this->creationDate = DateTimePrecision::reducePrecision($creationDate); } /** diff --git a/Classes/Helper/DateTimePrecision.php b/Classes/Helper/DateTimePrecision.php new file mode 100644 index 00000000..8d71cbe6 --- /dev/null +++ b/Classes/Helper/DateTimePrecision.php @@ -0,0 +1,31 @@ +assertEquals("2024-06-12T08:31:11.570355Z", DateTimePrecision::reducePrecision($datetime)); + } + + /** + * @test + */ + public function No_truncation_on_six_digit_precision_() { + $datetime = "2024-06-12T08:31:11.570355Z"; + $this->assertEquals("2024-06-12T08:31:11.570355Z", DateTimePrecision::reducePrecision($datetime)); + } + + /** + * @test + */ + public function No_truncation_on_less_than_six_digit_precision_() { + $datetime = "2024-06-12T08:31:11.570Z"; + $this->assertEquals("2024-06-12T08:31:11.570Z", DateTimePrecision::reducePrecision($datetime)); + } + +}