From 714763572a9deacd3f0a6915dc8c3d4e7bcd2689 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Thu, 21 Mar 2019 09:18:12 -0400 Subject: [PATCH] Resolve OAI-PMH date discrepancies. (#1350) - When generating OAI dates, make sure they are always in UTC. - Also add some tolerance to default 'until' date in case of minor inconsistencies in indexing process. --- module/VuFind/src/VuFind/OAI/Server.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/OAI/Server.php b/module/VuFind/src/VuFind/OAI/Server.php index 5d4c8ac18fa..c396bc23323 100644 --- a/module/VuFind/src/VuFind/OAI/Server.php +++ b/module/VuFind/src/VuFind/OAI/Server.php @@ -270,6 +270,21 @@ class Server $this->metadataFormats = []; } + /** + * Get the current UTC date/time in ISO 8601 format. + * + * @param string $time Time string to represent as UTC (default = 'now') + * + * @return string + */ + protected function getUTCDateTime($time = 'now') + { + // All times must be in UTC, so translate the current time to the + // appropriate time zone: + $utc = new \DateTime($time, new \DateTimeZone('UTC')); + return date_format($utc, $this->iso8601); + } + /** * Respond to the OAI-PMH request. * @@ -444,7 +459,7 @@ class Server // Get modification date: $date = $record->getLastIndexed(); if (empty($date)) { - $date = date($this->iso8601); + $date = $this->getUTCDateTime('now'); } // Set up header (inside or outside a <record> container depending on @@ -987,7 +1002,7 @@ class Server } } if (empty($params['until'])) { - $params['until'] = date($this->iso8601); + $params['until'] = $this->getUTCDateTime('now +1 day'); if (strlen($params['until']) > strlen($params['from'])) { $params['until'] = substr($params['until'], 0, 10); } @@ -1252,7 +1267,7 @@ class Server . 'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd', 'http://www.w3.org/2001/XMLSchema-instance' ); - $xml->responseDate = date($this->iso8601); + $xml->responseDate = $this->getUTCDateTime('now'); $xml->request = $this->baseURL; if ($echoParams) { foreach ($this->params as $key => $value) { -- GitLab