diff --git a/config/constants.config.php b/config/constants.config.php index a970072702f..f6220ced6e5 100644 --- a/config/constants.config.php +++ b/config/constants.config.php @@ -33,3 +33,6 @@ ? getenv('VUFIND_CACHE_DIR') : (strlen(LOCAL_OVERRIDE_DIR) > 0 ? LOCAL_OVERRIDE_DIR . '/cache' : '')) ); + +// Define database datetime format +defined('VUFIND_DATABASE_DATETIME_FORMAT') || define('VUFIND_DATABASE_DATETIME_FORMAT', 'Y-m-d H:i:s'); diff --git a/module/VuFind/src/VuFind/Crypt/SecretCalculator.php b/module/VuFind/src/VuFind/Crypt/SecretCalculator.php index 0dc9fa88f04..344a0d789c0 100644 --- a/module/VuFind/src/VuFind/Crypt/SecretCalculator.php +++ b/module/VuFind/src/VuFind/Crypt/SecretCalculator.php @@ -67,7 +67,7 @@ public function getSearchUnsubscribeSecret(SearchEntityInterface $search): strin $data = [ 'id' => $search->getId(), 'user_id' => $user->getId(), - 'created' => $user->getCreated()->format('Y-m-d H:i:s'), + 'created' => $user->getCreated()->format(VUFIND_DATABASE_DATETIME_FORMAT), ]; return $this->hmac->generate(array_keys($data), $data); } diff --git a/module/VuFind/src/VuFind/Db/Feature/DateTimeTrait.php b/module/VuFind/src/VuFind/Db/Feature/DateTimeTrait.php index 9896eee9209..47107020daa 100644 --- a/module/VuFind/src/VuFind/Db/Feature/DateTimeTrait.php +++ b/module/VuFind/src/VuFind/Db/Feature/DateTimeTrait.php @@ -53,7 +53,8 @@ trait DateTimeTrait protected function getNullableDateTimeFromNonNullable(DateTime $date): ?DateTime { // Compare strings to avoid trouble with time zones: - return $date->format('Y-m-d H:i:s') !== $this->getUnassignedDefaultDateTime()->format('Y-m-d H:i:s') + return $date->format(VUFIND_DATABASE_DATETIME_FORMAT) + !== $this->getUnassignedDefaultDateTime()->format(VUFIND_DATABASE_DATETIME_FORMAT) ? $date : null; } diff --git a/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php b/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php index 09dc6871453..51b01f0abf9 100644 --- a/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php +++ b/module/VuFind/src/VuFind/Db/Service/AccessTokenService.php @@ -134,7 +134,7 @@ public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int $subQueryBuilder->select('CONCAT(a.id, a.type)') ->from(AccessTokenEntityInterface::class, 'a') ->where('a.created < :latestCreated') - ->setParameter('latestCreated', $dateLimit->format('Y-m-d H:i:s')); + ->setParameter('latestCreated', $dateLimit->format(VUFIND_DATABASE_DATETIME_FORMAT)); if ($limit) { $subQueryBuilder->setMaxResults($limit); } diff --git a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php index 1fdd3bfec41..d5bb0558bf8 100644 --- a/module/VuFind/src/VuFind/Db/Service/AuthHashService.php +++ b/module/VuFind/src/VuFind/Db/Service/AuthHashService.php @@ -135,7 +135,7 @@ public function deleteExpired(DateTime $dateLimit, ?int $limit = null): int $subQueryBuilder->select('ah.id') ->from(AuthHashEntityInterface::class, 'ah') ->where('ah.created < :dateLimit') - ->setParameter('dateLimit', $dateLimit->format('Y-m-d H:i:s')); + ->setParameter('dateLimit', $dateLimit->format(VUFIND_DATABASE_DATETIME_FORMAT)); if ($limit) { $subQueryBuilder->setMaxResults($limit); } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/OAuth2/Repository/AbstractTokenRepositoryTestCase.php b/module/VuFind/tests/unit-tests/src/VuFindTest/OAuth2/Repository/AbstractTokenRepositoryTestCase.php index 598daa9841f..dba8bb30b6c 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/OAuth2/Repository/AbstractTokenRepositoryTestCase.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/OAuth2/Repository/AbstractTokenRepositoryTestCase.php @@ -356,7 +356,7 @@ protected function createTokenId(): string */ protected function createExpiryDateTime(): \DateTimeImmutable { - return new \DateTimeImmutable(date('Y-m-d H:i:s', strtotime('now+1hour'))); + return new \DateTimeImmutable('now+1hour'); } /** diff --git a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php index 659ce028428..53fdb8af53d 100644 --- a/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php +++ b/module/VuFindApi/src/VuFindApi/Controller/SearchApiController.php @@ -476,7 +476,7 @@ function ( $resumptionToken = $this->createResumptionToken($request, $nextCursor, $nextCursorMark); $response['resumptionToken'] = [ 'token' => $resumptionToken->getToken(), - 'expires' => $resumptionToken->getExpiry()->format('Y-m-d H:i:s'), + 'expires' => $resumptionToken->getExpiry()->format(VUFIND_DATABASE_DATETIME_FORMAT), ]; } return $response; diff --git a/tests/phpstan-constants.php b/tests/phpstan-constants.php index 7e90a803c9f..898596b1181 100644 --- a/tests/phpstan-constants.php +++ b/tests/phpstan-constants.php @@ -5,4 +5,5 @@ const DEFAULT_SEARCH_BACKEND = 'Solr'; const LOCAL_CACHE_DIR = './local'; const LOCAL_OVERRIDE_DIR = '.'; +const VUFIND_DATABASE_DATETIME_FORMAT = 'Y-m-d H:i:s';