{"version":3,"file":"relative-time.cjs","names":[],"sources":["../../src/utils/relative-time.ts"],"sourcesContent":["export type RelativeTimeLocale = \"pt-BR\" | \"en\";\n\ninterface Strings {\n    justNow: string;\n    secondsAgo: (n: number) => string;\n    minutesAgo: (n: number) => string;\n    hoursAgo: (n: number) => string;\n    daysAgo: (n: number) => string;\n    weeksAgo: (n: number) => string;\n    monthsAgo: (n: number) => string;\n    yearsAgo: (n: number) => string;\n    inSeconds: (n: number) => string;\n    inMinutes: (n: number) => string;\n    inHours: (n: number) => string;\n    inDays: (n: number) => string;\n    inWeeks: (n: number) => string;\n    inMonths: (n: number) => string;\n    inYears: (n: number) => string;\n}\n\nconst PT_BR: Strings = {\n    justNow: \"agora há pouco\",\n    secondsAgo: (n) => `${n} s atrás`,\n    minutesAgo: (n) => `${n} min atrás`,\n    hoursAgo: (n) => (n === 1 ? \"1 hora atrás\" : `${n} horas atrás`),\n    daysAgo: (n) => (n === 1 ? \"ontem\" : `${n} dias atrás`),\n    weeksAgo: (n) => (n === 1 ? \"semana passada\" : `${n} semanas atrás`),\n    monthsAgo: (n) => (n === 1 ? \"mês passado\" : `${n} meses atrás`),\n    yearsAgo: (n) => (n === 1 ? \"ano passado\" : `${n} anos atrás`),\n    inSeconds: (n) => `em ${n} s`,\n    inMinutes: (n) => `em ${n} min`,\n    inHours: (n) => `em ${n} h`,\n    inDays: (n) => `em ${n} ${n === 1 ? \"dia\" : \"dias\"}`,\n    inWeeks: (n) => `em ${n} ${n === 1 ? \"semana\" : \"semanas\"}`,\n    inMonths: (n) => `em ${n} ${n === 1 ? \"mês\" : \"meses\"}`,\n    inYears: (n) => `em ${n} ${n === 1 ? \"ano\" : \"anos\"}`,\n};\n\nconst EN: Strings = {\n    justNow: \"just now\",\n    secondsAgo: (n) => `${n}s ago`,\n    minutesAgo: (n) => `${n}m ago`,\n    hoursAgo: (n) => `${n}h ago`,\n    daysAgo: (n) => (n === 1 ? \"yesterday\" : `${n} days ago`),\n    weeksAgo: (n) => `${n}w ago`,\n    monthsAgo: (n) => `${n}mo ago`,\n    yearsAgo: (n) => `${n}y ago`,\n    inSeconds: (n) => `in ${n}s`,\n    inMinutes: (n) => `in ${n}m`,\n    inHours: (n) => `in ${n}h`,\n    inDays: (n) => `in ${n}d`,\n    inWeeks: (n) => `in ${n}w`,\n    inMonths: (n) => `in ${n}mo`,\n    inYears: (n) => `in ${n}y`,\n};\n\nconst LOCALES: Record<RelativeTimeLocale, Strings> = { \"pt-BR\": PT_BR, en: EN };\n\nconst SECOND = 1000;\nconst MINUTE = 60 * SECOND;\nconst HOUR = 60 * MINUTE;\nconst DAY = 24 * HOUR;\nconst WEEK = 7 * DAY;\nconst MONTH = 30 * DAY;\nconst YEAR = 365 * DAY;\n\n/**\n * Render a `Date` / ISO string as a relative-time string. Supports past and\n * future, PT-BR (default) and English.\n *\n * @example\n * relativeTime(new Date(Date.now() - 90_000));         // \"1 min atrás\"\n * relativeTime(\"2026-05-17T10:00:00Z\", { locale: \"en\" }); // \"5h ago\"\n */\nexport function relativeTime(\n    input: Date | string | number,\n    options: { locale?: RelativeTimeLocale; now?: Date | number } = {},\n): string {\n    const { locale = \"pt-BR\", now = Date.now() } = options;\n    const strings = LOCALES[locale];\n    const target = input instanceof Date ? input.getTime() : new Date(input).getTime();\n    const nowMs = typeof now === \"number\" ? now : now.getTime();\n    const diff = nowMs - target;\n    const past = diff >= 0;\n    const abs = Math.abs(diff);\n\n    if (abs < 30 * SECOND) return strings.justNow;\n    if (abs < MINUTE) {\n        const n = Math.round(abs / SECOND);\n        return past ? strings.secondsAgo(n) : strings.inSeconds(n);\n    }\n    if (abs < HOUR) {\n        const n = Math.round(abs / MINUTE);\n        return past ? strings.minutesAgo(n) : strings.inMinutes(n);\n    }\n    if (abs < DAY) {\n        const n = Math.round(abs / HOUR);\n        return past ? strings.hoursAgo(n) : strings.inHours(n);\n    }\n    if (abs < WEEK) {\n        const n = Math.round(abs / DAY);\n        return past ? strings.daysAgo(n) : strings.inDays(n);\n    }\n    if (abs < MONTH) {\n        const n = Math.round(abs / WEEK);\n        return past ? strings.weeksAgo(n) : strings.inWeeks(n);\n    }\n    if (abs < YEAR) {\n        const n = Math.round(abs / MONTH);\n        return past ? strings.monthsAgo(n) : strings.inMonths(n);\n    }\n    const n = Math.round(abs / YEAR);\n    return past ? strings.yearsAgo(n) : strings.inYears(n);\n}\n"],"mappings":"AAwDA,IAAM,EAA+C,CAAE,QAAS,CAnC5D,QAAS,iBACT,WAAa,GAAM,GAAG,EAAE,UACxB,WAAa,GAAM,GAAG,EAAE,YACxB,SAAW,GAAO,IAAM,EAAI,eAAiB,GAAG,EAAE,cAClD,QAAU,GAAO,IAAM,EAAI,QAAU,GAAG,EAAE,aAC1C,SAAW,GAAO,IAAM,EAAI,iBAAmB,GAAG,EAAE,gBACpD,UAAY,GAAO,IAAM,EAAI,cAAgB,GAAG,EAAE,cAClD,SAAW,GAAO,IAAM,EAAI,cAAgB,GAAG,EAAE,aACjD,UAAY,GAAM,MAAM,EAAE,IAC1B,UAAY,GAAM,MAAM,EAAE,MAC1B,QAAU,GAAM,MAAM,EAAE,IACxB,OAAS,GAAM,MAAM,EAAE,GAAG,IAAM,EAAI,MAAQ,SAC5C,QAAU,GAAM,MAAM,EAAE,GAAG,IAAM,EAAI,SAAW,YAChD,SAAW,GAAM,MAAM,EAAE,GAAG,IAAM,EAAI,MAAQ,UAC9C,QAAU,GAAM,MAAM,EAAE,GAAG,IAAM,EAAI,MAAQ,QAqBe,EAAO,GAAI,CAjBvE,QAAS,WACT,WAAa,GAAM,GAAG,EAAE,OACxB,WAAa,GAAM,GAAG,EAAE,OACxB,SAAW,GAAM,GAAG,EAAE,OACtB,QAAU,GAAO,IAAM,EAAI,YAAc,GAAG,EAAE,WAC9C,SAAW,GAAM,GAAG,EAAE,OACtB,UAAY,GAAM,GAAG,EAAE,QACvB,SAAW,GAAM,GAAG,EAAE,OACtB,UAAY,GAAM,MAAM,EAAE,GAC1B,UAAY,GAAM,MAAM,EAAE,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