From 72af0532fa5855f4c51edf431895dedd8ab948d8 Mon Sep 17 00:00:00 2001 From: jude Date: Fri, 1 Mar 2024 17:54:05 +0000 Subject: [PATCH] Fix timezones --- .../src/components/Reminder/TimeInput.tsx | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/reminder-dashboard/src/components/Reminder/TimeInput.tsx b/reminder-dashboard/src/components/Reminder/TimeInput.tsx index 8bb563a..c037c46 100644 --- a/reminder-dashboard/src/components/Reminder/TimeInput.tsx +++ b/reminder-dashboard/src/components/Reminder/TimeInput.tsx @@ -17,7 +17,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { const [timezone] = useTimezone(); const [time, setTime] = useState( - defaultValue ? DateTime.fromISO(defaultValue).setZone(timezone) : null, + defaultValue ? DateTime.fromISO(defaultValue, { zone: "UTC" }) : null, ); const updateTime = useCallback( @@ -28,7 +28,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { let newTime = time; if (newTime === null) { - newTime = DateTime.now().setZone(timezone); + newTime = DateTime.now().setZone("UTC"); } setTime(newTime.set(upd)); }, @@ -36,7 +36,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { ); useEffect(() => { - onInput(time?.toFormat("yyyy-LL-dd'T'HH:mm:ss")); + onInput(time?.setZone("UTC").toFormat("yyyy-LL-dd'T'HH:mm:ss")); }, [time]); const flash = useFlash(); @@ -48,7 +48,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { onPaste={(ev) => { ev.preventDefault(); const pasteValue = ev.clipboardData.getData("text/plain"); - let dt = DateTime.fromISO(pasteValue); + let dt = DateTime.fromISO(pasteValue, { zone: timezone }); if (dt.isValid) { setTime(dt); @@ -84,7 +84,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="YYYY" value={ time - ? time.year.toLocaleString("en-US", { + ? time.setZone(timezone).year.toLocaleString("en-US", { minimumIntegerDigits: 4, useGrouping: false, }) @@ -115,7 +115,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="MM" value={ time - ? time.month.toLocaleString("en-US", { + ? time.setZone(timezone).month.toLocaleString("en-US", { minimumIntegerDigits: 2, }) : "" @@ -145,7 +145,9 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="DD" value={ time - ? time.day.toLocaleString("en-US", { minimumIntegerDigits: 2 }) + ? time + .setZone(timezone) + .day.toLocaleString("en-US", { minimumIntegerDigits: 2 }) : "" } onBlur={(ev) => { @@ -172,7 +174,9 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="hh" value={ time - ? time.hour.toLocaleString("en-US", { minimumIntegerDigits: 2 }) + ? time + .setZone(timezone) + .hour.toLocaleString("en-US", { minimumIntegerDigits: 2 }) : "" } onBlur={(ev) => { @@ -200,7 +204,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="mm" value={ time - ? time.minute.toLocaleString("en-US", { + ? time.setZone(timezone).minute.toLocaleString("en-US", { minimumIntegerDigits: 2, }) : "" @@ -230,7 +234,7 @@ export const TimeInput = ({ defaultValue, onInput }) => { placeholder="ss" value={ time - ? time.second.toLocaleString("en-US", { + ? time.setZone(timezone).second.toLocaleString("en-US", { minimumIntegerDigits: 2, }) : "" @@ -279,8 +283,12 @@ export const TimeInput = ({ defaultValue, onInput }) => { ref={ref} onInput={(ev) => { ev.currentTarget.value === "" - ? setTime(null) - : setTime(DateTime.fromISO(ev.currentTarget.value)); + ? updateTime(null) + : setTime( + DateTime.fromISO(ev.currentTarget.value, { zone: timezone }).setZone( + "UTC", + ), + ); }} >