This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/time/parseDateOrString.ts
kolaente 84f177c80e
Some checks failed
continuous-integration/drone/pr Build is failing
feat: reduce dependency on router and move everything to route props instead
2022-02-06 20:11:13 +01:00

13 lines
300 B
TypeScript

export function parseDateOrString(rawValue: string | undefined, fallback: any): string | Date {
if (typeof rawValue === 'undefined') {
return fallback
}
const d = new Date(rawValue)
// @ts-ignore if rawValue is an invalid date, isNan will return false.
return !isNaN(d)
? d
: rawValue
}