fix: news articles showing 1970 dates when published_at is null
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Backend falls back to fetched_at when published_at is NULL in the database, so the API always returns a meaningful date. Frontend also handles null defensively to avoid new Date(null) producing Unix epoch 0.
This commit is contained in:
parent
9f86aaf540
commit
4df7c67c13
2 changed files with 5 additions and 3 deletions
|
|
@ -8,7 +8,7 @@ interface Article {
|
||||||
title: string;
|
title: string;
|
||||||
source: string;
|
source: string;
|
||||||
url: string;
|
url: string;
|
||||||
published_at: string;
|
published_at: string | null;
|
||||||
ticker: string;
|
ticker: string;
|
||||||
sentiment_score: number;
|
sentiment_score: number;
|
||||||
confidence: number;
|
confidence: number;
|
||||||
|
|
@ -105,7 +105,9 @@ export default function NewsFeed() {
|
||||||
<span>{article.source}</span>
|
<span>{article.source}</span>
|
||||||
<span>|</span>
|
<span>|</span>
|
||||||
<span>
|
<span>
|
||||||
{new Date(article.published_at).toLocaleString()}
|
{article.published_at
|
||||||
|
? new Date(article.published_at).toLocaleString()
|
||||||
|
: 'Date unknown'}
|
||||||
</span>
|
</span>
|
||||||
{article.ticker && (
|
{article.ticker && (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ async def list_news(
|
||||||
"published_at": (
|
"published_at": (
|
||||||
article.published_at.isoformat()
|
article.published_at.isoformat()
|
||||||
if article.published_at
|
if article.published_at
|
||||||
else None
|
else article.fetched_at.isoformat()
|
||||||
),
|
),
|
||||||
"fetched_at": article.fetched_at.isoformat(),
|
"fetched_at": article.fetched_at.isoformat(),
|
||||||
"ticker": sentiment.ticker,
|
"ticker": sentiment.ticker,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue