import { memo } from "react"; export type UnitDisplay = NonNullable; export interface DurationProps { seconds: number; display: UnitDisplay; maxDigits?: number; } export default memo(Duration); type Unit = | "year" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond"; /** * Constants will be folded by the bundler * * Values taken from: * https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier * * TODO: Maybe use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat one day */ const durationFormatters = { year: 1000 * 60 * 60 * 24 * 365, month: 1000 * 60 * 60 * 24 * 30, week: 1000 * 60 * 60 * 24 * 7, day: 1000 * 60 * 60 * 24, hour: 1000 * 60 * 60, minute: 1000 * 60, second: 1000, millisecond: 1, } satisfies Record; function Duration({ seconds, display, maxDigits }: DurationProps) { //