Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
/compatibility_test export-ignore
/demo export-ignore
/tests export-ignore
/utils/PHPStan export-ignore
.gitattributes export-ignore
.editorconfig export-ignore
.gitignore export-ignore
ROADMAP.md export-ignore
phpunit.xml.dist export-ignore
.php-cs-fixer.dist.php export-ignore
db.sql export-ignore
phpstan.dist.neon export-ignore
2 changes: 1 addition & 1 deletion src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __construct(string $url, int $timeout = 10, int $redirects = 5,
}
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.21.6', '>=')) {
curl_setopt($fp, CURLOPT_ACCEPT_ENCODING, '');
} elseif (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) {
} else {
curl_setopt($fp, CURLOPT_ENCODING, '');
}
curl_setopt($fp, CURLOPT_URL, $url);
Expand Down
2 changes: 1 addition & 1 deletion src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public function get_date(string $date_format = 'j F Y, g:i a')
return $this->data['date']['parsed'];

default:
return date($date_format, $this->data['date']['parsed']);
return $this->data['date']['parsed'] !== null ? date($date_format, $this->data['date']['parsed']) : null;
}
}

Expand Down
49 changes: 46 additions & 3 deletions tests/Unit/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public function test_get_content(string $data, string $expected): void
}

/**
* @return array<string, array{string, int|null}>
* @return array<string, array{0: string, 1: int|string|null, 2?: string}>
*/
public static function getDateDataProvider(): array
{
Expand Down Expand Up @@ -1318,13 +1318,56 @@ public static function getDateDataProvider(): array
,
1168531200,
],
'Test RFC 2822 formatted date' => [
<<<XML
<rss version="2.0">
<channel>
<item>
<pubDate>Thu, 11 Jan 2007 16:00:00 +0000</pubDate>
</item>
</channel>
</rss>
XML
,
1168531200
],
'Test date is properly formatted' => [
<<<XML
<rss version="2.0">
<channel>
<item>
<pubDate>Thu, 11 Jan 2007 16:00:00 +0000</pubDate>
</item>
</channel>
</rss>
XML
,
'2007-01-11',
'Y-m-d'
],
'Invalid format: localized RFC 2822 formatted date' => [
<<<XML
<rss version="2.0">
<channel>
<item>
<pubDate>Ost, 11 Urt 2007 16:00:00 +0000</pubDate>
</item>
</channel>
</rss>
XML
,
null,
'Y-m-d'
],
];
}

/**
* @param int|string|null $expected
*
* @dataProvider getDateDataProvider
*/
public function test_get_date(string $data, ?int $expected): void
public function test_get_date(string $data, $expected, string $format = 'U'): void
{
$feed = new SimplePie();
$feed->set_raw_data($data);
Expand All @@ -1334,7 +1377,7 @@ public function test_get_date(string $data, ?int $expected): void
$item = $feed->get_item(0);
self::assertInstanceOf(Item::class, $item);

self::assertSame($expected, $item->get_date('U'));
self::assertSame($expected, $item->get_date($format));
}

/**
Expand Down