You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
mackeyguenther
changed the title
datetime field: incorrect UTC converstoindatetime field: incorrect UTC conversion
Feb 8, 2025
mackeyguenther
changed the title
datetime field: incorrect UTC conversiondatetime field: incorrect UTC conversion behavior
Feb 8, 2025
The
datetime
field currently captures dates in local time, using an<input>
of typedatetime-local
. However, these values are serialized to content files as UTC by appending a "Z", without correctly adjusting the local time to UTC:https://github.com/Thinkmill/keystatic/blob/4c4b0efa8ecfc45053dee992f7ceb8566c520ede/packages/keystatic/src/form/fields/datetime/index.tsx#L64C1-L70C7
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 text was updated successfully, but these errors were encountered: