From d6c9bfca4f4f7da18f008fb1e02a1343c8aea2f6 Mon Sep 17 00:00:00 2001 From: Gabriela Seabra Date: Thu, 25 Mar 2021 15:53:36 -0300 Subject: [PATCH 1/2] [fix] edge case in datetime type knob --- addons/knobs/src/components/types/Date.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/knobs/src/components/types/Date.tsx b/addons/knobs/src/components/types/Date.tsx index b28e58b01601..87380df96fff 100644 --- a/addons/knobs/src/components/types/Date.tsx +++ b/addons/knobs/src/components/types/Date.tsx @@ -86,9 +86,7 @@ export default class DateType extends Component { const [year, month, day] = e.target.value.split('-'); const result = new Date(knob.value); if (result.getTime()) { - 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)); if (result.getTime()) { valid = true; onChange(result.getTime()); From f1df09e7f79cef3390ab9e4950935449ac80d9e7 Mon Sep 17 00:00:00 2001 From: Gabriela Seabra Date: Thu, 25 Mar 2021 22:42:40 -0300 Subject: [PATCH 2/2] [fix] edge case in datetime control --- lib/components/src/controls/Date.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/components/src/controls/Date.tsx b/lib/components/src/controls/Date.tsx index 99387d9a298a..414f57ec3622 100644 --- a/lib/components/src/controls/Date.tsx +++ b/lib/components/src/controls/Date.tsx @@ -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; }; @@ -75,9 +73,7 @@ export const DateControl: FC = ({ name, value, onChange, onFocus, onB const onDateChange = (e: ChangeEvent) => { 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);