Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datetime] fix(DateRange): values are possibly null, not undefined #3983

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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