-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use isNaN check in isValidDate (#10)
Co-authored-by: Aras Abbasi <a.abbasi@cognigy.com>
- Loading branch information
Showing
2 changed files
with
3 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
export function isValidDate(date: unknown): date is Date { | ||
// An invalid date object returns NaN for getTime() and NaN is the only | ||
// object not strictly equal to itself. | ||
// eslint-disable-next-line no-self-compare | ||
return date !== null && new Date(date as string).getTime() === new Date(date as string).getTime(); | ||
// An invalid date object returns NaN for getTime() | ||
return date !== null && Number.isNaN(new Date(date as string).getTime()) === false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters