(date?: Prisma.JsonValue)
| 67 | * @returns The date as a timestamp number. |
| 68 | */ |
| 69 | export const normalizeDate = (date?: Prisma.JsonValue): number => { |
| 70 | if (typeof date === 'number') { |
| 71 | return date; |
| 72 | } else if ( |
| 73 | date && |
| 74 | typeof date === 'object' && |
| 75 | '$date' in date && |
| 76 | typeof date.$date === 'string' |
| 77 | ) { |
| 78 | return new Date(date.$date).getTime(); |
| 79 | } else if (typeof date === 'string') { |
| 80 | const parsed = Number(date); |
| 81 | if (!isNaN(parsed)) { |
| 82 | // Number() handles invalid strings e.g. '2023-10-01T00:00:00Z' |
| 83 | // parseInt() handles floats |
| 84 | return parseInt(String(parsed)); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | throw Error('Unexpected date value: ' + JSON.stringify(date)); |
| 89 | }; |
| 90 | |
| 91 | /** |
| 92 | * Normalizes a challenge type value to a number. |
no outgoing calls
no test coverage detected