import React, { ChangeEventHandler, useState } from "react"; import { setHours, setMinutes } from "date-fns"; import { DayPicker } from "react-day-picker"; export function InputTime() { const [selected, setSelected] = useState(); const [timeValue, setTimeValue] = useState("00:00"); const handleTimeChange: ChangeEventHandler = (e) => { const time = e.target.value; if (!selected) { setTimeValue(time); return; } const [hours, minutes] = time.split(":").map((str) => parseInt(str, 10)); const newSelectedDate = setHours(setMinutes(selected, minutes), hours); setSelected(newSelectedDate); setTimeValue(time); }; const handleDaySelect = (date: Date | undefined) => { if (!timeValue || !date) { setSelected(date); return; } const [hours, minutes] = timeValue .split(":") .map((str) => parseInt(str, 10)); const newDate = new Date( date.getFullYear(), date.getMonth(), date.getDate(), hours, minutes ); setSelected(newDate); }; return (
); }