Fix date picker wrong on certain timezones (#5972)
Timezone with a negative offset weren't working good with date pickers. I split the logic for display and parsing between date only and datetime. Date time is sending and displaying using timezone, and date only is sending and displaying by forcing the date to take its UTC day and month and 00:00:00 time. This way its consistent across all timezones.
This commit is contained in:
@ -33,6 +33,7 @@ export type DateInputProps = {
|
||||
onChange?: (newDate: Nullable<Date>) => void;
|
||||
isDateTimeInput?: boolean;
|
||||
onClear?: () => void;
|
||||
onSubmit?: (newDate: Nullable<Date>) => void;
|
||||
};
|
||||
|
||||
export const DateInput = ({
|
||||
@ -44,6 +45,7 @@ export const DateInput = ({
|
||||
onChange,
|
||||
isDateTimeInput,
|
||||
onClear,
|
||||
onSubmit,
|
||||
}: DateInputProps) => {
|
||||
const [internalValue, setInternalValue] = useState(value);
|
||||
|
||||
@ -59,6 +61,11 @@ export const DateInput = ({
|
||||
onClear?.();
|
||||
};
|
||||
|
||||
const handleMouseSelect = (newDate: Date | null) => {
|
||||
setInternalValue(newDate);
|
||||
onSubmit?.(newDate);
|
||||
};
|
||||
|
||||
const { closeDropdown } = useDropdown(MONTH_AND_YEAR_DROPDOWN_ID);
|
||||
const { closeDropdown: closeDropdownMonthSelect } = useDropdown(
|
||||
MONTH_AND_YEAR_DROPDOWN_MONTH_SELECT_ID,
|
||||
@ -86,9 +93,7 @@ export const DateInput = ({
|
||||
<InternalDatePicker
|
||||
date={internalValue ?? new Date()}
|
||||
onChange={handleChange}
|
||||
onMouseSelect={(newDate: Date | null) => {
|
||||
onEnter(newDate);
|
||||
}}
|
||||
onMouseSelect={handleMouseSelect}
|
||||
clearable={clearable ? clearable : false}
|
||||
isDateTimeInput={isDateTimeInput}
|
||||
onEnter={onEnter}
|
||||
|
||||
Reference in New Issue
Block a user