Skip to content

Commit

Permalink
Improve validation of Date object in getInitialDateFromUrl
Browse files Browse the repository at this point in the history
The `isDate` function only verifies if a value is a `Date` object without checking its validity. Since `new Date()` returns a `Date` object even for invalid date strings (`initialDateString`), this adjustment ensures that only valid dates pass the check.
  • Loading branch information
kasperbirch1 committed Nov 5, 2024
1 parent 53de795 commit 848af19
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/apps/opening-hours-editor/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dayjs from "dayjs";
import { isDate } from "lodash";
import { EventInput } from "@fullcalendar/core";
import { EventImpl } from "@fullcalendar/core/internal";
import {
Expand Down Expand Up @@ -185,7 +184,7 @@ export const getInitialDateFromUrl = (): Date | null => {
}

const date = new Date(initialDateString);
if (isDate(date)) {
if (!Number.isNaN(date.getTime())) {
return date;
}
// eslint-disable-next-line no-console
Expand Down

0 comments on commit 848af19

Please sign in to comment.