Fix timezones

This commit is contained in:
jude 2024-03-01 17:54:05 +00:00
parent e83b643d86
commit 72af0532fa

View File

@ -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",
),
);
}}
></input>
</>