-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace EWW\Dpf\Helper; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
class DateTimePrecision | ||
{ | ||
|
||
/** | ||
* Reduce microsecond precision to value that can be handled by PHP 7. | ||
* | ||
* @param String dateTimeString Datetime string | ||
* @return String Precision reduced datetime string | ||
*/ | ||
public static function reducePrecision(String $dateTimeString) | ||
{ | ||
return preg_replace('/(\.\d{6})\d+Z/', '$1Z', $dateTimeString); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace EWW\Dpf\Tests\Unit\Helper; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use Nimut\TestingFramework\TestCase\UnitTestCase; | ||
use EWW\Dpf\Helper\DateTimePrecision; | ||
|
||
class DateTimePrecisionTest extends UnitTestCase { | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function Truncates_microseconds_precision_down_to_six_digits() { | ||
$datetime = "2024-06-12T08:31:11.570355509Z"; | ||
$this->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)); | ||
} | ||
|
||
} |