Skip to content

Commit

Permalink
[fix] edge case in datetime control
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriela Seabra committed Mar 26, 2021
1 parent d6c9bfc commit f1df09e
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/components/src/controls/Date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { ControlProps, DateValue, DateConfig } from './types';
const parseDate = (value: string) => {
const [year, month, day] = value.split('-');
const result = new Date();
result.setFullYear(parseInt(year, 10));
result.setMonth(parseInt(month, 10) - 1);
result.setDate(parseInt(day, 10));
result.setFullYear(parseInt(year, 10), parseInt(month, 10) - 1, parseInt(day, 10));
return result;
};

Expand Down Expand Up @@ -75,9 +73,7 @@ export const DateControl: FC<DateProps> = ({ name, value, onChange, onFocus, onB
const onDateChange = (e: ChangeEvent<HTMLInputElement>) => {
const parsed = parseDate(e.target.value);
const result = new Date(value);
result.setFullYear(parsed.getFullYear());
result.setMonth(parsed.getMonth());
result.setDate(parsed.getDate());
result.setFullYear(parsed.getFullYear(), parsed.getMonth(), parsed.getDate());
const time = result.getTime();
if (time) onChange(time);
setValid(!!time);
Expand Down

0 comments on commit f1df09e

Please sign in to comment.