fix: convert feed timestamps to US/Eastern and add test

Made-with: Cursor
This commit is contained in:
cottongin
2026-04-06 21:39:00 -04:00
parent f7b424b692
commit e40023b9f9
2 changed files with 20 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import json import json
import logging import logging
from datetime import datetime, timezone from datetime import datetime, timezone
from zoneinfo import ZoneInfo
import feedparser import feedparser
import requests import requests
@@ -44,6 +45,9 @@ def fetch_and_cache_articles() -> dict:
except Exception: except Exception:
pub_date = datetime.now(timezone.utc) pub_date = datetime.now(timezone.utc)
# Convert to US/Eastern and make naive for SQLite
pub_date = pub_date.astimezone(ZoneInfo("America/New_York")).replace(tzinfo=None)
categories = [t.term for t in entry.get("tags", [])] categories = [t.term for t in entry.get("tags", [])]
content_html = "" content_html = ""

View File

@@ -81,3 +81,19 @@ def test_fetch_handles_feed_error(app, db):
assert result["error"] is not None assert result["error"] is not None
assert Article.query.count() == 0 assert Article.query.count() == 0
def test_fetch_converts_timezone_to_eastern(app, db):
with app.app_context():
with patch("src.fetcher.requests.get") as mock_get:
mock_get.return_value = _mock_feed_response(SAMPLE_RSS_XML)
with patch("src.fetcher.process_image") as mock_img:
mock_img.return_value = ("/fake/path.jpg", 800, 450)
fetch_and_cache_articles()
article = Article.query.filter_by(title="Test Article One").first()
# The XML has: Mon, 06 Apr 2026 12:00:00 +0000
# US/Eastern in April is EDT (UTC-4), so it should be 08:00:00
assert article.pub_date.tzinfo is None
assert article.pub_date.hour == 8
assert article.pub_date.minute == 0