Skip to content

Commit

Permalink
[datetime] fix(DateRange): values are possibly null, not undefined
Browse files Browse the repository at this point in the history
fixes #3970
  • Loading branch information
adidahiya committed Feb 26, 2020
1 parent fddba2c commit d75b155
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/datetime/src/common/dateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Months } from "./months";

export type DateRange = [Date | undefined, Date | undefined];
export type DateRange = [Date | null, Date | null];

export function isDateValid(date: Date | false | null): date is Date {
return date instanceof Date && !isNaN(date.valueOf());
Expand Down
5 changes: 3 additions & 2 deletions packages/datetime/src/dateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ export class DateRangePicker extends AbstractPureComponent2<IDateRangePickerProp
}

private handleTimeChange = (newTime: Date, dateIndex: number) => {
Utils.safeInvoke(this.props.timePickerProps.onChange, newTime);
this.props.timePickerProps?.onChange?.(newTime);

const { value, time } = this.state;
const newValue = DateUtils.getDateTime(
value[dateIndex] != null ? DateUtils.clone(value[dateIndex]) : new Date(),
Expand All @@ -357,7 +358,7 @@ export class DateRangePicker extends AbstractPureComponent2<IDateRangePickerProp
newDateRange[dateIndex] = newValue;
const newTimeRange: DateRange = [time[0], time[1]];
newTimeRange[dateIndex] = newTime;
Utils.safeInvoke(this.props.onChange, newDateRange);
this.props.onChange?.(newDateRange);
this.setState({ value: newDateRange, time: newTimeRange });
};

Expand Down

0 comments on commit d75b155

Please sign in to comment.