Private
Public Access
Render article/feed times in the viewer's local timezone, client-side
Everything is stored and server-rendered in UTC (config.settings.base's TIME_ZONE), so article times, the article detail header, and the dashboard's "last fetched" column were always showing UTC regardless of where the viewer actually is. Article/feed timestamps now render as <time datetime="..."> elements carrying the UTC instant plus a UTC-formatted fallback as their initial text; static/js/localize-times.js reformats them using the browser's own timezone via toLocaleString(), both on page load and after every htmx swap (pagination, the inline article expand, the dashboard's retry action all inject new <time> elements without a full page load). No server-side change needed — this doesn't touch the (currently unused) per-user timezone field, and works correctly even if the viewer travels or changes their system timezone, with no settings page required. Verified live in the browser against a UTC-stored timestamp rendering correctly shifted to the sandbox's local zone. Known related issue, out of scope here: the stream's "Received today/yesterday" date-group headers (apps.reader.views._group_by_date) are still computed server-side via timezone.localdate(), which is also effectively UTC — an article just before/after UTC midnight could land in a date group that doesn't match its now-correctly-localized time-of-day. Flagged for the user rather than fixed, since correcting it properly would mean moving date-grouping to the client too. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
90837b339c
commit
fd68400822
5 files changed
+56
-3
No files matched your search
@@ -8,7 +8,9 @@
|
||||
<a href="{% url 'reader:article_detail' article.pk %}" class="article-title"
|
||||
data-inline-url="{% url 'reader:article_inline' article.pk %}"
|
||||
onclick="return toggleArticle(event, {{ article.pk }})">{{ article.title|default:"(untitled)" }}</a>
|
||||
<span class="article-time">{{ article.published_at|date:"g:i A" }}</span>
|
||||
{% if article.published_at %}
|
||||
<time class="article-time" datetime="{{ article.published_at|date:"c" }}" data-local-format="short">{{ article.published_at|date:"g:i A" }}</time>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div id="article-body-{{ article.pk }}" class="article-inline-body" hidden></div>
|
||||
</li>
|
||||
Reference in new issue
Block a user