Repository navigation
fix(keystatic): reject non-midnight UTC Date values in fields.date() parse (#1615) - #1661
Open
thinhnx128 wants to merge 1 commit into
Open
thinhnx128 wants to merge 1 commit into
thinhnx128 wants to merge 1 commit into
Conversation
…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>
🦋 Changeset detectedLatest commit: 1195cbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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
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.
Summary
Updates
fields.date().parseinpackages/keystatic/src/form/fields/date/index.tsxto throw aFieldDataErrorwhenjs-yamlparses an unquoted ISO-8601 timestamp carrying a non-midnight UTC time component into aDateinstance, preventing silent truncation of the time and timezone offset on save.Root Cause
js-yamlautomatically parses unquoted ISO-8601 timestamps (such as2025-05-30T12:00:00+02:00) into JavaScriptDateobjects.fields.date().parsepreviously converted anyDateobject viavalue.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 thatDateinstances passed tofields.date().parseare at00:00:00.000Zbefore extracting theYYYY-MM-DDdate string, throwingFieldDataError("Must be a date without a time component")otherwise.packages/keystatic/src/form/fields/date/date.test.ts: add unit tests verifying midnight UTCDateacceptance, non-midnight UTCDaterejection, andYYYY-MM-DDstring 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.tsFixes #1615