Skip to content

fix(keystatic): reject non-midnight UTC Date values in fields.date() parse (#1615) - #1661

Open
thinhnx128 wants to merge 1 commit into
Thinkmill:mainfrom
thinhnx128:fix/issue-1615-date-field-reject-non-midnight-utc
Open

thinhnx128 wants to merge 1 commit into
Thinkmill:mainfrom
thinhnx128:fix/issue-1615-date-field-reject-non-midnight-utc

Conversation

@thinhnx128

Copy link
Copy Markdown

Summary

Updates fields.date().parse in packages/keystatic/src/form/fields/date/index.tsx to throw a FieldDataError when js-yaml parses an unquoted ISO-8601 timestamp carrying a non-midnight UTC time component into a Date instance, preventing silent truncation of the time and timezone offset on save.

Root Cause

js-yaml automatically parses unquoted ISO-8601 timestamps (such as 2025-05-30T12:00:00+02:00) into JavaScript Date objects. fields.date().parse previously converted any Date object via value.toISOString().slice(0, 10), silently discarding non-midnight time components and shifting dates across UTC boundaries.

Changes

  • packages/keystatic/src/form/fields/date/index.tsx: validate that Date instances passed to fields.date().parse are at 00:00:00.000Z before extracting the YYYY-MM-DD date string, throwing FieldDataError("Must be a date without a time component") otherwise.
  • packages/keystatic/src/form/fields/date/date.test.ts: add unit tests verifying midnight UTC Date acceptance, non-midnight UTC Date rejection, and YYYY-MM-DD string parsing.
  • .changeset/date-field-preserve-non-midnight-instant.md: add patch changeset for @keystatic/core.

Testing

  • pnpm --filter @keystatic/core test packages/keystatic/src/form/fields/date/date.test.ts

Fixes #1615

…dnight Date values (Thinkmill#1615)

- Return `value.toISOString()` in `fields.date().parse()` when a `Date` instance carries a non-zero UTC time component so `validate()` rejects it consistently with quoted ISO datetime strings instead of silently discarding the time.
- Add unit tests in `packages/keystatic/src/form/fields/date/date.test.ts` and a patch changeset.

Fixes Thinkmill#1615

Signed-off-by: Xuan Thinh Nguyen <thinhnx128@gmail.com>
@thinhnx128
thinhnx128 requested a review from emmatown as a code owner November 10, 2026 23:12
@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1195cbf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystatic/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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.

fields.date() silently truncates a frontmatter value that carries a time

1 participant