Skip to content

Commit

Permalink
[datetime2] fix(DateInput2MigrationUtils): handle invalid dates (#6077)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya authored Apr 19, 2023
1 parent b58fca3 commit 999b254
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import { isValid } from "date-fns";

import { DateInputProps, TimePrecision } from "@blueprintjs/datetime";

import { getCurrentTimezone } from "../../common/getTimezone";
Expand Down Expand Up @@ -48,7 +50,7 @@ export function onChangeAdapter(
* @returns DateInput2 value
*/
export function valueAdapter(value: DateInputProps["value"], timePrecision?: TimePrecision): DateInput2Props["value"] {
if (value == null) {
if (value == null || !isValid(value)) {
return null;
}
return convertDateToDateString(value, timePrecision);
Expand All @@ -65,7 +67,7 @@ export function defaultValueAdapter(
defaultValue: DateInputProps["defaultValue"],
timePrecision?: TimePrecision,
): DateInput2Props["defaultValue"] {
if (defaultValue === undefined) {
if (defaultValue === undefined || !isValid(defaultValue)) {
return undefined;
}
return convertDateToDateString(defaultValue, timePrecision);
Expand Down

1 comment on commit 999b254

@adidahiya
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[datetime2] fix(DateInput2MigrationUtils): handle invalid dates (#6077)

Build artifact links for this commit: documentation | landing | table | demo

This is an automated comment from the deploy-preview CircleCI job.

Please sign in to comment.