{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "send-time-check",
  "title": "Send Time Check",
  "description": "Send-time check that shows the recipient's local time on a strip of their day, flags night, after-hours, weekend (including Friday–Saturday weekends) and holidays you pass, and offers a one-tap schedule for the start of their next working day.",
  "dependencies": [
    "lucide-react",
    "@date-fns/tz",
    "date-fns",
    "motion"
  ],
  "files": [
    {
      "path": "registry/default/send-time-check/send-time-check.tsx",
      "content": "\"use client\"\r\n\r\n// Bollard UI — send-time-check · MIT licence · https://bollard-ui.vercel.app/components/send-time-check\r\n\r\nimport * as React from \"react\"\r\nimport { TZDate, tzOffset } from \"@date-fns/tz\"\r\nimport { addDays, format, startOfDay } from \"date-fns\"\r\nimport { CalendarClock, Clock, Moon } from \"lucide-react\"\r\nimport { motion, useReducedMotion } from \"motion/react\"\r\n\r\nimport { cn } from \"@/lib/utils\"\r\n\r\n/** Weekends that aren't Saturday–Sunday, by IANA zone (0 = Sunday). Everything else defaults to [6, 0]. */\r\nconst WEEKENDS: Record<string, number[]> = {\r\n  ...Object.fromEntries(\r\n    [\"Asia/Riyadh\", \"Asia/Kuwait\", \"Asia/Qatar\", \"Asia/Bahrain\", \"Asia/Muscat\", \"Asia/Baghdad\", \"Asia/Amman\", \"Asia/Aden\",\r\n      \"Asia/Jerusalem\", \"Asia/Tel_Aviv\", \"Africa/Cairo\", \"Africa/Algiers\", \"Africa/Khartoum\", \"Asia/Dhaka\"].map((z) => [z, [5, 6]]),\r\n  ),\r\n  \"Asia/Tehran\": [5], \"Africa/Djibouti\": [5], \"Africa/Mogadishu\": [5], \"Asia/Kathmandu\": [6], \"Asia/Brunei\": [5, 0],\r\n}\r\n\r\n/** The usual weekend days for a zone: Friday–Saturday in Riyadh, Saturday in Kathmandu, else Saturday–Sunday. */\r\nexport const weekendFor = (timeZone: string) => WEEKENDS[timeZone] ?? [6, 0]\r\n\r\n/** Wall-clock date, weekday and time an instant shows in `timeZone` (tz database via @date-fns/tz). */\r\nexport function wallClock(ts: number, timeZone: string) {\r\n  const d = new TZDate(ts, timeZone)\r\n  return { date: format(d, \"yyyy-MM-dd\"), weekday: d.getDay(), hour: d.getHours(), minute: d.getMinutes() }\r\n}\r\n\r\n/** The instant a wall time in `timeZone` happens. An hour a DST change skips moves forward to the first real time. */\r\nexport function zonedTime(date: string, hour: number, timeZone: string) {\r\n  const [y, m, d] = date.split(\"-\").map(Number)\r\n  return new TZDate(y, m - 1, d, hour, 0, timeZone).getTime()\r\n}\r\n\r\nexport interface Holiday {\r\n  /** The recipient's local date, YYYY-MM-DD. */\r\n  date: string\r\n  /** Name to show, e.g. \"Diwali\". */\r\n  name: string\r\n}\r\n\r\nexport interface SendTimeOptions {\r\n  /** Working hours in the recipient's zone, [start, end) in 24h hours. */\r\n  workHours?: [number, number]\r\n  /** Hours counted as night, [from, until), e.g. [22, 7]. */\r\n  nightHours?: [number, number]\r\n  weekend?: number[]\r\n  holidays?: Holiday[]\r\n}\r\n\r\n/** Why `now` is a bad moment for the recipient, and the next start of their working day. */\r\nexport function checkSendTime(now: number, timeZone: string, { workHours = [9, 18], nightHours = [22, 7], weekend, holidays = [] }: SendTimeOptions = {}) {\r\n  const off = weekend ?? weekendFor(timeZone)\r\n  const free = (date: string, weekday: number) => off.includes(weekday) || holidays.some((h) => h.date === date)\r\n  const w = wallClock(now, timeZone)\r\n  const hours = w.hour + w.minute / 60\r\n  const holiday = holidays.find((h) => h.date === w.date)\r\n  const reason = holiday ? \"holiday\" : off.includes(w.weekday) ? \"weekend\" : hours >= nightHours[0] || hours < nightHours[1] ? \"night\" : hours < workHours[0] || hours >= workHours[1] ? \"after-hours\" : null\r\n  if (!reason) return { reason, local: w, holiday, next: null }\r\n  // Today's start if it's still ahead and a working day, otherwise the next working day's start.\r\n  let day = startOfDay(new TZDate(now, timeZone))\r\n  for (let i = 0; i < 21; i++) {\r\n    if (!free(format(day, \"yyyy-MM-dd\"), day.getDay()) && (i > 0 || hours < workHours[0])) break\r\n    day = addDays(day, 1)\r\n  }\r\n  return { reason, local: w, holiday, next: zonedTime(format(day, \"yyyy-MM-dd\"), workHours[0], timeZone) }\r\n}\r\n\r\nconst clock = (h: number, m: number) => `${h % 12 || 12}:${String(m).padStart(2, \"0\")} ${h < 12 ? \"AM\" : \"PM\"}`\r\nconst dayName = (ts: number, timeZone: string, weekday: \"short\" | \"long\") => new Intl.DateTimeFormat(\"en-GB\", { weekday, timeZone }).format(ts)\r\nconst fill = (template: string, values: Record<string, string>) => template.replace(/\\{(\\w+)\\}/g, (m, k: string) => values[k] ?? m)\r\n\r\nexport interface SendTimeCheckProps extends SendTimeOptions, Omit<React.ComponentProps<\"div\">, \"children\"> {\r\n  /** Recipient's name, e.g. \"Priya\". */\r\n  recipient: string\r\n  /** Recipient's IANA zone, e.g. \"Europe/London\". */\r\n  timeZone: string\r\n  /** Where they are. Defaults to the zone's city. */\r\n  place?: string\r\n  /** Fixed \"now\" for previews and tests. Defaults to a live clock. */\r\n  now?: Date | number\r\n  /** Your zone, used to show the suggestion in your time too. Defaults to the browser's. */\r\n  senderTimeZone?: string\r\n  /** Called with the suggested instant when the user picks \"Schedule for …\". */\r\n  onSchedule?: (at: Date) => void\r\n  /** The Send / Schedule buttons this check sits next to. */\r\n  children?: React.ReactNode\r\n  /** Templates: `{name}`, `{place}`, `{time}`, `{day}` and `{holiday}` are filled in. */\r\n  okText?: string\r\n  /** Shown when it's night where the recipient is. */\r\n  nightText?: string\r\n  /** Shown outside their working hours. */\r\n  afterHoursText?: string\r\n  /** Shown on their weekend. */\r\n  weekendText?: string\r\n  /** Shown on a holiday you passed. */\r\n  holidayText?: string\r\n  /** Template for the fix button: `{when}`. */\r\n  scheduleLabel?: string\r\n  /** Template for your-time hint: `{time}`. */\r\n  yourTimeText?: string\r\n  /** Show the recipient's day as a 24-hour strip with their working hours and where the message would land. */\r\n  showDay?: boolean\r\n}\r\n\r\n/**\r\n * Stops a 2 AM ping. Next to a Send button it shows the recipient's local time and warns when\r\n * it's night, their weekend (Friday–Saturday in Riyadh, not just Sat–Sun) or a holiday you pass in,\r\n * with a one-tap \"Schedule for\" the start of their next working day, also shown in your time.\r\n * A strip of their day shows night and working hours with a dot for \"now\"; hovering or focusing\r\n * the fix glides the dot to the slot it picks, so the reason and the fix read at a glance.\r\n * Zone maths runs on the tz database through @date-fns/tz.\r\n */\r\nexport function SendTimeCheck({\r\n  recipient,\r\n  timeZone,\r\n  place = timeZone.split(\"/\").pop()?.replace(/_/g, \" \"),\r\n  now: fixedNow,\r\n  senderTimeZone,\r\n  onSchedule,\r\n  workHours,\r\n  nightHours,\r\n  weekend,\r\n  holidays,\r\n  okText = \"It's {time} for {name} in {place}.\",\r\n  nightText = \"It's {time} for {name} in {place}.\",\r\n  afterHoursText = \"It's {time} for {name} in {place}, after their working hours.\",\r\n  weekendText = \"It's {day} {time} for {name} in {place}, their weekend.\",\r\n  holidayText = \"It's {holiday} for {name} in {place}.\",\r\n  scheduleLabel = \"Schedule for {when}\",\r\n  yourTimeText = \"{time} your time\",\r\n  showDay = true,\r\n  className,\r\n  children,\r\n  ...props\r\n}: SendTimeCheckProps) {\r\n  const [liveNow, setLiveNow] = React.useState<number>()\r\n  const [ownZone, setOwnZone] = React.useState(senderTimeZone)\r\n  const [previewing, setPreviewing] = React.useState(false)\r\n  const reduceMotion = useReducedMotion()\r\n\r\n  React.useEffect(() => {\r\n    setOwnZone(senderTimeZone ?? Intl.DateTimeFormat().resolvedOptions().timeZone)\r\n    if (fixedNow !== undefined) return\r\n    setLiveNow(Date.now())\r\n    const id = setInterval(() => setLiveNow(Date.now()), 30_000)\r\n    return () => clearInterval(id)\r\n  }, [fixedNow, senderTimeZone])\r\n\r\n  const fixed = fixedNow !== undefined ? new Date(fixedNow).getTime() : undefined\r\n  const now = fixed !== undefined && Number.isFinite(fixed) ? fixed : liveNow\r\n  // An unknown zone (typo, retired name) shows nothing rather than a wrong time.\r\n  const knownZone = Number.isFinite(tzOffset(timeZone, new Date(0)))\r\n  const check = now === undefined || !knownZone ? null : checkSendTime(now, timeZone, { workHours, nightHours, weekend, holidays })\r\n  const values = check && now !== undefined\r\n    ? { name: recipient, place: place ?? timeZone, time: clock(check.local.hour, check.local.minute), day: dayName(now, timeZone, \"long\"), holiday: check.holiday?.name ?? \"\" }\r\n    : null\r\n  const text = !check || !values ? \"\" : fill(\r\n    { holiday: holidayText, weekend: weekendText, night: nightText, \"after-hours\": afterHoursText }[check.reason ?? \"\"] ?? okText,\r\n    values,\r\n  )\r\n  const next = check?.next ?? null\r\n  const nextLocal = next === null ? null : wallClock(next, timeZone)\r\n  const sameDay = nextLocal && check && nextLocal.date === check.local.date\r\n  const when = next === null || !nextLocal ? \"\" : `${sameDay ? \"\" : `${dayName(next, timeZone, \"short\")} `}${clock(nextLocal.hour, nextLocal.minute)}`\r\n  const mine = next !== null && ownZone && ownZone !== timeZone ? wallClock(next, ownZone) : null\r\n  const Icon = check?.reason === \"night\" ? Moon : check?.reason ? CalendarClock : Clock\r\n  React.useEffect(() => setPreviewing(false), [timeZone, now])\r\n\r\n  // The recipient's day as a strip: night shaded, working hours marked, and a dot for \"now\" that\r\n  // glides to the suggested slot while the Schedule button is hovered or focused.\r\n  const [workStart, workEnd] = workHours ?? [9, 18]\r\n  const [nightFrom, nightUntil] = nightHours ?? [22, 7]\r\n  const pct = (h: number) => `${(Math.min(24, Math.max(0, h)) / 24) * 100}%`\r\n  const nowHour = check ? check.local.hour + check.local.minute / 60 : 0\r\n  const atSlot = previewing && next !== null && nextLocal\r\n  const dot = atSlot ? nextLocal.hour + nextLocal.minute / 60 : nowHour\r\n  const workday = check?.reason !== \"weekend\" && check?.reason !== \"holiday\"\r\n  const day = showDay && check && (\r\n    <div aria-hidden className=\"relative mt-1 mb-4 h-4 select-none\">\r\n      <div className=\"absolute inset-x-0 top-1.5 h-1.5 overflow-hidden rounded-full bg-muted\">\r\n        <span className=\"absolute inset-y-0 left-0 bg-indigo-500/30 dark:bg-indigo-400/30\" style={{ width: pct(nightUntil) }} />\r\n        <span className=\"absolute inset-y-0 right-0 bg-indigo-500/30 dark:bg-indigo-400/30\" style={{ left: pct(nightFrom) }} />\r\n        {(workday || atSlot) && (\r\n          <span className=\"absolute inset-y-0 bg-emerald-500/50 dark:bg-emerald-400/45\" style={{ left: pct(workStart), width: `${((workEnd - workStart) / 24) * 100}%` }} />\r\n        )}\r\n      </div>\r\n      <motion.span\r\n        className={cn(\r\n          \"absolute top-0 size-4 -translate-x-1/2 rounded-full border-2 border-background shadow-sm\",\r\n          atSlot ? \"bg-emerald-600 dark:bg-emerald-400\" : check.reason ? \"bg-amber-500\" : \"bg-foreground\",\r\n        )}\r\n        initial={false}\r\n        animate={{ left: pct(dot), scale: atSlot && !reduceMotion ? [1, 1.25, 1] : 1 }}\r\n        transition={reduceMotion ? { duration: 0 } : { left: { type: \"spring\", stiffness: 260, damping: 26 }, scale: { duration: 0.35 } }}\r\n      />\r\n      <motion.span\r\n        className={cn(\"absolute top-5 -translate-x-1/2 text-[10px] whitespace-nowrap tabular-nums\", atSlot ? \"font-medium text-emerald-700 dark:text-emerald-400\" : \"text-muted-foreground\")}\r\n        initial={false}\r\n        animate={{ left: `clamp(1.5rem, ${pct(dot)}, calc(100% - 1.5rem))` }}\r\n        transition={reduceMotion ? { duration: 0 } : { type: \"spring\", stiffness: 260, damping: 26 }}\r\n      >\r\n        {atSlot ? when : values?.time}\r\n      </motion.span>\r\n    </div>\r\n  )\r\n\r\n  return (\r\n    <div data-slot=\"send-time-check\" data-state={check?.reason ?? \"ok\"} className={cn(\"grid gap-1.5\", className)} {...props}>\r\n      {children && <div className=\"flex flex-wrap items-center gap-2\">{children}</div>}\r\n      <div aria-live=\"polite\" className=\"min-h-6 text-xs\">\r\n        {values && (\r\n          <p className={cn(\"flex gap-1.5\", check?.reason ? \"text-amber-700 dark:text-amber-400\" : \"text-muted-foreground\")}>\r\n            <span className=\"flex h-6 shrink-0 items-center\">\r\n              <Icon aria-hidden className=\"size-3.5\" />\r\n            </span>\r\n            <span className=\"flex min-w-0 flex-wrap items-center gap-x-2\">\r\n              <span className=\"py-1 tabular-nums\">{text}</span>\r\n              {next !== null && (\r\n                <span className=\"flex flex-wrap items-center gap-x-2\">\r\n                  <button\r\n                    type=\"button\"\r\n                    onClick={() => onSchedule?.(new Date(next))}\r\n                    onPointerEnter={() => setPreviewing(true)}\r\n                    onPointerLeave={(event) => event.currentTarget !== document.activeElement && setPreviewing(false)}\r\n                    onFocus={() => setPreviewing(true)}\r\n                    onBlur={() => setPreviewing(false)}\r\n                    className=\"inline-flex h-6 items-center gap-1 rounded-md border border-amber-500/40 px-2 font-medium text-amber-900 transition-colors hover:bg-amber-500/10 dark:text-amber-200 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50\"\r\n                  >\r\n                    {fill(scheduleLabel, { when })}\r\n                  </button>\r\n                  {mine && (\r\n                    <span className=\"text-muted-foreground tabular-nums\">\r\n                      {fill(yourTimeText, {\r\n                        time: `${mine.date !== nextLocal?.date ? `${dayName(next, ownZone!, \"short\")} ` : \"\"}${clock(mine.hour, mine.minute)}`,\r\n                      })}\r\n                    </span>\r\n                  )}\r\n                </span>\r\n              )}\r\n            </span>\r\n          </p>\r\n        )}\r\n      </div>\r\n      {day}\r\n    </div>\r\n  )\r\n}\r\n",
      "type": "registry:ui",
      "target": "@ui/send-time-check.tsx"
    }
  ],
  "meta": {
    "stops": "Message landed at 2 AM their time",
    "mistakes": [
      "messaged client at night",
      "sent on their weekend",
      "recipient time zone",
      "schedule send",
      "holiday message"
    ],
    "aliases": [
      "schedule send",
      "time zone",
      "local time",
      "working hours",
      "slack",
      "email",
      "weekend",
      "send later"
    ],
    "flows": [
      "messaging",
      "scheduling"
    ],
    "fields": [
      "datetime"
    ],
    "summary": "Shows the recipient's local time next to Send and offers to schedule for their next working morning when it's night, weekend or a holiday there.",
    "catches": [
      "Night hours in the recipient's zone (default 22:00–07:00)",
      "Outside working hours (default 9–18)",
      "Their weekend, by zone (Friday–Saturday in Riyadh, Saturday in Kathmandu, otherwise Saturday–Sunday)",
      "Holidays you supply",
      "Next working-day start, DST-safe, as a one-tap schedule"
    ],
    "limits": [
      "Weekend table is built in and coarse (by IANA zone, not by person or employer)",
      "Holidays are not built in; pass them",
      "Needs the recipient's real time zone; guessing it from a country can be wrong"
    ],
    "a11y": [
      "Status message in a polite live region; the day strip is aria-hidden",
      "Marker glide respects reduced motion (useReducedMotion)",
      "Schedule is a labelled button; icons are aria-hidden"
    ],
    "rules": {
      "verified": null,
      "note": "Weekend-by-zone table (Fri–Sat in much of the Gulf, Sat-only in Nepal, Fri–Sun in Brunei) not re-verified against official sources this round. Check local rules before relying on it."
    },
    "usage": "import { SendTimeCheck } from \"@/components/ui/send-time-check\"",
    "runtimeDependencies": [
      "lucide-react",
      "@date-fns/tz",
      "date-fns",
      "motion"
    ],
    "zeroRuntimeDependencies": false
  },
  "docs": "https://bollard-ui.vercel.app/components/send-time-check",
  "categories": [
    "Sharing, sending and paying"
  ],
  "type": "registry:ui"
}
