{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "local-date",
  "title": "LocalDate",
  "description": "A date (and time) in the reader's own time zone and language, in a `<time>` that carries the exact instant.",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-env",
    "@ouro/lib-use-dev-messages"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/local-date/local-date-styles.ts",
      "content": "export const dateFormats: Record<DateFormat, Intl.DateTimeFormatOptions> = {\n  date: { dateStyle: \"medium\" },\n  month: { month: \"short\", year: \"numeric\" },\n  datetime: { dateStyle: \"medium\", timeStyle: \"short\" },\n  time: { timeStyle: \"short\" },\n};\n\n/** How much of the date and time {@link LocalDate} shows. */\nexport type DateFormat = \"date\" | \"month\" | \"datetime\" | \"time\";\n\n/** The instant as a Date, or null when it is not one. */\nexport function toDate(value: Date | string | number): Date | null {\n  const date = new Date(value);\n  return Number.isNaN(date.getTime()) ? null : date;\n}\n\n/**\n * A calendar date with no time of day: `\"2026-06-01\"`, or `\"2026-06\"` for a month. It names the same day everywhere.\n *\n * @claim \"A calendar date with no time\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n * @claim \"It names the same day everywhere\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n */\nconst calendarDate = /^\\d{4}-\\d{2}(-\\d{2})?$/;\n\n/**\n * Whether `value` is a calendar date with no time of day (`\"2026-06-01\"`, `\"2026-06\"`), which no time zone moves.\n *\n * @claim \"Whether `value` is a calendar date\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n */\nexport function isCalendarDate(value: Date | string | number): value is string {\n  return typeof value === \"string\" && calendarDate.test(value);\n}\n\n/** What {@link LocalDate} writes: the text, and the `<time>` element's machine-readable `dateTime`. */\nexport interface DateText {\n  text: string;\n  dateTime: string;\n}\n\n/**\n * The text for `value` in `timeZone` (the reader's when undefined), or null when it is not a\n * date. An instant moves into the time zone. A calendar date (`\"2026-06-01\"`, `\"2026-06\"`) parses\n * as UTC midnight, so it is always written in UTC and never moves: the 1st stays the 1st west\n * of UTC. `labelZone` adds the time zone's name after a time, for the server's UTC text.\n * @claim \"`) parses as UTC midnight, so it is\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::LocalDate > writes the UTC date on the server, hydrates without a mismatch, then shows the local date)\n * @claim \"`) parses as UTC midnight, so it is\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n */\nexport function dateText(value: Date | string | number, format: DateFormat, locale: Intl.LocalesArgument, timeZone: string | undefined, labelZone = false): DateText | null {\n  const date = toDate(value);\n  if (!date) return null;\n  if (isCalendarDate(value)) {\n    return { text: new Intl.DateTimeFormat(locale, { ...dateFormats[format], timeZone: \"UTC\" }).format(date), dateTime: value };\n  }\n  let text = new Intl.DateTimeFormat(locale, { ...dateFormats[format], timeZone }).format(date);\n  if (labelZone && dateFormats[format].timeStyle) {\n    const zone = new Intl.DateTimeFormat(locale, { timeZone, timeZoneName: \"short\" }).formatToParts(date).find((part) => part.type === \"timeZoneName\")!;\n    text += ` ${zone.value}`;\n  }\n  return { text, dateTime: date.toISOString() };\n}\n\n/** Nothing to subscribe to: the value only changes between the server and the browser. */\nexport const subscribeNever = (): (() => void) => () => {};\nexport const inBrowser = (): boolean => true;\nexport const onServer = (): boolean => false;\n",
      "type": "registry:ui",
      "target": "@components/ouro/local-date/local-date-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/local-date/local-date.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 { dateFormats, dateText, inBrowser, onServer, subscribeNever, toDate, type DateFormat } from \"@/registry/ouro/components/ouro/local-date/local-date-styles\";\n\nexport type { DateFormat } from \"@/registry/ouro/components/ouro/local-date/local-date-styles\";\n\n/** The props LocalDate adds to the `<time>` attributes it passes through. */\nexport interface LocalDateOwnProps {\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\"` with `format=\"month\"`) is that day for every reader and is\n   * never moved into a time zone.\n   * @claim \"A calendar date with no time\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > moves an instant into the reader's time zone)\n   * @claim \"A calendar date with no time\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n   */\n  value: Date | string | number;\n  /** `date` \"Jun 1, 2026\", `month` \"Jun 2026\", `datetime` \"Jun 1, 2026, 9:30 AM\", `time` \"9:30 AM\". @default \"date\" */\n  format?: DateFormat | (string & { 'Use \"date\", \"month\", \"datetime\" or \"time\"': never }) | undefined;\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  /** 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`: `<LocalDate value={note.createdAt} />`. */\n  date?: { 'Use value={date}': never };\n  /** Not a prop. The instant is `value`; the `<time>` gets its `dateTime` from it. */\n  dateTime?: { 'Use value={date}; dateTime is set from it': never };\n  /**\n   * Not a prop. The text is the date; there are no children.\n   *\n   * @claim \"The text is the date; there\" registry/ouro/components/ouro/local-date/local-date.test-d.ts verify:fileLine(registry/ouro/components/ouro/local-date/local-date.test-d.ts, /\\{\\svalue:\\sDate;\\schildren:\\s\"June\\s1\"\\s\\}>\\(\\)\\.not\\.toExtend<LocalDateProps>/)\n   */\n  children?: { 'LocalDate writes the date itself; pass value={date}': never };\n}\n\n/** Props for {@link LocalDate}: its own props and the `<time>` attributes it passes through. */\nexport type LocalDateProps = Omit<TimeHTMLAttributes<HTMLTimeElement>, keyof LocalDateOwnProps> & LocalDateOwnProps;\n\n/**\n * A date (and time) in the reader's own time zone and language, in a `<time>` that carries\n * the exact instant. Only the browser knows the reader's time zone and language, so the server\n * writes the instant in UTC (in en-US unless `locale` is set), hydration repeats it so the\n * markup matches, and the browser then shows the local one. A date then changes only when the instant falls near midnight, but a time\n * (`time`, `datetime`) changes for every reader outside UTC, so the server's text names the\n * zone (\"9:30 AM UTC\") until the browser takes over. A calendar date with no time (`\"2026-06-01\"`)\n * is the same day for everyone: it is written the same on the server and in the browser, and\n * the `<time>` carries that date.\n *\n * Use `RelativeTime` instead for \"3 days ago\", and `Intl.DateTimeFormat` in your own text for\n * a date inside a sentence you build.\n *\n * @group Text\n * @see https://ui.ouroboros.bot/docs/local-date\n *\n * @example\n * <LocalDate value={note.updatedAt} format=\"datetime\" />\n * @claim \"A date then changes only when\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::LocalDate > labels a time UTC on the server, and drops the label once the browser shows the local time)\n * @claim \"A date then changes only when\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > moves an instant into the reader's time zone)\n * @claim \"A date then changes only when\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::LocalDate > writes the UTC date on the server, hydrates without a mismatch, then shows the local date)\n * @claim \"A calendar date with no time\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::dateText > treats only a whole calendar date as one)\n * @claim \"A calendar date with no time\" registry/ouro/components/ouro/local-date/local-date.test.tsx verify:testExists(registry/ouro/components/ouro/local-date/local-date.test.tsx::LocalDate > writes the UTC date on the server, hydrates without a mismatch, then shows the local date)\n */\nexport function LocalDate(props: LocalDateProps): JSX.Element {\n  const {\n    value,\n    format: formatProp = \"date\",\n    locale,\n    className,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    date: dateProp,\n    dateTime,\n    children,\n    ...rest\n  } = props;\n  const format: DateFormat = Object.hasOwn(dateFormats, formatProp) ? (formatProp as DateFormat) : \"date\";\n  const date = toDate(value);\n  useAppearanceClassNameCheck(\n    \"LocalDate\",\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    \"LocalDate\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          format !== formatProp && [`format=\"${String(formatProp)}\" is not a format; use \"date\", \"month\", \"datetime\" or \"time\"`, '<LocalDate format=\"datetime\" />'],\n          date === null && [`value={${JSON.stringify(value)}} is not a date`, \"<LocalDate value={new Date()} />\"],\n          dateProp !== undefined && [\"date is not a prop\", \"<LocalDate value={date} />\"],\n          dateTime !== undefined && [\"dateTime is not a prop; it is set from value\", \"<LocalDate value={date} />\"],\n          children !== undefined && [\"LocalDate writes the date itself\", \"<LocalDate value={date} />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  const hydrated = useSyncExternalStore(subscribeNever, inBrowser, onServer);\n  // The server's language is not the reader's, so the server and hydration write en-US in UTC;\n  // the browser then switches to the reader's language and time zone. Each engine's ICU joins and\n  // spaces the same date its own way (Node \"Jun 1, 2026, 9:30 AM\", Safari \"Jun 1, 2026 at 9:30 AM\"),\n  // so hydration lets the server's text stand: the next render replaces it anyway. (It also lets a `value` that differs\n  // between the server and the browser through: the text follows the browser's, and `datetime` keeps the server's.)\n  const written = hydrated ? dateText(value, format, locale, undefined) : dateText(value, format, locale ?? \"en-US\", \"UTC\", true);\n  return (\n    <time {...rest} data-ouro=\"local-date\" dateTime={written?.dateTime} className={cn(className)} suppressHydrationWarning>\n      {written?.text}\n    </time>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/local-date/local-date.tsx"
    }
  ],
  "docs": "A date (and time) in the reader's own time zone and language, in a `<time>` that carries the exact instant. Import: import { LocalDate } from \"@/components/ouro/local-date/local-date\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports 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/local-date.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}