Refactor date change handling in DateTimeField to ensure proper timezone formatting and fallback to ISO string

This commit is contained in:
Elio Struyf
2025-07-14 21:24:31 +02:00
parent 76b103cb62
commit 99405042ed

View File

@@ -40,11 +40,13 @@ export const DateTimeField: React.FunctionComponent<IDateTimeFieldProps> = ({
const onDateChange = React.useCallback((date: Date) => {
setDateValue(date);
if (format) {
// Always use DateHelper.formatInTimezone when a format is provided
onChange(DateHelper.formatInTimezone(date, format, timezone) || "");
} else {
// Only fallback to ISO string if no format is provided
onChange(date.toISOString());
}
}, [format, onChange]);
}, [format, timezone, onChange]);
const showRequiredState = useMemo(() => {
return required && !dateValue;