The onSubmit handler was setting the datetime-local input's value to an ISO UTC string (e.g. "2026-03-11T17:00:00.000Z"). datetime-local inputs only accept the format "YYYY-MM-DDTHH:MM" — values with a 'Z' timezone suffix are invalid and the browser silently clears the field to "". This caused the form to submit an empty scheduledAt, which the server treated as null, so games were always saved without a date. Fix by keeping the datetime-local input for user interaction (renamed scheduledAtLocal, not submitted) and writing the converted UTC ISO string into a separate hidden input named scheduledAt in the onSubmit handler. Also adds app/lib/date-utils.ts with a localDateTimeToUtcIso helper and matching tests to document and verify the datetime-local ↔ ISO conversion behaviour. https://claude.ai/code/session_0148fgZiXpyvGX8ZX3BFRGCs
18 lines
803 B
TypeScript
18 lines
803 B
TypeScript
/**
|
|
* Converts a datetime-local input value (local time, no timezone info)
|
|
* to a UTC ISO string for server submission.
|
|
*
|
|
* `datetime-local` inputs use the format "YYYY-MM-DDTHH:MM" and do NOT accept
|
|
* ISO strings with a timezone designator (e.g. "2026-03-11T17:00:00.000Z").
|
|
* Setting an ISO UTC string directly on a datetime-local input causes the browser
|
|
* to silently clear the field value. Use this function with a separate hidden input
|
|
* to hold the converted UTC value before form submission.
|
|
*
|
|
* Returns null when value is empty, nullish, or not a valid date.
|
|
*/
|
|
export function localDateTimeToUtcIso(value: string | null | undefined): string | null {
|
|
if (!value) return null;
|
|
const date = new Date(value);
|
|
if (isNaN(date.getTime())) return null;
|
|
return date.toISOString();
|
|
}
|