fix: news dates show a day early for viewers west of UTC - #119
Merged
Conversation
The include-releases=true news list emitted dates as midnight UTC (2006-01-02T15:04:05Z format) and then reformatted them client-side with toLocaleDateString in the viewer's local timezone. Midnight UTC converted to any negative-offset zone lands on the previous calendar day, so every article showed one day early for viewers west of UTC.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The homepage news list (rendered via the
include-releases=truepath of thelatest-newsshortcode) shows every article one day early for any viewer whose timezone is behind UTC (all of the Americas, and most of the site's likely audience).Root cause: the server emits each static news item's date as midnight UTC (
.Date.Format "2006-01-02T15:04:05Z"), and the client then formats it withtoLocaleDateStringin the viewer's own timezone. Midnight UTC converted to any negative-offset zone lands on the previous calendar day.The plain (non-
include-releases) path used by/about/news/formats dates entirely server-side and is unaffected.Approach
Format the date on the server, where the intended calendar day is known, instead of shipping a raw instant and re-interpreting it in an unknown client timezone (as the issue proposes):
dateDisplayfield to the JSON news items, computed server-side via.Date.Format "January 2, 2006".renderNews, preferitem.dateDisplaywhen present.dateDisplayfield and carry a real timestamp (published_at, not midnight), so they correctly fall back to the existingformatDate()client-side conversion.datefield is left untouched and still drives sort order.I also checked for the same bug pattern (a server-emitted midnight-UTC instant reformatted with
toLocaleDateStringclient-side) elsewhere in the repo.decentralized-services-issues.htmlandmerged-pull-requests.htmlalso calltoLocaleDateStringclient-side, but onissue.created_at/pr.merged_at— real timestamps from the GitHub API with genuine time-of-day, not midnight-UTC-stamped dates — so timezone conversion there is legitimate and not the same bug. No other instances found.Testing
hugo --minifybuild succeeded; inspected the emitteddata-news-itemsattribute on the built homepage and confirmed each entry now carries a correctdateDisplay(e.g."date":"2026-07-24T00:00:00Z","dateDisplay":"July 24, 2026").renderNews/formatDateJS logic and ran it against the real built news-item JSON underTZ=UTC,TZ=America/Los_Angeles, andTZ=Pacific/Auckland. All three now render identical, correct calendar dates.formatDate(item.date)) against the same data underTZ=America/Los_Angelesreproduces the bug exactly — every date one day early (e.g. July 24 → July 23)./about/news/path (lines untouched by this diff) still formats dates entirely server-side.Closes #80
[AI-assisted - Claude]