Fix the détection of bad publication date. fix #245

The previous one was based on the fact that the PHP version used was 64bits and so the unix timestamp could go way back.

With a 32bits PHP that's not the case.  Check the notes in http://php.net/manual/en/function.strtotime.php for more information.
This commit is contained in:
Sébastien Lucas 2016-02-13 06:25:20 +01:00
parent df592eb668
commit 0a0007a096
3 changed files with 39 additions and 6 deletions

View file

@ -173,6 +173,16 @@ class OPDSRenderer
self::getXmlStream ()->endElement ();
}
private function getPublicationDate($book) {
$dateYmd = substr($book->pubdate, 0, 10);
$pubdate = \DateTime::createFromFormat('Y-m-d', $dateYmd);
if ($pubdate === false ||
$pubdate->format ("Y") == "0101" ||
$pubdate->format ("Y") == "0100") {
return "";
}
return $pubdate->format("Y-m-d");
}
private function renderEntry ($entry) {
self::getXmlStream ()->startElement ("title");
@ -218,10 +228,10 @@ class OPDSRenderer
}
if ($entry->book->getPubDate () != "") {
self::getXmlStream ()->startElement ("dcterms:issued");
self::getXmlStream ()->text (date ("Y-m-d", $entry->book->pubdate));
self::getXmlStream ()->text (self::getPublicationDate($entry->book));
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("published");
self::getXmlStream ()->text (date ("Y-m-d", $entry->book->pubdate) . "T08:08:08Z");
self::getXmlStream ()->text (self::getPublicationDate($entry->book) . "T08:08:08Z");
self::getXmlStream ()->endElement ();
}