forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
6 additions
and
3 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
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,13 +1,16 @@ | ||
const TIME2000 = 946684800000; | ||
|
||
export function parseDate(input: unknown): Date | null { | ||
if (typeof input !== 'string') return null; | ||
const date = new Date(input); | ||
if (date.toString() === 'Invalid Date') return null; | ||
return date; | ||
} | ||
|
||
export function parseDateWithLimit(input: unknown, positiveMs: number): Date | null { | ||
export function parseDateWithLimit(input: unknown, positiveMs = 1000 * 60 * 10, minValue = TIME2000): Date | null { | ||
const date = parseDate(input); | ||
if (date == null) return null; | ||
if (date.getTime() - Date.now() > positiveMs) return null; | ||
if (minValue > date.getTime()) return null; | ||
return date; | ||
} |
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