* Parse timestamp, treating as UTC if no timezone specified. * This handles the case where PostgreSQL returns timestamps without explicit timezone. * Also handles Date objects and numbers (epoch ms) passed through.
(timestamp: string | Date | number | null | undefined)
| 29 | * Also handles Date objects and numbers (epoch ms) passed through. |
| 30 | */ |
| 31 | function parseTimestamp(timestamp: string | Date | number | null | undefined): Date { |
| 32 | if (timestamp == null) return new Date(NaN) |
| 33 | if (timestamp instanceof Date) return timestamp |
| 34 | if (typeof timestamp === 'number') return new Date(timestamp) |
| 35 | if (typeof timestamp !== 'string') return new Date(NaN) |
| 36 | if (!timestamp) return new Date(NaN) |
| 37 | if (!timestamp.endsWith('Z') && !timestamp.match(/[+-]\d{2}:?\d{2}$/)) { |
| 38 | return new Date(timestamp + 'Z') |
| 39 | } |
| 40 | return new Date(timestamp) |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Format timestamp as relative time (e.g., "2 hours ago", "5 minutes ago") |
no outgoing calls
no test coverage detected
searching dependent graphs…