Skip to content

Commit

Permalink
fix: use isNaN check in isValidDate (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Aras Abbasi <a.abbasi@cognigy.com>
  • Loading branch information
Uzlopak and Aras Abbasi authored Oct 25, 2020
1 parent 98d16cb commit 3bc2e30
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/utils/isValidDate.ts
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;
}
3 changes: 1 addition & 2 deletions src/utils/nextRunAt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const dateForTimezone = (timezoneDate: Date, timezone?: string): moment.Moment =

export function isValidHumanInterval(value: unknown): value is string {
const transformedValue = humanInterval(value as string);
// eslint-disable-next-line no-restricted-globals
return typeof transformedValue === 'number' && isNaN(transformedValue) === false;
return typeof transformedValue === 'number' && Number.isNaN(transformedValue) === false;
}

/**
Expand Down

0 comments on commit 3bc2e30

Please sign in to comment.