MCPcopy Create free account
hub / github.com/AIScientists-Dev/Flowtrace / parseTimestamp

Function parseTimestamp

frontend/src/shared/lib/date-utils.ts:31–41  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

29 * Also handles Date objects and numbers (epoch ms) passed through.
30 */
31function 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")

Callers 1

formatRelativeTimeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…