From 75dbe29b7bfe1f9135b1c37352569c0590fe6dce Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 16 May 2026 00:18:11 -0700 Subject: Fix timezone shift and script-tag escape in news tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unix-int timestamps from Finnhub were returned as naive UTC, then .timestamp() reinterpreted them as local time — shifting relative ages and date filtering. Now normalize to local-naive like the other branches. Also escape , so headlines containing cannot break out of the inline script. Co-Authored-By: Claude Opus 4.7 --- components/news.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'components') diff --git a/components/news.py b/components/news.py index 90f0ddb..2a22b25 100644 --- a/components/news.py +++ b/components/news.py @@ -1,6 +1,7 @@ """News tab rendered as a client-side HTML surface.""" from datetime import date as _date from datetime import datetime as _dt +from datetime import timezone as _tz from html import escape as _esc import streamlit.components.v1 as components @@ -50,7 +51,7 @@ def _normalize_dt(raw): return _dt(raw.year, raw.month, raw.day) if isinstance(raw, (int, float)): try: - return _dt.utcfromtimestamp(float(raw)) + return _dt.fromtimestamp(float(raw), tz=_tz.utc).astimezone().replace(tzinfo=None) except Exception: return None @@ -163,7 +164,7 @@ def render_news(ticker: str): co_name = _esc(info.get("longName") or info.get("shortName") or ticker.upper()) price_str = "${:,.2f}".format(cur_num) if cur_num is not None else "—" - rows_js = "const NEWS_ROWS=" + _json.dumps(rows) + ";" + rows_js = "const NEWS_ROWS=" + _json.dumps(rows).replace("