teqo-backup/src/utilities/formatRelativeAge.ts
2026-07-19 04:06:14 -03:00

11 lines
573 B
TypeScript

const relativeFormatter = new Intl.RelativeTimeFormat('pt-BR', { numeric: 'auto' })
export const formatRelativeAge = (timestampMs: number, nowMs: number): string => {
const diffMs = timestampMs - nowMs
const minutes = Math.round(diffMs / (60 * 1000))
if (Math.abs(minutes) < 60) return relativeFormatter.format(minutes, 'minute')
const hours = Math.round(diffMs / (60 * 60 * 1000))
if (Math.abs(hours) < 24) return relativeFormatter.format(hours, 'hour')
const days = Math.round(diffMs / (24 * 60 * 60 * 1000))
return relativeFormatter.format(days, 'day')
}