@coriolis/coriolis
Version:
Event sourced effect management
15 lines (10 loc) • 478 B
JavaScript
import { hrToMs } from './hrToMs'
const hasPerformance = typeof performance !== 'undefined'
const hasHr = typeof process !== 'undefined' && !!process.hrtime
const dateRef =
(hasPerformance && performance.timing.navigationStart) || +new Date()
const timeDeltaRef = hasHr && process.hrtime()
export const getTimestamp =
(hasPerformance && (() => dateRef + performance.now())) ||
(hasHr && (() => dateRef + hrToMs(process.hrtime(timeDeltaRef)))) ||
(() => +new Date())