Skip to content

Commit

Permalink
RN-850 Date param use UTC timezone (#4437)
Browse files Browse the repository at this point in the history
  • Loading branch information
biaoli0 authored Apr 12, 2023
1 parent b7445bf commit 67d3e50
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,21 @@ const getDateValue = value => {
export const DatePicker = ({ name, value, onChange, config }) => {
const dateValue = getDateValue(value);
const defaultDateValue = getDateValue(config?.hasDefaultValue && config?.defaultValue);
// Convert date to UTC as server uses UTC timezone
const onChangeDate = localDate => {
if (!localDate) {
return;
}
const UTCDate = new Date(
Date.UTC(localDate.getFullYear(), localDate.getMonth(), localDate.getDate()),
);
onChange(UTCDate);
};

return (
<BaseDatePicker
label={name || ''}
onChange={onChange}
onChange={onChangeDate}
value={dateValue}
placeholder={defaultDateValue && format(defaultDateValue, 'dd/MM/yyyy')}
/>
Expand Down

0 comments on commit 67d3e50

Please sign in to comment.