Make datetime parsing resilient to empty strings

This commit is contained in:
Sam Becker 2024-02-29 11:57:04 -06:00
parent 73f423db68
commit 20fbcca862
2 changed files with 3 additions and 2 deletions

View File

@ -41,7 +41,8 @@
"WRHGZC", "WRHGZC",
"wxyz", "wxyz",
"zadd", "zadd",
"zrange" "zrange",
"datetime"
], ],
"files.associations": { "files.associations": {
"*.css": "tailwindcss" "*.css": "tailwindcss"

View File

@ -21,7 +21,7 @@ export const formatDateForPostgres = (date: Date) =>
const dateFromTimestamp = (timestamp?: AmbiguousTimestamp): Date => const dateFromTimestamp = (timestamp?: AmbiguousTimestamp): Date =>
typeof timestamp === 'number' typeof timestamp === 'number'
? new Date(timestamp * 1000) ? new Date(timestamp * 1000)
: typeof timestamp === 'string' : typeof timestamp === 'string' && timestamp.trim().length > 0
? /.+Z/i.test(timestamp) ? /.+Z/i.test(timestamp)
? new Date(timestamp) ? new Date(timestamp)
: new Date(`${timestamp}Z`) : new Date(`${timestamp}Z`)