Skip to content

fix: scheduled post filter uses UTC instead of site timezone - #663

Open
WXY-V1hZ wants to merge 1 commit into
satnaing:mainfrom
WXY-V1hZ:fix/scheduled-post-timezone
Open

fix: scheduled post filter uses UTC instead of site timezone#663
WXY-V1hZ wants to merge 1 commit into
satnaing:mainfrom
WXY-V1hZ:fix/scheduled-post-timezone

Conversation

@WXY-V1hZ

@WXY-V1hZ WXY-V1hZ commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Description

The postFilter utility compares pubDatetime against Date.now() to determine whether a scheduled post should be visible. However, new Date("2026-06-28") is interpreted as midnight UTC, while the user may be in a different timezone (e.g., Asia/Shanghai, UTC+8).

This means:

  • If a user writes a post with pubDatetime: 2026-06-28 and builds at 3:00 AM China time, the UTC time is still June 27 19:00 — 5 hours before the intended publish time.
  • In dev mode (import.meta.env.DEV), the time check is skipped, so the post appears. But in production builds, it's silently filtered out — no error, no warning, just a missing page.
  • Only posts with a "today or very recent" pubDatetime are affected, making it hard to reproduce and debug.

Fix: Use dayjs.utc(date).tz(tz, true) to interpret the date in the site's configured timezone rather than UTC. The true parameter ("fixed mode") keeps the calendar values unchanged and shifts the underlying UTC instant accordingly, so 2026-06-28 means "June 28 in Shanghai" not "June 28 at Greenwich".

Types of changes

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Documentation Update (if none of the other choices apply)
  • Others (any other types not listed above)

Checklist

  • I have read the Contributing Guide
  • I have added the necessary documentation (if appropriate)
  • Breaking Change (fix or feature that would cause existing functionality to not work as expected)

Further comments

This only affects users whose timezone offset is positive (east of UTC) and who publish posts on the same day. The existing Datetime.astro component already uses dayjs().tz() with the site's configured timezone for display — this fix brings postFilter in line with that same convention.

Related Issue

No existing issue — discovered during personal use.

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.

1 participant