Skip to content

Fix missing item date and description#74

Merged
martialblog merged 1 commit intomainfrom
fix/missing-date
Jan 28, 2026
Merged

Fix missing item date and description#74
martialblog merged 1 commit intomainfrom
fix/missing-date

Conversation

@martialblog
Copy link
Member

Some guardrails when there are invalid items in a feed.

I switched to new DateTime('@0') so that these elements are not shown on top.

Fixed #64

@martialblog martialblog added this to the v0.2.0 milestone Jan 27, 2026
@martialblog martialblog self-assigned this Jan 27, 2026
@martialblog martialblog merged commit e025878 into main Jan 28, 2026
3 checks passed
@martialblog martialblog deleted the fix/missing-date branch January 28, 2026 07:51
$ad = $this->date ?? new DateTime('NOW');
$bd = $other->date ?? new DateTime('NOW');
$ad = $this->date ?? new DateTime('@0');
$bd = $other->date ?? new DateTime('@0');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is actually no need to create DateTime objects here at all.

Simply check if one of the elements is null before trying to compare.

protected function getContentElement(): ?BaseHtmlElement
{
$text = $this->item->description;
$text = $this->item->description ?? '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description was defined as non-null in the same PR

$d = $this->item->date;
$ts = $this->item->date !== null ? $this->item->date->getTimestamp() : 0;

return (new TimeAgo($ts));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous brackets

public ?string $title = null;
public ?string $link = null;
public ?string $description = null;
public string $description = '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't null better than a sentinel value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CNN fails to load

2 participants