mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Fix issue with wrong date()
This commit is contained in:
@@ -124,7 +124,11 @@ final readonly class ReleaseItemPayloadBuilder
|
||||
$attributes['grabs'] = $this->value($release, 'grabs');
|
||||
$attributes['comments'] = $this->value($release, 'comments');
|
||||
$attributes['password'] = $this->value($release, 'passwordstatus');
|
||||
$attributes['usenetdate'] = date(DATE_RSS, strtotime((string) $this->value($release, 'postdate')));
|
||||
$usenetTimestamp = $this->timestamp($this->value($release, 'postdate'))
|
||||
?? $this->timestamp($this->value($release, 'adddate'));
|
||||
if ($usenetTimestamp !== null) {
|
||||
$attributes['usenetdate'] = date(DATE_RSS, $usenetTimestamp);
|
||||
}
|
||||
|
||||
$groupName = $this->value($release, 'group_name');
|
||||
if (! empty($groupName)) {
|
||||
@@ -223,4 +227,19 @@ final readonly class ReleaseItemPayloadBuilder
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function timestamp(mixed $value): ?int
|
||||
{
|
||||
if (\is_int($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (! \is_string($value) || trim($value) === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$timestamp = strtotime($value);
|
||||
|
||||
return $timestamp === false ? null : $timestamp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,21 @@ final class XMLResponseTest extends TestCase
|
||||
self::assertStringContainsString('<newznab:attr name="group" value="alt.binaries.testing"/>', $xml);
|
||||
}
|
||||
|
||||
public function test_extended_api_falls_back_to_adddate_for_invalid_postdate(): void
|
||||
{
|
||||
$release = $this->release([
|
||||
'postdate' => 'not-a-date',
|
||||
]);
|
||||
|
||||
$array = $this->response([$release], ['extended' => '1'])->returnArray();
|
||||
|
||||
self::assertIsArray($array);
|
||||
self::assertSame(
|
||||
date(DATE_RSS, strtotime('2026-05-29 12:00:00')),
|
||||
$array['item'][0]['attr']['usenetdate']
|
||||
);
|
||||
}
|
||||
|
||||
public function test_api_rows_are_normalized_from_supported_payload_shapes(): void
|
||||
{
|
||||
$arrayRow = (array) $this->release([
|
||||
|
||||
Reference in New Issue
Block a user