Skip to content
Snippets Groups Projects
Commit 71476357 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

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.
parent 4134ebfd
No related merge requests found
...@@ -270,6 +270,21 @@ class Server ...@@ -270,6 +270,21 @@ class Server
$this->metadataFormats = []; $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. * Respond to the OAI-PMH request.
* *
...@@ -444,7 +459,7 @@ class Server ...@@ -444,7 +459,7 @@ class Server
// Get modification date: // Get modification date:
$date = $record->getLastIndexed(); $date = $record->getLastIndexed();
if (empty($date)) { if (empty($date)) {
$date = date($this->iso8601); $date = $this->getUTCDateTime('now');
} }
// Set up header (inside or outside a <record> container depending on // Set up header (inside or outside a <record> container depending on
...@@ -987,7 +1002,7 @@ class Server ...@@ -987,7 +1002,7 @@ class Server
} }
} }
if (empty($params['until'])) { if (empty($params['until'])) {
$params['until'] = date($this->iso8601); $params['until'] = $this->getUTCDateTime('now +1 day');
if (strlen($params['until']) > strlen($params['from'])) { if (strlen($params['until']) > strlen($params['from'])) {
$params['until'] = substr($params['until'], 0, 10); $params['until'] = substr($params['until'], 0, 10);
} }
...@@ -1252,7 +1267,7 @@ class Server ...@@ -1252,7 +1267,7 @@ class Server
. 'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd', . 'http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
'http://www.w3.org/2001/XMLSchema-instance' 'http://www.w3.org/2001/XMLSchema-instance'
); );
$xml->responseDate = date($this->iso8601); $xml->responseDate = $this->getUTCDateTime('now');
$xml->request = $this->baseURL; $xml->request = $this->baseURL;
if ($echoParams) { if ($echoParams) {
foreach ($this->params as $key => $value) { foreach ($this->params as $key => $value) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment