diff --git a/CHANGELOG.md b/CHANGELOG.md index c5f91ae2..30fd7779 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Add logic to set the node's link from the element when isPermaLink="true" and no link is present. (#12) +- Do no longer default to 1800-01-01 as date for fetching feeds (#15) ### Fixed -- Fix: Analysis of relative links for the Atom feed (#13) +- Analysis of relative links for the Atom feed (#10) diff --git a/src/FeedIo/Reader.php b/src/FeedIo/Reader.php index 5687eebb..f7fd058a 100644 --- a/src/FeedIo/Reader.php +++ b/src/FeedIo/Reader.php @@ -66,9 +66,6 @@ public function addParser(ParserAbstract $parser): Reader public function read(string $url, FeedInterface $feed, DateTime $modifiedSince = null): Result { $this->logger->debug("start reading {$url}"); - if (is_null($modifiedSince)) { - $modifiedSince = new DateTime('1800-01-01'); - } try { $this->logger->info("hitting {$url}"); diff --git a/src/FeedIo/Reader/Result.php b/src/FeedIo/Reader/Result.php index 362a6a16..ef7b84c2 100644 --- a/src/FeedIo/Reader/Result.php +++ b/src/FeedIo/Reader/Result.php @@ -32,7 +32,7 @@ class Result public function __construct( protected Document $document, protected FeedInterface $feed, - protected DateTime $modifiedSince, + protected ?DateTime $modifiedSince = null, protected ResponseInterface $response, protected string $url ) { @@ -56,8 +56,15 @@ public function getFeed(): FeedInterface public function getItemsSince(DateTime $since = null): iterable { + $startDate = $since ?? $this->modifiedSince; + + // return all items if no start date is given + if ($startDate === null) { + return $this->feed; + } + $filter = new Chain(); - $filter->add(new Since($since ?? $this->modifiedSince)); + $filter->add(new Since($startDate)); return $filter->filter($this->getFeed()); } diff --git a/tests/FeedIo/ReaderTest.php b/tests/FeedIo/ReaderTest.php index eeec07da..0b9c8db3 100644 --- a/tests/FeedIo/ReaderTest.php +++ b/tests/FeedIo/ReaderTest.php @@ -131,7 +131,7 @@ public function testReadWithoutModifiedSince() $feed = new Feed(); $this->object->addParser($this->getParser()); $result = $this->object->read('fakeurl', $feed); - $this->assertEquals(new \DateTime('1800-01-01'), $result->getModifiedSince()); + $this->assertEquals(null, $result->getModifiedSince()); } public function testReadException()