{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "relative-time",
  "title": "RelativeTime",
  "description": "How long ago (or how soon) something happens, in the reader's language: \"3 days ago\", \"yesterday\", \"in 5 minutes\", \"now\", kept current while it shows.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages",
    "@ouro/local-date"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/relative-time/relative-time-styles.ts",
      "content": "const units: [Intl.RelativeTimeFormatUnit, number][] = [\n  [\"year\", 365 * 24 * 3600],\n  [\"month\", 30 * 24 * 3600],\n  [\"week\", 7 * 24 * 3600],\n  [\"day\", 24 * 3600],\n  [\"hour\", 3600],\n  [\"minute\", 60],\n  [\"second\", 1],\n];\nconst DAY_SECONDS = 24 * 3600;\nconst DAY_MS = DAY_SECONDS * 1000;\n\n/**\n * \"3 days ago\", \"in 5 minutes\", \"now\": the largest whole unit to an instant, rounded.\n *\n * @claim \"the largest whole unit to an instant\" registry/ouro/components/ouro/relative-time/relative-time.test.tsx verify:fileLine(registry/ouro/components/ouro/relative-time/relative-time.test.tsx, /\\[5\\s\\*\\sMINUTE\\s\\+\\s10\\s\\*\\sSECOND,\\s\"auto\",\\s\"in\\s5\\sminutes\"\\]/)\n */\nexport function relative(date: Date, at: number, locale: Intl.LocalesArgument, numeric: \"auto\" | \"always\"): string {\n  const seconds = (date.getTime() - at) / 1000;\n  const [unit, size] = units.find(([, length]) => Math.abs(seconds) >= length) ?? [\"second\", 1];\n  const amount = unit === \"second\" && Math.abs(seconds) < 45 ? 0 : Math.round(seconds / size);\n  return new Intl.RelativeTimeFormat(locale, { numeric }).format(amount, unit);\n}\n\n/**\n * \"tomorrow\", \"in 3 days\", \"this month\": how far a calendar date (`\"2026-06-01\"`, or `\"2026-06\"`\n * for a month) is from the day it is at `at` in `timeZone` (the reader's when undefined), in\n * whole days, or whole months for a month, so it turns over at the reader's own midnight.\n */\nexport function calendarRelative(value: string, at: number, locale: Intl.LocalesArgument, numeric: \"auto\" | \"always\", timeZone?: string): string {\n  const parts = new Intl.DateTimeFormat(\"en-US\", { timeZone, year: \"numeric\", month: \"numeric\", day: \"numeric\" }).formatToParts(at);\n  const today = (type: \"year\" | \"month\" | \"day\") => Number(parts.find((part) => part.type === type)!.value);\n  const [year, month, day] = value.split(\"-\").map(Number) as [number, number, number | undefined];\n  const format = new Intl.RelativeTimeFormat(locale, { numeric });\n  if (day === undefined) {\n    const months = year * 12 + month - (today(\"year\") * 12 + today(\"month\"));\n    return Math.abs(months) >= 12 ? format.format(Math.round(months / 12), \"year\") : format.format(months, \"month\");\n  }\n  const days = (Date.UTC(year, month - 1, day) - Date.UTC(today(\"year\"), today(\"month\") - 1, today(\"day\"))) / DAY_MS;\n  const [unit, size] = units.find(([, length]) => Math.abs(days) * DAY_SECONDS >= length) ?? [\"day\", DAY_SECONDS];\n  return format.format(Math.round((days * DAY_SECONDS) / size), unit);\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/relative-time/relative-time-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/relative-time/relative-time.tsx",
      "content": "\"use client\";\n\nimport { useSyncExternalStore, type JSX, type Ref, type TimeHTMLAttributes } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { dateText, isCalendarDate, type DateFormat } from \"@/registry/ouro/components/ouro/local-date/local-date-styles\";\nimport { calendarRelative, relative } from \"@/registry/ouro/components/ouro/relative-time/relative-time-styles\";\n\n/** The props RelativeTime adds to the `<time>` attributes it passes through. */\nexport interface RelativeTimeOwnProps {\n  /**\n   * The instant: a `Date`, an ISO string or a timestamp in milliseconds. A calendar date with no\n   * time (`\"2026-06-01\"`, or `\"2026-06\"` for a month) counts whole days (or months) in the\n   * reader's own calendar and is never moved into a time zone.\n   * @claim \"A calendar date with no time\" registry/ouro/components/ouro/relative-time/relative-time.test.tsx verify:testExists(registry/ouro/components/ouro/relative-time/relative-time.test.tsx::RelativeTime > counts a calendar date in whole days of the reader's calendar, titled with that day)\n   * @claim \"A calendar date with no time\" registry/ouro/components/ouro/relative-time/relative-time.test.tsx verify:testExists(registry/ouro/components/ouro/relative-time/relative-time.test.tsx::RelativeTime > writes a calendar date as that day on the server)\n   */\n  value: Date | string | number;\n  /** The language and region to write it in. @default the reader's (en-US in the server's text, until the browser takes over) */\n  locale?: Intl.LocalesArgument | undefined;\n  /** `auto` says \"yesterday\" and \"now\"; `always` says \"1 day ago\" and \"in 0 seconds\". @default \"auto\" */\n  numeric?: \"auto\" | \"always\" | (string & { 'Use \"auto\" or \"always\"': never }) | undefined;\n  /** Layout only. Appearance classes warn in development. */\n  className?: string | undefined;\n  ref?: Ref<HTMLTimeElement> | undefined;\n\n  /** Not a prop. The instant is `value`: `<RelativeTime value={comment.createdAt} />`. */\n  date?: { 'Use value={date}': never };\n  /** Not a prop. The time updates itself; nothing to pass. */\n  now?: { 'RelativeTime keeps itself current; remove now': never };\n}\n\n/** Props for {@link RelativeTime}: its own props and the `<time>` attributes it passes through. */\nexport type RelativeTimeProps = Omit<TimeHTMLAttributes<HTMLTimeElement>, keyof RelativeTimeOwnProps> & RelativeTimeOwnProps;\n\n// One clock for every RelativeTime on the page, moved on every 30 seconds while any shows.\nlet now = 0;\nconst listeners = new Set<() => void>();\nlet interval: ReturnType<typeof setInterval> | undefined;\nfunction subscribe(listener: () => void): () => void {\n  listeners.add(listener);\n  now = Date.now();\n  interval ??= setInterval(() => {\n    now = Date.now();\n    for (const each of [...listeners]) each();\n  }, 30_000);\n  return () => {\n    listeners.delete(listener);\n    if (listeners.size > 0) return;\n    clearInterval(interval);\n    interval = undefined;\n  };\n}\nconst readNow = () => now;\nconst serverNow = () => 0;\n\n/**\n * How long ago (or how soon) something happens, in the reader's language: \"3 days ago\",\n * \"yesterday\", \"in 5 minutes\", \"now\", kept current while it shows. It is a `<time>` with the\n * exact instant, and its `title` gives the full local date and time. The server writes the UTC\n * date (in en-US unless `locale` is set) and hydration repeats it, so the markup matches; the\n * browser then shows the relative time in the reader's language.\n * A calendar date with no time (`\"2026-06-01\"`) counts whole days from the reader's own today\n * (\"tomorrow\", \"in 3 days\"), and its `title` and `<time>` carry that day, never moved into a\n * time zone.\n *\n * Use `LocalDate` instead where the date itself matters, such as a due date.\n *\n * @group Text\n * @see https://ui.ouroboros.bot/docs/relative-time\n *\n * @example\n * <RelativeTime value={comment.createdAt} />\n * @claim \"A calendar date with no time\" registry/ouro/components/ouro/relative-time/relative-time.test.tsx verify:testExists(registry/ouro/components/ouro/relative-time/relative-time.test.tsx::RelativeTime > counts a calendar date in whole days of the reader's calendar, titled with that day)\n * @claim \"A calendar date with no time\" registry/ouro/components/ouro/relative-time/relative-time.test.tsx verify:testExists(registry/ouro/components/ouro/relative-time/relative-time.test.tsx::RelativeTime > writes a calendar date as that day on the server)\n */\nexport function RelativeTime(props: RelativeTimeProps): JSX.Element {\n  const {\n    value,\n    locale,\n    numeric: numericProp = \"auto\",\n    className,\n    title,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    date: dateProp,\n    now: nowProp,\n    ...rest\n  } = props;\n  const numeric = numericProp === \"always\" ? \"always\" : \"auto\";\n  const calendar = isCalendarDate(value);\n  const shape: DateFormat = calendar && value.length === 7 ? \"month\" : \"date\";\n  // What the server writes, and hydration repeats: the date in UTC, in en-US unless the app set a\n  // language, because the server's own is not the reader's.\n  const written = dateText(value, shape, locale ?? \"en-US\", \"UTC\");\n  useAppearanceClassNameCheck(\n    \"RelativeTime\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; style the text around it instead`\n      : /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"RelativeTime\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          numeric !== numericProp && [`numeric=\"${String(numericProp)}\" is not an option; use \"auto\" or \"always\"`, '<RelativeTime numeric=\"always\" />'],\n          written === null && [`value={${JSON.stringify(value)}} is not a date`, \"<RelativeTime value={new Date()} />\"],\n          dateProp !== undefined && [\"date is not a prop\", \"<RelativeTime value={date} />\"],\n          nowProp !== undefined && [\"now is not a prop; RelativeTime keeps itself current\", \"<RelativeTime value={date} />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const at = useSyncExternalStore(subscribe, readNow, serverNow);\n  const hydrated = at !== 0;\n  let text = written?.text;\n  let full: string | undefined;\n  if (written && hydrated) {\n    text = calendar ? calendarRelative(value, at, locale, numeric) : relative(new Date(value), at, locale, numeric);\n    full = dateText(value, calendar ? shape : \"datetime\", locale, undefined)!.text;\n  }\n  // The server's UTC date is a placeholder another engine's ICU may write differently (LocalDate), so hydration lets it stand.\n  return (\n    <time {...rest} data-ouro=\"relative-time\" dateTime={written?.dateTime} title={title ?? full} className={cn(className)} suppressHydrationWarning>\n      {text}\n    </time>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/relative-time/relative-time.tsx"
    }
  ],
  "docs": "How long ago (or how soon) something happens, in the reader's language: \"3 days ago\", \"yesterday\", \"in 5 minutes\", \"now\", kept current while it shows. Import: import { RelativeTime } from \"@/components/ouro/relative-time/relative-time\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: local-date, the helpers they import in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/relative-time.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}