Skip to content

Commit

Permalink
fix: Support RSS feeds with dates in two-digits
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Jul 20, 2024
1 parent efbbda2 commit 01f87f2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/SpiderBits/src/feeds/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static function parse(string $string_date): \DateTimeImmutable|false
// been removed.
// @see https://github.com/alexdebril/feed-io/blob/main/src/FeedIo/Rule/DateTimeBuilder.php
$date_formats = [
'D, d M y H:i:s O', // RSS with year in 2-digits
\DateTimeInterface::RFC2822, // RSS
\DateTimeInterface::RFC3339, // Atom
\DateTimeInterface::RFC3339_EXTENDED,
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/SpiderBits/feeds/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ public function testFromTextWithDatesWithMilliseconds(): void
$this->assertSame(1633339200, $entry->published_at->getTimestamp());
}

public function testFromTextWithYearsInTwoDigits(): void
{
$feed_as_string = file_get_contents(self::$examples_path . '/years-in-two-digits.rss.xml');

$this->assertNotFalse($feed_as_string);

$feed = Feed::fromText($feed_as_string);

$this->assertSame('rss', $feed->type);
$this->assertSame('A feed with years in 2-digits', $feed->title);
$this->assertSame(1, count($feed->entries));
$entry = $feed->entries[0];
$this->assertNotNull($entry->published_at);
$this->assertSame(1721458536, $entry->published_at->getTimestamp());
}

public function testFromTextWithEmptyRss(): void
{
$feed = Feed::fromText('<rss></rss>');
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/SpiderBits/feeds/examples/years-in-two-digits.rss.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title>A feed with years in 2-digits</title>
<pubDate>Sat, 20 Jul 24 10:32:04 +0200</pubDate>
<link>https://example.org</link>
<atom:link rel="self" type="application/rss+xml" href="https://example.org/feed.rss"/>
<item>
<title>My article</title>
<description></description>
<pubDate>Sat, 20 Jul 24 08:55:36 +0200</pubDate>
<link>https://example.org/my-article</link>
<guid>https://example.org/my-article</guid>
</item>
</channel>
</rss>

0 comments on commit 01f87f2

Please sign in to comment.