{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "date",
  "title": "Date",
  "description": "Compact date formatted in a time zone you supply. Accepts unix seconds, milliseconds, ISO strings or Date, and can underline the date to open that zone beside UTC.",
  "registryDependencies": [
    "popover",
    "hover-card"
  ],
  "files": [
    {
      "path": "components/dentil/date/date.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, useState, type ComponentProps, type ReactNode } from 'react';\n\nimport { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card';\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';\nimport { cn } from '@/lib/utils';\n\nimport { formatDateParts, formatDateTime, type DateFormatOptions, type DateInput } from './format';\n\n/** Long enough to move from the date onto the popover across the offset gap. */\nconst HOVER_CLOSE_MS = 150;\n\nexport type DateProps = {\n  date: DateInput;\n  /** IANA time zone, for example `Europe/London`. Omit it to use the runtime zone. */\n  timezone?: DateFormatOptions['timezone'];\n  /** BCP 47 language tag. Omit it to use the runtime locale. */\n  locale?: DateFormatOptions['locale'];\n  /** Include the 24-hour time. */\n  showTime?: boolean;\n  /** Include the year even when the date is in the current year. */\n  showYear?: boolean;\n  /** Underline the date and open a popover with this zone and the UTC time. */\n  showTimezone?: boolean;\n  /** Open the popover on hover, and keep it open while the pointer is over the popover. */\n  hover?: boolean;\n  /** Side of the date the popover opens on. */\n  side?: 'top' | 'right' | 'bottom' | 'left';\n  /** Alignment of the popover along that side. */\n  align?: 'start' | 'center' | 'end';\n  /** Rendered when `date` is empty or invalid. */\n  fallback?: ReactNode;\n  className?: string;\n} & Omit<ComponentProps<'time'>, 'dateTime' | 'children' | 'className'>;\n\n/**\n * Compact date such as \"Nov 7, 09:14\", formatted in `timezone`.\n * Accepts unix seconds, milliseconds, an ISO string or a `Date`.\n */\nexport function Date({\n  date,\n  timezone,\n  locale,\n  showTime = true,\n  showYear = false,\n  showTimezone = false,\n  hover = false,\n  side = 'bottom',\n  align = 'start',\n  fallback = null,\n  className,\n  ...props\n}: DateProps) {\n  const [open, setOpen] = useState(false);\n  const closeTimer = useRef<number | undefined>(undefined);\n\n  useEffect(() => () => window.clearTimeout(closeTimer.current), []);\n\n  const formatted = formatDateParts(date, { timezone, locale, showTime, showYear });\n  if (!formatted) return fallback;\n\n  if (!showTimezone) {\n    return (\n      <time\n        data-slot=\"date\"\n        dateTime={formatted.iso}\n        suppressHydrationWarning={!timezone}\n        className={cn(className)}\n        {...props}>\n        {formatted.label}\n      </time>\n    );\n  }\n\n  const instant = new globalThis.Date(formatted.iso);\n  const zone = formatted.timezone ?? Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n  function clearClose() {\n    window.clearTimeout(closeTimer.current);\n  }\n\n  function openPopover() {\n    clearClose();\n    setOpen(true);\n  }\n\n  function closePopover() {\n    clearClose();\n    closeTimer.current = window.setTimeout(() => setOpen(false), HOVER_CLOSE_MS);\n  }\n\n  function handleOpenChange(next: boolean) {\n    clearClose();\n    setOpen(next);\n  }\n\n  const triggerClassName = cn(\n    'hover:bg-muted cursor-pointer rounded-sm underline underline-offset-2 transition-colors',\n    className\n  );\n  const time = (\n    <time dateTime={formatted.iso} suppressHydrationWarning={!timezone} {...props}>\n      {formatted.label}\n    </time>\n  );\n  const details = (\n    <dl className=\"grid grid-cols-[auto_1fr] gap-x-6 gap-y-1 text-sm\">\n      <dt className=\"text-muted-foreground\">{zone}</dt>\n      <dd className=\"text-right\">{formatDateTime(instant, zone, locale)}</dd>\n      <dt className=\"text-muted-foreground\">UTC</dt>\n      <dd className=\"text-right\">{formatDateTime(instant, 'UTC', locale)}</dd>\n    </dl>\n  );\n\n  // A popover moves focus into itself on open in both Radix and Base UI, so hovering would steal focus from\n  // whatever the user is typing in. A hover card leaves focus alone.\n  if (hover) {\n    return (\n      <HoverCard open={open} onOpenChange={handleOpenChange}>\n        <HoverCardTrigger asChild>\n          <button\n            type=\"button\"\n            data-slot=\"date\"\n            className={triggerClassName}\n            onMouseEnter={openPopover}\n            onMouseLeave={closePopover}>\n            {time}\n          </button>\n        </HoverCardTrigger>\n        <HoverCardContent\n          align={align}\n          className=\"w-auto p-3\"\n          side={side}\n          sideOffset={8}\n          onMouseEnter={openPopover}\n          onMouseLeave={closePopover}>\n          {details}\n        </HoverCardContent>\n      </HoverCard>\n    );\n  }\n\n  return (\n    <Popover>\n      <PopoverTrigger asChild>\n        <button type=\"button\" data-slot=\"date\" className={triggerClassName}>\n          {time}\n        </button>\n      </PopoverTrigger>\n      <PopoverContent align={align} className=\"w-auto p-3\" side={side} sideOffset={8}>\n        {details}\n      </PopoverContent>\n    </Popover>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/dentil/date/date.tsx"
    },
    {
      "path": "components/dentil/date/format.ts",
      "content": "/** Unix timestamps in seconds are what most APIs return; anything above this is treated as milliseconds. */\nconst MAX_UNIX_SECONDS = 1e11;\n\nexport type DateInput = number | string | Date | null | undefined;\n\nexport type DateFormatOptions = {\n  /** IANA time zone, for example `Europe/London`. Omit it to use the runtime zone. */\n  timezone?: string;\n  /** BCP 47 language tag. Omit it to use the runtime locale. */\n  locale?: string;\n  /** Include the 24-hour time. Defaults to true. */\n  showTime?: boolean;\n  /** Include the year even when the date is in the current year. */\n  showYear?: boolean;\n  /** Append the short zone name, such as GMT. */\n  showTimezone?: boolean;\n};\n\nexport type FormattedDate = {\n  /** Date text, without the zone name. */\n  label: string;\n  /** Short zone name when `showTimezone` is set. */\n  zone?: string;\n  /** Zone the value was formatted in. Invalid names are replaced with `UTC`. */\n  timezone?: string;\n  iso: string;\n};\n\n/**\n * Accepts unix seconds, unix milliseconds, an ISO string or a `Date`.\n * Returns `null` when the value cannot be parsed.\n */\nexport function toDate(value: DateInput): Date | null {\n  if (value === null || value === undefined || value === '') return null;\n\n  if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : value;\n\n  if (typeof value === 'number') {\n    if (!Number.isFinite(value)) return null;\n    const date = new Date(value < MAX_UNIX_SECONDS ? value * 1000 : value);\n    return Number.isNaN(date.getTime()) ? null : date;\n  }\n\n  const date = new Date(value);\n  return Number.isNaN(date.getTime()) ? null : date;\n}\n\n/** A zone `Intl` rejects is treated as UTC, so a bad setting does not throw. */\nfunction resolvedTimezone(timezone: string | undefined) {\n  if (!timezone) return undefined;\n\n  try {\n    Intl.DateTimeFormat(undefined, { timeZone: timezone });\n    return timezone;\n  } catch {\n    return 'UTC';\n  }\n}\n\nfunction yearInZone(date: Date, timeZone: string | undefined) {\n  return new Intl.DateTimeFormat('en-US', { timeZone, year: 'numeric' }).format(date);\n}\n\n/** Compact date such as \"Nov 7, 09:14\", or \"Mar 4, 2024, 14:30\" outside the current year. */\nexport function formatDateParts(value: DateInput, options: DateFormatOptions = {}): FormattedDate | null {\n  const date = toDate(value);\n  if (!date) return null;\n\n  const timezone = resolvedTimezone(options.timezone);\n  const showTime = options.showTime ?? true;\n  const showYear = options.showYear ?? false;\n  const showTimezone = options.showTimezone ?? false;\n  const isThisYear = yearInZone(date, timezone) === yearInZone(new Date(), timezone);\n\n  const parts = new Intl.DateTimeFormat(options.locale, {\n    timeZone: timezone,\n    month: 'short',\n    day: 'numeric',\n    year: showYear || !isThisYear ? 'numeric' : undefined,\n    hour: showTime ? '2-digit' : undefined,\n    minute: showTime ? '2-digit' : undefined,\n    hourCycle: 'h23',\n    timeZoneName: showTimezone ? 'short' : undefined,\n  }).formatToParts(date);\n\n  const zone = parts.find((part) => part.type === 'timeZoneName')?.value;\n  const label = parts\n    .filter((part) => part.type !== 'timeZoneName')\n    .map((part) => part.value)\n    .join('')\n    .trim();\n\n  return { label, zone, timezone, iso: date.toISOString() };\n}\n\n/** Full clock time in a zone, such as \"07 Nov 2026, 09:14\". */\nexport function formatDateTime(date: Date, timeZone: string, locale?: string) {\n  return new Intl.DateTimeFormat(locale, {\n    timeZone,\n    day: '2-digit',\n    month: 'short',\n    year: 'numeric',\n    hour: '2-digit',\n    minute: '2-digit',\n    hourCycle: 'h23',\n  }).format(date);\n}\n\n/** The compact label. `showTimezone` appends the short zone name, such as GMT. */\nexport function formatDate(value: DateInput, options: DateFormatOptions = {}) {\n  const formatted = formatDateParts(value, options);\n  if (!formatted) return null;\n  return formatted.zone ? `${formatted.label} ${formatted.zone}` : formatted.label;\n}\n",
      "type": "registry:lib",
      "target": "components/dentil/date/format.ts"
    }
  ],
  "type": "registry:component"
}
