UTC build server causing client‑side date offset in Astro date frontmatter parsing
0 reputation · 26 Sept 2022, 04:57 UTC
0 reputation · 26 Sept 2022, 04:57 UTC
If the string lacks a timezone designator, the value is interpreted as the local timezone of the build process, which can produce different date values when the same frontmatter is processed on machines with different timezone settings.
The `formatDate` utility defaults to UTC output via `toISOString`, yet the underlying conversion remains ambiguous because the parsed date may represent local time, leading to an unresolved offset between server‑side build dates and client‑side display, as reported in an open issue.
What mechanism should Astro adopt to guarantee consistent date interpretation across diverse timezone environments, and should it default to UTC parsing for frontmatter dates or preserve local interpretation while exposing a clear timezone‑aware API?
35775 reputation · 26 Sept 2022, 12:04 UTC
When Astro parses a frontmatter date value with new Date(value), the string is interpreted in the build process’s local timezone if no zone designator is present. This inconsistency can cause mismatched publication dates, SEO metadata errors, and unexpected UI displays.
new Date(frontmatterDate) interpretation.formatDate calls toISOString, which always yields UTC, but the underlying Date may represent local time.2026-11-12T00:00:00Z or 2026-11-12T00:00:00+00:00).Is the current frontmatter date string already suffixed with a timezone designator, or does it rely on the implicit local timezone?
Use comments to ask for clarification. Post a solution as an answer.
35,775 reputation · 26 Sept 2022, 09:36 UTC
The ES2015+ specification treats YYYY-MM-DD (date-only) as UTC but YYYY-MM-DDTHH:mm:ss (date-time without offset) as local time. This means 2024-06-15 parses consistently across timezones while 2024-06-15T12:00:00 shifts by the build server's offset — a silent inconsistency when both formats appear in the same content collection.
Astro's z.date() schema validates structure but not timezone semantics, so mixing formats passes validation yet produces divergent UTC timestamps after formatDate.
YYYY-MM-DD for date-only intent or YYYY-MM-DDTHH:mm:ssZ for explicit UTC