Thinkmill / Thinkmill/keystatic
`datetime` field: incorrect UTC conversion behavior
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.4k
- Forks
- 159
- Avg merge
- 21h 41m
- Merged PRs (30d)
- 2
Description
The datetime field currently captures dates in local time, using an <input> of type datetime-local. However, these values are serialized to content files as UTC by appending a "Z", without correctly adjusting the local time to UTC:
serialize(value) {
if (value === null) return { value: undefined };
const date = new Date(value + 'Z');
date.toJSON = () => date.toISOString().slice(0, -8);
date.toString = () => date.toISOString().slice(0, -8);
return { value: date };
},
This implementation requires content users to manually adjust deserialized Date objects to the time zone of the content editor, which may not always be known.
Instead, the datetime fields should convert its data from local time to UTC before serialization. This would ensure predictable alignment between content editors and content users.
Overview:
- The datetime-local input type captures dates in local time.
- The current implementation appends a "Z" to the local time, indicating UTC, without converting the local time to UTC.
- This can lead to inconsistencies and unexpected behavior when the serialized date is interpreted as UTC.
- The datetime component should convert the local time to UTC before serializing.
- This change will ensure that the serialized date is consistently interpreted as UTC, leading to more predictable behavior.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/keystatic/src/form/fields/datetime/index.tsx at the serialize implementation linked in the issue. Read how datetime-local values are converted before serialization, then verify behavior across a non-UTC local timezone. Done means serialized dates represent the corresponding UTC instant without requiring content users to adjust deserialized Date objects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100