Skip to content

Add hour/minute/timezone to blog post dates#151

Merged
miguelaenlle merged 5 commits into
mainfrom
miguelaenlle/blog-dates-utc-timezone
May 21, 2026
Merged

Add hour/minute/timezone to blog post dates#151
miguelaenlle merged 5 commits into
mainfrom
miguelaenlle/blog-dates-utc-timezone

Conversation

@miguelaenlle
Copy link
Copy Markdown
Collaborator

@miguelaenlle miguelaenlle commented May 21, 2026

Description

  • Posting the AI grading blog post resulted in "19 hours ago" appearing on the PL homepage at 2026-05-21 1:32 PM CT, since its publication date was specified at 2026-05-21 00:00 UTC.

Claude: 2026-05-21 00:00 UTC converts to 2026-05-20 7:00 PM CT (Central Daylight Time, UTC-5 in May). From 7:00 PM CT on May 20 to 1:32 PM CT on May 21 is 18 hours and 32 minutes.

  • On the blog post page, all dates were expected to be in UTC. As a result, the displayed dates were different from those specified in the code. E.g. Specifying 2026-05-21 would result in 2026-05-20 being displayed.
  • Added support to specify the hour/minute of a blog post and its timezone.
  • Here's what the homepage looks like now (assuming no news item was dismissed):
Screenshot 2026-05-21 at 2 34 55 PM (Viewing at 2:35 PM CT, post was from 1:32PM CT of the same day)

Testing

  • View the blog posts and compare their displayed publication dates to what's in the code.
  • Run the marketing site. Then, in the main PL repository, set newsFeedUrl to http://localhost:3000/blog/rss.xml, sync the news items, and check that the time since each article's publication is correct.

Frontmatter date-only strings like "2026-05-21" were parsed by `new Date()`
as UTC midnight, which displayed as the previous day for any viewer west of
UTC and caused the PrairieLearn news popup's "X hours ago" to be off by up
to a full day. Switch the five existing posts to full ISO timestamps with
US Central offsets, and parse dates with date-fns `parseISO` (treats
date-only strings as local time) in the blog index, post layout, RSS feed,
and sort.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marketing Ready Ready Preview, Comment May 21, 2026 8:19pm

Request Review

@miguelaenlle miguelaenlle marked this pull request as draft May 21, 2026 19:31
@miguelaenlle miguelaenlle changed the title Fix blog dates rendering in UTC instead of author's timezone Add hour/minute/timezone to blog post dates May 21, 2026
`format(parseISO(date), ...)` formats in the local timezone, so the static
HTML rendered on Vercel (UTC) and the client hydration in the viewer's
timezone could disagree by a day for west-of-UTC viewers — the same off-by-
one symptom as before. Extract a small `formatBlogDate` helper that uses
`Intl.DateTimeFormat` pinned to America/Chicago, so the rendered calendar
date is identical regardless of where the code runs.

Lives in a separate file from `lib/blog.ts` (which imports `fs`) to keep
the client bundle clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@miguelaenlle miguelaenlle marked this pull request as ready for review May 21, 2026 19:47
Comment thread src/lib/blogDate.ts Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, IMO there's no reason for this to be a separate file, this can just live in lib/blog.ts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed blogDate.ts and moved it into blog.ts.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/lib/blogDate.ts Outdated
year: "numeric",
month: "long",
day: "numeric",
timeZone: "America/Chicago",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding seems reasonable enough given that we're only rendering dates and not times - I'd want a different approach if we were doing times.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per review, drop the standalone lib/blogDate.ts and move formatBlogDate
back to lib/blog.ts. Moves getAllPosts (the only fs-using piece, used
solely in this page's getStaticProps) inline into pages/about/blog/index.tsx
so lib/blog.ts stays free of node-only imports and is safe to bundle into
the client component that calls formatBlogDate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@miguelaenlle miguelaenlle merged commit 8f6bf7b into main May 21, 2026
3 checks passed
@miguelaenlle miguelaenlle deleted the miguelaenlle/blog-dates-utc-timezone branch May 21, 2026 20:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants