diff --git a/src/components/DateRangePicker.tsx b/src/components/DateRangePicker.tsx index 49b62bd..c0b94da 100644 --- a/src/components/DateRangePicker.tsx +++ b/src/components/DateRangePicker.tsx @@ -38,13 +38,41 @@ const DateRangePicker: React.FC = ({ dateRange, onChange, return date.toLocaleDateString('pt-BR', { day: '2-digit', month: '2-digit', year: '2-digit' }); }; + const formatDateForInput = (date: Date) => { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + return `${year}-${month}-${day}`; + }; + + const parseLocalDate = (value: string) => { + if (!value) return null; + const [year, month, day] = value.split('-'); + return new Date(parseInt(year), parseInt(month) - 1, parseInt(day)); + }; + + const handleStartChange = (e: React.ChangeEvent) => { + const newStart = parseLocalDate(e.target.value); + if (newStart && !isNaN(newStart.getTime())) { + onChange({ ...dateRange, start: newStart }); + } + }; + + const handleEndChange = (e: React.ChangeEvent) => { + const newEnd = parseLocalDate(e.target.value); + if (newEnd && !isNaN(newEnd.getTime())) { + newEnd.setHours(23, 59, 59, 999); + onChange({ ...dateRange, end: newEnd }); + } + }; + return (
{/* Date Presets Dropdown */}
@@ -77,7 +129,7 @@ const DateRangePicker: React.FC = ({ dateRange, onChange,