-
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.
refactor: simlplify calculateProcessEvery (#6)
* refactor nextRunAt and processEvery * reduce complexity of calculateProcessEvery Co-authored-by: Aras Abbasi <a.abbasi@cognigy.com>
- Loading branch information
Showing
6 changed files
with
79 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,6 @@ | ||
export function isValidDate(date: Date): boolean { | ||
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 new Date(date).getTime() === new Date(date).getTime(); | ||
return date !== null && new Date(date as string).getTime() === new Date(date as string).getTime(); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import * as humanInterval from 'human-interval'; | ||
|
||
export function calculateProcessEvery(input: number | string = 5000): number { | ||
if (typeof input === 'number') return input; | ||
return (humanInterval(input) as number) || 5000; | ||
} |