@flamingo-stack/openframe-frontend-core 0.0.642 → 0.0.643-snapshot.20260916153353

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/chat-protocol/index.cjs +6 -3
  2. package/dist/chat-protocol/index.cjs.map +1 -1
  3. package/dist/chat-protocol/index.js +6 -3
  4. package/dist/chat-protocol/index.js.map +1 -1
  5. package/dist/chat-protocol/source-metadata.d.ts +16 -1
  6. package/dist/chat-protocol/source-metadata.d.ts.map +1 -1
  7. package/dist/{chunk-YM6L3WM5.js → chunk-27RD5XTP.js} +3 -3
  8. package/dist/{chunk-POPL3W2S.js → chunk-3DGRXC74.js} +3 -3
  9. package/dist/{chunk-2Z5FPHOL.cjs → chunk-3UBT2OIX.cjs} +20 -20
  10. package/dist/{chunk-2Z5FPHOL.cjs.map → chunk-3UBT2OIX.cjs.map} +1 -1
  11. package/dist/{chunk-6GY6DFIH.js → chunk-4WVWRFGP.js} +6 -6
  12. package/dist/{chunk-OYI3K5R6.cjs → chunk-65EVGKFV.cjs} +8 -14
  13. package/dist/chunk-65EVGKFV.cjs.map +1 -0
  14. package/dist/{chunk-6NHLZORM.js → chunk-7Q5XXPCB.js} +6 -6
  15. package/dist/{chunk-2NRLRRMR.cjs → chunk-7R2DIGG4.cjs} +319 -293
  16. package/dist/chunk-7R2DIGG4.cjs.map +1 -0
  17. package/dist/{chunk-3LXJEXPH.js → chunk-B3Z3RJRW.js} +2 -2
  18. package/dist/{chunk-N5C5P2LM.cjs → chunk-B5IFXCRF.cjs} +22 -22
  19. package/dist/{chunk-N5C5P2LM.cjs.map → chunk-B5IFXCRF.cjs.map} +1 -1
  20. package/dist/{chunk-YRSRP4U3.cjs → chunk-C5Y5T6GC.cjs} +15 -15
  21. package/dist/{chunk-YRSRP4U3.cjs.map → chunk-C5Y5T6GC.cjs.map} +1 -1
  22. package/dist/{chunk-VHB3I6F3.cjs → chunk-CBXZSTAG.cjs} +419 -445
  23. package/dist/chunk-CBXZSTAG.cjs.map +1 -0
  24. package/dist/{chunk-VKPTN5MT.cjs → chunk-DCCY54LU.cjs} +6 -6
  25. package/dist/{chunk-VKPTN5MT.cjs.map → chunk-DCCY54LU.cjs.map} +1 -1
  26. package/dist/{chunk-WL3PNUNY.cjs → chunk-FAD5WURS.cjs} +81 -81
  27. package/dist/{chunk-WL3PNUNY.cjs.map → chunk-FAD5WURS.cjs.map} +1 -1
  28. package/dist/{chunk-3IPL6G7S.js → chunk-FOSIR4QF.js} +260 -234
  29. package/dist/chunk-FOSIR4QF.js.map +1 -0
  30. package/dist/{chunk-MJ424FEC.js → chunk-HOGOQA2X.js} +2 -2
  31. package/dist/{chunk-SDGMLXIP.js → chunk-HPWLIYRL.js} +12 -25
  32. package/dist/chunk-HPWLIYRL.js.map +1 -0
  33. package/dist/{chunk-3I6XHQUD.js → chunk-I57XLISO.js} +54 -80
  34. package/dist/chunk-I57XLISO.js.map +1 -0
  35. package/dist/{chunk-FRCUUK5X.cjs → chunk-IIXB5REN.cjs} +3 -3
  36. package/dist/{chunk-FRCUUK5X.cjs.map → chunk-IIXB5REN.cjs.map} +1 -1
  37. package/dist/{chunk-HW7BLVQH.js → chunk-IXD6SHQ6.js} +4 -4
  38. package/dist/{chunk-XFLJC2WR.cjs → chunk-LZYPSDFE.cjs} +59 -59
  39. package/dist/{chunk-XFLJC2WR.cjs.map → chunk-LZYPSDFE.cjs.map} +1 -1
  40. package/dist/{chunk-QY25ZP2V.cjs → chunk-MCQAOIUK.cjs} +28 -28
  41. package/dist/{chunk-QY25ZP2V.cjs.map → chunk-MCQAOIUK.cjs.map} +1 -1
  42. package/dist/{chunk-S254VEDE.js → chunk-MRIOYSXH.js} +3 -3
  43. package/dist/{chunk-OOOOC5O5.cjs → chunk-OMSUWB6A.cjs} +29 -29
  44. package/dist/{chunk-OOOOC5O5.cjs.map → chunk-OMSUWB6A.cjs.map} +1 -1
  45. package/dist/{chunk-GEIHTN6J.cjs → chunk-OVXYX47B.cjs} +10 -10
  46. package/dist/{chunk-GEIHTN6J.cjs.map → chunk-OVXYX47B.cjs.map} +1 -1
  47. package/dist/{chunk-XWGHLSAL.js → chunk-PFV4DAX5.js} +4 -4
  48. package/dist/{chunk-O4LL7RQV.cjs → chunk-RB6L5EGM.cjs} +208 -221
  49. package/dist/chunk-RB6L5EGM.cjs.map +1 -0
  50. package/dist/{chunk-M4PJVFBF.cjs → chunk-RFFF2EYD.cjs} +11 -11
  51. package/dist/{chunk-M4PJVFBF.cjs.map → chunk-RFFF2EYD.cjs.map} +1 -1
  52. package/dist/{chunk-UFBWNVZZ.js → chunk-RNMGKAS6.js} +7 -7
  53. package/dist/{chunk-SE6YRE3R.cjs → chunk-RWURXICE.cjs} +32 -32
  54. package/dist/{chunk-SE6YRE3R.cjs.map → chunk-RWURXICE.cjs.map} +1 -1
  55. package/dist/{chunk-ZAIYD3MZ.js → chunk-S2KMNFFN.js} +3 -3
  56. package/dist/{chunk-ZGPJ3NVF.js → chunk-SKABQX44.js} +3 -3
  57. package/dist/{chunk-YE3TFNW6.cjs → chunk-TGUA3C4U.cjs} +5 -5
  58. package/dist/{chunk-YE3TFNW6.cjs.map → chunk-TGUA3C4U.cjs.map} +1 -1
  59. package/dist/{chunk-ORFJVMAL.js → chunk-TTVOBWAH.js} +5 -11
  60. package/dist/chunk-TTVOBWAH.js.map +1 -0
  61. package/dist/{chunk-M7QROULE.js → chunk-UEXIMEVU.js} +5 -5
  62. package/dist/{chunk-EW3MSJOE.cjs → chunk-UKV52KAP.cjs} +33 -33
  63. package/dist/{chunk-EW3MSJOE.cjs.map → chunk-UKV52KAP.cjs.map} +1 -1
  64. package/dist/{chunk-J4RZVLLQ.js → chunk-VE52MSYC.js} +5 -5
  65. package/dist/components/case-studies/index.cjs +16 -16
  66. package/dist/components/case-studies/index.js +4 -4
  67. package/dist/components/chat/chat-sidebar.d.ts.map +1 -1
  68. package/dist/components/chat/entity-cards/blog-card.d.ts.map +1 -1
  69. package/dist/components/chat/entity-cards/dispatch.d.ts.map +1 -1
  70. package/dist/components/chat/entity-cards/program-card.d.ts.map +1 -1
  71. package/dist/components/chat/index.cjs +3 -9
  72. package/dist/components/chat/index.cjs.map +1 -1
  73. package/dist/components/chat/index.js +2 -8
  74. package/dist/components/chat/types/entities/investor-update.d.ts.map +1 -1
  75. package/dist/components/chat/types/entities/program-types.d.ts +8 -18
  76. package/dist/components/chat/types/entities/program-types.d.ts.map +1 -1
  77. package/dist/components/chat/utils/compact-card-classes.d.ts.map +1 -1
  78. package/dist/components/contact/index.cjs +5 -5
  79. package/dist/components/contact/index.js +4 -4
  80. package/dist/components/docs/index.cjs +8 -8
  81. package/dist/components/docs/index.js +7 -7
  82. package/dist/components/embeds/index.cjs +5 -5
  83. package/dist/components/embeds/index.js +4 -4
  84. package/dist/components/faq/index.cjs +5 -5
  85. package/dist/components/faq/index.js +4 -4
  86. package/dist/components/features/index.cjs +4 -4
  87. package/dist/components/features/index.js +3 -3
  88. package/dist/components/help-center-pages/index.cjs +24 -24
  89. package/dist/components/help-center-pages/index.js +15 -15
  90. package/dist/components/index.cjs +53 -59
  91. package/dist/components/index.cjs.map +1 -1
  92. package/dist/components/index.js +15 -21
  93. package/dist/components/index.js.map +1 -1
  94. package/dist/components/logs-list.d.ts.map +1 -1
  95. package/dist/components/meeting-scheduler/confirmation.d.ts.map +1 -1
  96. package/dist/components/meeting-scheduler/directory.d.ts.map +1 -1
  97. package/dist/components/meeting-scheduler/index.cjs +47 -72
  98. package/dist/components/meeting-scheduler/index.cjs.map +1 -1
  99. package/dist/components/meeting-scheduler/index.d.ts.map +1 -1
  100. package/dist/components/meeting-scheduler/index.js +16 -41
  101. package/dist/components/meeting-scheduler/index.js.map +1 -1
  102. package/dist/components/meeting-scheduler/slot-picker.d.ts.map +1 -1
  103. package/dist/components/navigation/index.cjs +7 -7
  104. package/dist/components/navigation/index.js +6 -6
  105. package/dist/components/onboarding-guides/index.cjs +7 -7
  106. package/dist/components/onboarding-guides/index.js +6 -6
  107. package/dist/components/related-content/index.cjs +3 -3
  108. package/dist/components/related-content/index.js +2 -2
  109. package/dist/components/shared/article-author-byline.d.ts.map +1 -1
  110. package/dist/components/tickets/index.cjs +8 -8
  111. package/dist/components/tickets/index.js +7 -7
  112. package/dist/components/ui/date-picker.d.ts.map +1 -1
  113. package/dist/components/ui/device-card.d.ts.map +1 -1
  114. package/dist/components/ui/drawer.d.ts +19 -5
  115. package/dist/components/ui/drawer.d.ts.map +1 -1
  116. package/dist/components/ui/index.cjs +4 -10
  117. package/dist/components/ui/index.cjs.map +1 -1
  118. package/dist/components/ui/index.js +3 -9
  119. package/dist/components/ui/table/table-timestamp-cell.d.ts.map +1 -1
  120. package/dist/index.cjs +29 -17
  121. package/dist/index.cjs.map +1 -1
  122. package/dist/index.js +35 -23
  123. package/dist/index.js.map +1 -1
  124. package/dist/utils/date-formatters.d.ts +7 -2
  125. package/dist/utils/date-formatters.d.ts.map +1 -1
  126. package/dist/utils/date-utils.d.ts +4 -1
  127. package/dist/utils/date-utils.d.ts.map +1 -1
  128. package/dist/utils/format-date.d.ts.map +1 -1
  129. package/dist/utils/format.d.ts +155 -11
  130. package/dist/utils/format.d.ts.map +1 -1
  131. package/dist/utils/index.cjs +223 -109
  132. package/dist/utils/index.cjs.map +1 -1
  133. package/dist/utils/index.d.ts +4 -1
  134. package/dist/utils/index.d.ts.map +1 -1
  135. package/dist/utils/index.js +211 -110
  136. package/dist/utils/index.js.map +1 -1
  137. package/dist/utils/program-instant.d.ts +145 -0
  138. package/dist/utils/program-instant.d.ts.map +1 -0
  139. package/dist/utils/program-meta-renderers.d.ts +3 -0
  140. package/dist/utils/program-meta-renderers.d.ts.map +1 -0
  141. package/dist/utils/url-safety.d.ts +33 -0
  142. package/dist/utils/url-safety.d.ts.map +1 -0
  143. package/package.json +1 -1
  144. package/src/chat-protocol/__tests__/source-metadata.test.ts +70 -3
  145. package/src/chat-protocol/source-metadata.ts +22 -6
  146. package/src/components/chat/chat-sidebar.tsx +4 -11
  147. package/src/components/chat/entity-cards/.program-card.md +1 -1
  148. package/src/components/chat/entity-cards/blog-card.tsx +4 -24
  149. package/src/components/chat/entity-cards/dispatch.tsx +9 -27
  150. package/src/components/chat/entity-cards/program-card.tsx +42 -81
  151. package/src/components/chat/types/entities/investor-update.ts +4 -6
  152. package/src/components/chat/types/entities/program-types.ts +8 -89
  153. package/src/components/chat/utils/.compact-card-classes.md +1 -1
  154. package/src/components/chat/utils/compact-card-classes.ts +5 -3
  155. package/src/components/logs-list.tsx +4 -13
  156. package/src/components/meeting-scheduler/confirmation.tsx +6 -10
  157. package/src/components/meeting-scheduler/directory.tsx +2 -12
  158. package/src/components/meeting-scheduler/index.tsx +3 -11
  159. package/src/components/meeting-scheduler/slot-picker.tsx +4 -7
  160. package/src/components/shared/article-author-byline.tsx +4 -13
  161. package/src/components/ui/.drawer.md +1 -0
  162. package/src/components/ui/__tests__/drawer-size.test.tsx +38 -0
  163. package/src/components/ui/date-picker.tsx +6 -13
  164. package/src/components/ui/device-card.tsx +4 -10
  165. package/src/components/ui/drawer.tsx +44 -9
  166. package/src/components/ui/table/table-timestamp-cell.tsx +8 -2
  167. package/src/utils/.format.md +5 -2
  168. package/src/utils/__tests__/date-rendering.test.ts +118 -0
  169. package/src/utils/__tests__/format-program-dates.test.ts +148 -0
  170. package/src/utils/__tests__/program-instant.test.ts +125 -0
  171. package/src/utils/__tests__/url-safety.test.ts +44 -0
  172. package/src/utils/date-formatters.ts +18 -29
  173. package/src/utils/date-utils.ts +27 -40
  174. package/src/utils/format-date.ts +14 -16
  175. package/src/utils/format.ts +367 -66
  176. package/src/utils/index.ts +24 -0
  177. package/src/utils/program-instant.ts +180 -0
  178. package/src/utils/program-meta-renderers.ts +18 -0
  179. package/src/utils/url-safety.ts +43 -0
  180. package/dist/chunk-2NRLRRMR.cjs.map +0 -1
  181. package/dist/chunk-3I6XHQUD.js.map +0 -1
  182. package/dist/chunk-3IPL6G7S.js.map +0 -1
  183. package/dist/chunk-O4LL7RQV.cjs.map +0 -1
  184. package/dist/chunk-ORFJVMAL.js.map +0 -1
  185. package/dist/chunk-OYI3K5R6.cjs.map +0 -1
  186. package/dist/chunk-SDGMLXIP.js.map +0 -1
  187. package/dist/chunk-VHB3I6F3.cjs.map +0 -1
  188. /package/dist/{chunk-YM6L3WM5.js.map → chunk-27RD5XTP.js.map} +0 -0
  189. /package/dist/{chunk-POPL3W2S.js.map → chunk-3DGRXC74.js.map} +0 -0
  190. /package/dist/{chunk-6GY6DFIH.js.map → chunk-4WVWRFGP.js.map} +0 -0
  191. /package/dist/{chunk-6NHLZORM.js.map → chunk-7Q5XXPCB.js.map} +0 -0
  192. /package/dist/{chunk-3LXJEXPH.js.map → chunk-B3Z3RJRW.js.map} +0 -0
  193. /package/dist/{chunk-MJ424FEC.js.map → chunk-HOGOQA2X.js.map} +0 -0
  194. /package/dist/{chunk-HW7BLVQH.js.map → chunk-IXD6SHQ6.js.map} +0 -0
  195. /package/dist/{chunk-S254VEDE.js.map → chunk-MRIOYSXH.js.map} +0 -0
  196. /package/dist/{chunk-XWGHLSAL.js.map → chunk-PFV4DAX5.js.map} +0 -0
  197. /package/dist/{chunk-UFBWNVZZ.js.map → chunk-RNMGKAS6.js.map} +0 -0
  198. /package/dist/{chunk-ZAIYD3MZ.js.map → chunk-S2KMNFFN.js.map} +0 -0
  199. /package/dist/{chunk-ZGPJ3NVF.js.map → chunk-SKABQX44.js.map} +0 -0
  200. /package/dist/{chunk-M7QROULE.js.map → chunk-UEXIMEVU.js.map} +0 -0
  201. /package/dist/{chunk-J4RZVLLQ.js.map → chunk-VE52MSYC.js.map} +0 -0
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type React from 'react';
4
4
  import { cn } from '../../utils/cn';
5
+ import { formatDateTimeYmd } from '../../utils/format';
5
6
  import type { OSPlatformId } from '../../utils/os-platforms';
6
7
  import { OSTypeIcon } from '../features/os-type-badge';
7
8
  import { MonitorIcon } from '../icons-v2-generated/devices/monitor-icon';
@@ -64,16 +65,9 @@ export function DeviceCard({
64
65
  const formatLastSeen = (lastSeen?: string | Date) => {
65
66
  if (!lastSeen) return null;
66
67
 
67
- const date = typeof lastSeen === 'string' ? new Date(lastSeen) : lastSeen;
68
- // UTC getters so "last seen" is identical on server (UTC) and client
69
- // (local) — otherwise React #418 hydration mismatch.
70
- const year = date.getUTCFullYear();
71
- const month = String(date.getUTCMonth() + 1).padStart(2, '0');
72
- const day = String(date.getUTCDate()).padStart(2, '0');
73
- const hours = String(date.getUTCHours()).padStart(2, '0');
74
- const minutes = String(date.getUTCMinutes()).padStart(2, '0');
75
-
76
- return `${year}/${month}/${day}, ${hours}:${minutes}`;
68
+ // UTC-pinned so the server and every client agree (React #418), through the
69
+ // one renderer rather than hand-built `getUTC*` strings.
70
+ return formatDateTimeYmd(lastSeen, null) || null;
77
71
  };
78
72
 
79
73
  return (
@@ -104,8 +104,19 @@ const drawerPanelVariants = cva(
104
104
  false: 'gap-4 rounded-md border border-ods-border p-4',
105
105
  true: '',
106
106
  },
107
+ /** Panel size along the axis the drawer slides on. `default` leaves it to
108
+ * the content (or `resizable`); `wide` is the admin detail panel, 90% of
109
+ * the viewport. Set the size here, never with a width class. */
110
+ size: {
111
+ default: '',
112
+ wide: '',
113
+ },
107
114
  },
108
115
  compoundVariants: [
116
+ { side: 'right', size: 'wide', class: 'w-[90vw]' },
117
+ { side: 'left', size: 'wide', class: 'w-[90vw]' },
118
+ { side: 'top', size: 'wide', class: 'h-[90vh]' },
119
+ { side: 'bottom', size: 'wide', class: 'h-[90vh]' },
109
120
  // flush=true → drops inner padding/gap so the consumer fully owns
110
121
  // internal layout, BUT preserves the card chrome (rounded + border)
111
122
  // on desktop so the panel still reads as an elevated card.
@@ -118,6 +129,7 @@ const drawerPanelVariants = cva(
118
129
  defaultVariants: {
119
130
  side: 'right',
120
131
  flush: false,
132
+ size: 'default',
121
133
  },
122
134
  },
123
135
  );
@@ -304,16 +316,12 @@ function DrawerResizeHandle({ side, size, minSize, maxSize, onSize, ariaLabel }:
304
316
  );
305
317
  }
306
318
 
307
- interface DrawerContentProps
319
+ interface DrawerContentBaseProps
308
320
  extends Omit<ComponentPropsWithoutRef<typeof DialogPrimitive.Content>, 'style'>, VariantProps<typeof drawerVariants> {
309
321
  /** Remove outer wrapper padding and panel rounded/border/padding so the
310
322
  * panel attaches flush to the viewport edge. Use for full-height side
311
323
  * panels (e.g. the embedded chat). */
312
324
  flush?: boolean;
313
- /** Enable the drag-to-resize handle on the inside-facing edge. Only
314
- * active for `side="left"` / `side="right"` (or `top`/`bottom`) on
315
- * non-mobile viewports. */
316
- resizable?: boolean;
317
325
  /** Minimum allowed size (px) when resizable. */
318
326
  minSize?: number;
319
327
  /** Maximum allowed size (px) when resizable. Also clamped by viewport. */
@@ -344,11 +352,34 @@ interface DrawerContentProps
344
352
  offsetHeader?: boolean;
345
353
  }
346
354
 
355
+ /**
356
+ * The panel's size has ONE owner: a `size` preset OR the drag-to-resize handle.
357
+ * A resizable panel sizes itself inline, which would silently override `wide`,
358
+ * so the two cannot be combined (a type error, not a runtime surprise).
359
+ */
360
+ type DrawerContentSizing =
361
+ | {
362
+ /** Panel size preset (`wide` = 90% of the viewport). Use it instead of a
363
+ * width/height class. */
364
+ size?: 'default' | 'wide';
365
+ resizable?: false;
366
+ }
367
+ | {
368
+ size?: 'default';
369
+ /** Enable the drag-to-resize handle on the inside-facing edge. Only
370
+ * active for `side="left"` / `side="right"` (or `top`/`bottom`) on
371
+ * non-mobile viewports. The handle owns the size, so no `size` preset. */
372
+ resizable: true;
373
+ };
374
+
375
+ type DrawerContentProps = DrawerContentBaseProps & DrawerContentSizing;
376
+
347
377
  const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, DrawerContentProps>(
348
378
  (
349
379
  {
350
380
  side = 'right',
351
381
  flush = false,
382
+ size = 'default',
352
383
  resizable = false,
353
384
  minSize = 320,
354
385
  maxSize = 1280,
@@ -383,7 +414,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
383
414
  return () => mq.removeEventListener('change', update);
384
415
  }, [mobileBreakpoint]);
385
416
 
386
- const { size, setSize } = useResizableSize({
417
+ const { size: resizedSize, setSize } = useResizableSize({
387
418
  enabled: resizable,
388
419
  isHorizontal,
389
420
  minSize,
@@ -393,7 +424,11 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
393
424
  });
394
425
 
395
426
  const applyInlineSize = resizable && !isMobile;
396
- const sizeStyle: CSSProperties = applyInlineSize ? (isHorizontal ? { width: size } : { height: size }) : {};
427
+ const sizeStyle: CSSProperties = applyInlineSize
428
+ ? isHorizontal
429
+ ? { width: resizedSize }
430
+ : { height: resizedSize }
431
+ : {};
397
432
 
398
433
  return (
399
434
  <DrawerPortal>
@@ -410,7 +445,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
410
445
  {applyInlineSize ? (
411
446
  <DrawerResizeHandle
412
447
  side={resolvedSide}
413
- size={size}
448
+ size={resizedSize}
414
449
  minSize={minSize}
415
450
  maxSize={maxSize}
416
451
  onSize={setSize}
@@ -418,7 +453,7 @@ const DrawerContent = forwardRef<ComponentRef<typeof DialogPrimitive.Content>, D
418
453
  />
419
454
  ) : null}
420
455
  <div
421
- className={cn(drawerPanelVariants({ side, flush }), className, panelClassName)}
456
+ className={cn(drawerPanelVariants({ side, flush, size }), className, panelClassName)}
422
457
  style={{ ...sizeStyle, ...panelStyle }}
423
458
  >
424
459
  {children}
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  import { cn } from '../../../utils/cn';
4
+ import { formatDateWithTimezone, VIEWER_TIMEZONE } from '../../../utils/format';
4
5
 
5
6
  /** @deprecated Use `data-table` instead. */
6
7
  export interface TableTimestampCellProps {
@@ -28,6 +29,11 @@ export interface TableTimestampCellProps {
28
29
  formatTimestamp?: boolean;
29
30
  }
30
31
 
32
+ /** The viewer's own date-time shape, in their zone and locale — the meaning of a
33
+ * dashboard table timestamp. Rendered by the one renderer, not `toLocaleString`. */
34
+ const formatLocalTimestamp = (date: Date): string =>
35
+ formatDateWithTimezone(date, VIEWER_TIMEZONE, 'localeDateTime', { viewerLocale: true });
36
+
31
37
  /**
32
38
  * Formats a timestamp for display
33
39
  * If already formatted (contains space or comma), returns as-is
@@ -35,7 +41,7 @@ export interface TableTimestampCellProps {
35
41
  */
36
42
  function formatTimestampValue(timestamp: string | Date): string {
37
43
  if (timestamp instanceof Date) {
38
- return timestamp.toLocaleString();
44
+ return formatLocalTimestamp(timestamp);
39
45
  }
40
46
 
41
47
  // If it looks like an ISO string, format it
@@ -48,7 +54,7 @@ function formatTimestampValue(timestamp: string | Date): string {
48
54
  // Try to parse and format ISO strings
49
55
  const date = new Date(timestamp);
50
56
  if (!isNaN(date.getTime())) {
51
- return date.toLocaleString();
57
+ return formatLocalTimestamp(date);
52
58
  }
53
59
  }
54
60
 
@@ -18,8 +18,11 @@ Utility functions for consistent formatting of dates, times, numbers, file sizes
18
18
  | `nameInitials` | Extracts up to two-letter initials from the first and second word; single source of truth for avatar fallbacks |
19
19
  | `formatDurationMMSS` | Formats seconds as `MM:SS` or `HH:MM:SS` for media players |
20
20
  | `formatDurationCompact` | Formats seconds as `Xh Xm` or `X min` for cards and headers |
21
- | `formatDurationFromRange` | Calculates and formats duration between two timestamps as `1h 30m` or `45m` |
22
- | `formatTimeWithTimezone` | Formats an event's wall-clock time in its own IANA timezone; falls back to UTC on invalid zone labels |
21
+ | `formatDurationFromRange` | Duration between two timestamps as `1h 30m` / `45m`. Returns `''` for a non-positive or unparseable range — a renderer shows nothing rather than `-45m` |
22
+ | `formatTimeWithTimezone` | An event's wall-clock time in its own IANA zone; falls back to UTC on an unresolvable label. Pair it with `formatDateWithTimezone` so both halves of one timestamp use one zone |
23
+ | `formatDateWithTimezone` | The calendar day in the event's own zone — the sibling of the above |
24
+ | `formatWebinarTimeMeta` | THE time+duration composition every webinar surface renders. Owns the display-override rule (a chosen date has no clock), so no call site can forget it |
25
+ | `formatProgramDate` | THE date half beside it, taking the same resolved `ProgramInstant`. Replaced a `zoned ? formatDateWithTimezone(...) : formatUtc(...)` branch written out at four call sites, whose two arms rendered different shapes |
23
26
 
24
27
  ## Usage Example
25
28
 
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { formatReleaseDate, formatDateShort, formatDateSlashUTC } from '../date-formatters';
4
+ import { formatAbsoluteDate, formatTicketFullTimestamp, formatTicketRelativeTime } from '../date-utils';
5
+ import {
6
+ VIEWER_TIMEZONE,
7
+ formatDateTimeYmd,
8
+ formatDateUTC,
9
+ formatDateWithTimezone,
10
+ formatEntryMonthUTC,
11
+ formatLegalDate,
12
+ formatTimeWithTimezone,
13
+ } from '../format';
14
+
15
+ /**
16
+ * Every date or time this package presents is rendered by
17
+ * `formatDateWithTimezone`. The named helpers are presets over it, so these
18
+ * tests pin the ONE rule — the zone is always an explicit decision — and that
19
+ * the presets still produce the shapes their callers print.
20
+ */
21
+ describe('formatDateWithTimezone — the zone is always explicit', () => {
22
+ // 01:18 UTC on the 20th is 9:18 PM on the 19th in New York.
23
+ const INSTANT = '2026-03-20T01:18:00Z';
24
+
25
+ it('an IANA zone renders in that zone', () => {
26
+ expect(formatDateWithTimezone(INSTANT, 'America/New_York')).toBe('Mar 19, 2026');
27
+ });
28
+
29
+ it('no zone pins to UTC, so the server and every client agree', () => {
30
+ expect(formatDateWithTimezone(INSTANT, null)).toBe('Mar 20, 2026');
31
+ expect(formatDateWithTimezone(INSTANT, undefined)).toBe('Mar 20, 2026');
32
+ });
33
+
34
+ it('a zone passed inside a raw field set is ignored — only the argument decides', () => {
35
+ expect(
36
+ formatDateWithTimezone(INSTANT, null, {
37
+ year: 'numeric',
38
+ month: 'short',
39
+ day: 'numeric',
40
+ timeZone: 'Asia/Tokyo',
41
+ }),
42
+ ).toBe('Mar 20, 2026');
43
+ });
44
+
45
+ it('an unresolvable zone degrades to UTC instead of throwing', () => {
46
+ expect(formatDateWithTimezone(INSTANT, 'Mars/Phobos')).toBe('Mar 20, 2026');
47
+ });
48
+
49
+ it('the viewer zone is available, and only when asked for', () => {
50
+ const viewer = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'short', day: 'numeric' }).format(
51
+ new Date(INSTANT),
52
+ );
53
+ expect(formatDateWithTimezone(INSTANT, VIEWER_TIMEZONE)).toBe(viewer);
54
+ });
55
+
56
+ it.each([null, undefined, '', 'not-a-date'])('an unusable value %j renders nothing, never "Invalid Date"', v => {
57
+ expect(formatDateWithTimezone(v, null)).toBe('');
58
+ });
59
+
60
+ it('accepts an epoch number and a Date', () => {
61
+ expect(formatDateWithTimezone(Date.parse(INSTANT), null)).toBe('Mar 20, 2026');
62
+ expect(formatDateWithTimezone(new Date(INSTANT), null)).toBe('Mar 20, 2026');
63
+ });
64
+ });
65
+
66
+ describe('presets render the shapes their callers print', () => {
67
+ const INSTANT = '2026-03-20T01:18:00Z';
68
+ it.each([
69
+ ['medium', 'Mar 20, 2026'],
70
+ ['long', 'March 20, 2026'],
71
+ ['weekday', 'Friday, March 20'],
72
+ ['numeric', '03/20/2026'],
73
+ ['monthYear', 'March 2026'],
74
+ ['monthYearShort', 'Mar 2026'],
75
+ ['numericDateTime', '03/20/2026, 1:18 AM'],
76
+ ['numericDateTime24h', '03/20/2026, 01:18'],
77
+ ] as const)('%s → %s', (style, expected) => {
78
+ expect(formatDateWithTimezone(INSTANT, null, style)).toBe(expected);
79
+ });
80
+
81
+ it('the clock is rendered by the same core, in the same zone', () => {
82
+ expect(formatTimeWithTimezone(INSTANT, 'America/New_York')).toBe('9:18 PM');
83
+ expect(formatTimeWithTimezone(INSTANT, 'America/New_York', { withZoneLabel: true })).toBe('9:18 PM EDT');
84
+ });
85
+
86
+ it('formatDateTimeYmd builds the sortable operator shape from the same formatter', () => {
87
+ expect(formatDateTimeYmd('2026-03-20T00:05:00Z', null)).toBe('2026/03/20, 00:05');
88
+ expect(formatDateTimeYmd('2026-03-20T00:05:00Z', null, { separator: ',' })).toBe('2026/03/20,00:05');
89
+ // It used to print `NaN/NaN/NaN, NaN:NaN`.
90
+ expect(formatDateTimeYmd('junk', null)).toBe('');
91
+ });
92
+ });
93
+
94
+ describe('named helpers are presets over the core', () => {
95
+ it('formatLegalDate states the calendar day, on any machine', () => {
96
+ // It rendered with NO zone, so this read 02/28/2026 west of UTC.
97
+ expect(formatLegalDate('2026-03-01')).toBe('03/01/2026');
98
+ // ...and it threw on an unparseable value; it now renders nothing.
99
+ expect(formatLegalDate('nope')).toBe('');
100
+ });
101
+
102
+ it('calendar-date presets render the day as written', () => {
103
+ expect(formatReleaseDate('2025-11-11')).toBe('November 11, 2025');
104
+ expect(formatDateShort('2025-11-11T23:30:00Z')).toBe('Nov 11, 2025');
105
+ expect(formatDateSlashUTC('2025-11-11')).toBe('11/11/2025');
106
+ // Unparseable input is returned as given, not reassembled into garbage.
107
+ expect(formatReleaseDate('not-a-date')).toBe('not-a-date');
108
+ expect(formatDateSlashUTC('not-a-date')).toBe('not-a-date');
109
+ });
110
+
111
+ it('the remaining helpers keep their shapes', () => {
112
+ expect(formatDateUTC('2026-03-01')).toBe('Mar 1, 2026');
113
+ expect(formatEntryMonthUTC('2026-03-01', 'long')).toBe('March 2026');
114
+ expect(formatTicketFullTimestamp('2026-03-20T13:05:00Z')).toBe('03/20/2026, 1:05 PM');
115
+ expect(formatTicketRelativeTime('2020-01-02T00:00:00Z')).toBe('01/02/2020');
116
+ expect(formatAbsoluteDate('2026-03-20T01:18:00Z', { timeZone: 'America/New_York' })).toBe('Mar 19, 2026');
117
+ });
118
+ });
@@ -0,0 +1,148 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ formatDateWithTimezone,
5
+ formatDurationFromRange,
6
+ formatTimeWithTimezone,
7
+ formatWebinarTimeMeta,
8
+ } from '../format';
9
+ import { programDateInstant } from '../program-instant';
10
+
11
+ /**
12
+ * These three formatters render the date, time and duration of ONE event, side
13
+ * by side on the program card. They had no coverage at all, which is how a
14
+ * missing sign guard shipped: a live webinar row whose `end_at` preceded its
15
+ * `start_at` printed "-45m" on the card.
16
+ */
17
+ describe('formatDurationFromRange', () => {
18
+ it('formats a positive range', () => {
19
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:45:00Z')).toBe('45m');
20
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T01:30:00Z')).toBe('1h 30m');
21
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T02:00:00Z')).toBe('2h');
22
+ });
23
+
24
+ it('renders NOTHING when the event ends before it starts', () => {
25
+ // The live row that produced the bug report: e6cff6f8, end_at 45 minutes
26
+ // before start_at. It used to render "-45m" — and note that a -90 minute
27
+ // range never reached the `>= 60` branch, so it printed "-90m" rather than
28
+ // "-1h 30m": the output was not merely wrong, it was inconsistently wrong.
29
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-19T23:15:25Z')).toBe('');
30
+ expect(formatDurationFromRange('2026-03-20T02:00:00Z', '2026-03-20T00:30:00Z')).toBe('');
31
+ });
32
+
33
+ it('renders nothing for a zero-length or unparseable range', () => {
34
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', '2026-03-20T00:00:00Z')).toBe('');
35
+ // Used to print the literal string "NaNm".
36
+ expect(formatDurationFromRange('not-a-date', '2026-03-20T00:00:00Z')).toBe('');
37
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', 'not-a-date')).toBe('');
38
+ });
39
+
40
+ it('renders nothing when an endpoint is missing', () => {
41
+ expect(formatDurationFromRange(null, '2026-03-20T00:00:00Z')).toBe('');
42
+ expect(formatDurationFromRange('2026-03-20T00:00:00Z', undefined)).toBe('');
43
+ });
44
+ });
45
+
46
+ describe('formatDateWithTimezone / formatTimeWithTimezone agree on the zone', () => {
47
+ // The reported defect: the card printed the date in UTC and the time beside
48
+ // it in the event's own zone, so this instant read "Mar 20, 2026 · 9:18 PM"
49
+ // — 9:18 PM on the 20th is not when it happens, 9:18 PM on the 19th is.
50
+ const instant = '2026-03-20T01:18:00Z';
51
+ const zone = 'America/New_York';
52
+
53
+ it('puts the date on the event-local day, not the UTC day', () => {
54
+ expect(formatDateWithTimezone(instant, zone)).toBe('Mar 19, 2026');
55
+ expect(formatTimeWithTimezone(instant, zone)).toBe('9:18 PM');
56
+ });
57
+
58
+ it('renders the weekday style in the same zone', () => {
59
+ // Note the copy shift: the default density used to build this from the
60
+ // date-fns pattern 'EEEE d MMMM' ("Thursday 19 March"). Intl's en-US order
61
+ // is "Thursday, March 19". Preserving the old wording would mean composing
62
+ // the string from Intl parts by hand — re-introducing exactly the bespoke
63
+ // date arithmetic this change exists to remove — so the locale-correct
64
+ // form wins, consistent with every other formatter in this file.
65
+ expect(formatDateWithTimezone(instant, zone, 'weekday')).toBe('Thursday, March 19');
66
+ });
67
+
68
+ it('falls back to UTC on both halves when no zone is given', () => {
69
+ expect(formatDateWithTimezone(instant, null)).toBe('Mar 20, 2026');
70
+ expect(formatTimeWithTimezone(instant, null)).toBe('1:18 AM');
71
+ });
72
+
73
+ it('handles a legacy fixed-offset label consistently across both halves', () => {
74
+ // "EST" does NOT throw — Node resolves it as a legacy fixed UTC-5 alias, so
75
+ // it lands on the 19th at 8:18 PM (no DST, unlike America/New_York's EDT).
76
+ // What matters is that the date and the time agree about the zone.
77
+ expect(formatDateWithTimezone(instant, 'EST')).toBe('Mar 19, 2026');
78
+ expect(formatTimeWithTimezone(instant, 'EST')).toBe('8:18 PM');
79
+ });
80
+
81
+ it('degrades BOTH halves to UTC on a genuinely invalid zone', () => {
82
+ // A label Intl cannot resolve DOES throw a RangeError. Both formatters must
83
+ // catch it the same way, or the pair disagrees about which zone it used.
84
+ expect(formatDateWithTimezone(instant, 'Not/AZone')).toBe('Mar 20, 2026');
85
+ expect(formatTimeWithTimezone(instant, 'Not/AZone')).toBe('1:18 AM');
86
+ });
87
+
88
+ it('appends the zone label only when asked', () => {
89
+ expect(formatTimeWithTimezone(instant, zone, { withZoneLabel: true })).toBe('9:18 PM EDT');
90
+ });
91
+
92
+ it('renders nothing for a missing or unparseable date', () => {
93
+ expect(formatDateWithTimezone(null, zone)).toBe('');
94
+ expect(formatDateWithTimezone('not-a-date', zone)).toBe('');
95
+ expect(formatTimeWithTimezone('not-a-date', zone)).toBe('');
96
+ });
97
+ });
98
+
99
+ /**
100
+ * The webinar time+duration composition. These exact three lines existed in
101
+ * three surfaces and drifted twice — once so the page read the raw `start_at`
102
+ * while the card read the resolved instant, once so the zone label differed.
103
+ * The rule now lives here, so it is tested here.
104
+ */
105
+ describe('formatWebinarTimeMeta', () => {
106
+ const RANGE = { startAt: '2026-03-20T01:18:00Z', endAt: '2026-03-20T02:18:00Z' };
107
+ // Built through the resolver, never hand-assembled: the helper takes the
108
+ // RESOLVED value precisely so a caller cannot invent a combination the
109
+ // resolver would never produce (which is how four call sites disagreed).
110
+ const zonedRow = { date: RANGE.startAt, start_at: RANGE.startAt, timezone: 'America/New_York' };
111
+
112
+ it('renders the time from the resolved instant and the duration from the range', () => {
113
+ expect(formatWebinarTimeMeta(programDateInstant(zonedRow), RANGE)).toBe('9:18 PM · 1h');
114
+ });
115
+
116
+ it('labels the zone when asked', () => {
117
+ expect(formatWebinarTimeMeta(programDateInstant(zonedRow), { ...RANGE, withZoneLabel: true })).toBe(
118
+ '9:18 PM EDT · 1h',
119
+ );
120
+ });
121
+
122
+ it('leaves no dangling separator when either side is missing', () => {
123
+ const at = programDateInstant(zonedRow);
124
+ expect(formatWebinarTimeMeta(at, { ...RANGE, endAt: null })).toBe('9:18 PM');
125
+ // An inverted range yields no duration — and must not leave a trailing " · ".
126
+ expect(formatWebinarTimeMeta(at, { ...RANGE, endAt: '2026-03-20T00:00:00Z' })).toBe('9:18 PM');
127
+ // An unrenderable time must not leave a LEADING " · " either.
128
+ expect(
129
+ formatWebinarTimeMeta(programDateInstant({ ...zonedRow, date: 'not-a-date', start_at: 'not-a-date' }), RANGE),
130
+ ).toBe('1h');
131
+ });
132
+
133
+ it('a zoneless row still renders a deterministic UTC clock, not nothing', () => {
134
+ // `instant` is null without a zone (the React #418 pin), so the helper must
135
+ // fall through to the canonical value rather than dropping the time.
136
+ const at = programDateInstant({ date: RANGE.startAt, start_at: RANGE.startAt });
137
+ expect(at.instant).toBeNull();
138
+ expect(formatWebinarTimeMeta(at, RANGE)).toBe('1:18 AM · 1h');
139
+ });
140
+
141
+ it('the two compact surfaces that mirror each other label the zone alike', () => {
142
+ // They took `withZoneLabel` from different expressions, so a zoneless
143
+ // webinar read "1:18 AM UTC" on the public card and "1:18 AM" on the chat
144
+ // card — for one row, on two cards built to look the same.
145
+ const at = programDateInstant({ date: RANGE.startAt, start_at: RANGE.startAt });
146
+ expect(formatWebinarTimeMeta(at, { ...RANGE, withZoneLabel: true })).toBe('1:18 AM UTC · 1h');
147
+ });
148
+ });
@@ -0,0 +1,125 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import {
4
+ formatDateWithTimezone,
5
+ formatDurationCompact,
6
+ formatProgramDate,
7
+ formatProgramTimeRange,
8
+ formatTimeWithTimezone,
9
+ formatWebinarTimeMeta,
10
+ } from '../format';
11
+ import { programDateInstant, programMetaLine } from '../program-instant';
12
+
13
+ /**
14
+ * The rule every program surface renders by. It lived as prose in two
15
+ * components that "mirrored" each other, and they drifted: the public card was
16
+ * fixed while the chat card kept rendering the date in the VIEWER's zone beside
17
+ * a time in the EVENT's zone. One owner, pinned here.
18
+ */
19
+ describe('programDateInstant', () => {
20
+ const zoned = {
21
+ date: '2026-03-20T01:18:00.000Z',
22
+ start_at: '2026-03-20T01:18:00.000Z',
23
+ timezone: 'America/New_York',
24
+ };
25
+
26
+ it('renders date and time from ONE instant in ONE zone', () => {
27
+ const r = programDateInstant(zoned);
28
+ expect(r.instant).toBe('2026-03-20T01:18:00.000Z');
29
+ expect(r.timezone).toBe('America/New_York');
30
+ // 01:18Z is 9:18 PM on the 19th in New York — both halves must say the 19th.
31
+ expect(formatDateWithTimezone(r.instant, r.timezone)).toBe('Mar 19, 2026');
32
+ expect(formatTimeWithTimezone(r.instant, r.timezone)).toBe('9:18 PM');
33
+ });
34
+
35
+ it('prefers item.date, the host-resolved instant', () => {
36
+ const r = programDateInstant({ ...zoned, date: '2026-02-09T15:00:00.000Z' });
37
+ expect(r.instant).toBe('2026-02-09T15:00:00.000Z');
38
+ });
39
+
40
+ it('falls back to start_at when the item carries no resolved date', () => {
41
+ expect(programDateInstant({ start_at: '2026-03-20T01:18:00.000Z', timezone: 'America/New_York' }).instant).toBe(
42
+ '2026-03-20T01:18:00.000Z',
43
+ );
44
+ });
45
+
46
+ it('keeps the UTC pin when the row declares no zone (React #418)', () => {
47
+ // Returning an instant here would let a caller render viewer-local, which
48
+ // differs between server and client.
49
+ expect(programDateInstant({ date: '2026-03-20T01:18:00.000Z' }).instant).toBeNull();
50
+ });
51
+
52
+ it('renders the same shape whether or not the row declares a zone', () => {
53
+ // The UTC fallback used to be a separate date-fns branch at each call site,
54
+ // and it emitted a DIFFERENT SHAPE ("Thursday 19 March" vs "Thursday,
55
+ // March 19"), so whether a row happened to carry a zone decided how its
56
+ // headline read.
57
+ const withZone = formatProgramDate(programDateInstant(zoned), 'weekday');
58
+ const withoutZone = formatProgramDate(programDateInstant({ date: '2026-03-19T12:00:00.000Z' }), 'weekday');
59
+ expect(withZone).toBe('Thursday, March 19');
60
+ expect(withoutZone).toBe('Thursday, March 19');
61
+ });
62
+ });
63
+
64
+ /**
65
+ * The compact meta line. The public card and the chat card built this
66
+ * separately, under a comment saying the second "mirrors" the first — and it
67
+ * drifted twice, each time only on the copy nobody was looking at.
68
+ */
69
+ describe('programMetaLine', () => {
70
+ const FMT = {
71
+ date: (at: ReturnType<typeof programDateInstant>) => formatProgramDate(at, 'medium'),
72
+ duration: formatDurationCompact,
73
+ webinarMeta: (at: ReturnType<typeof programDateInstant>, o: { startAt: string | null; endAt: string | null }) =>
74
+ formatWebinarTimeMeta(at, { ...o, withZoneLabel: true }),
75
+ };
76
+
77
+ it('a webinar: day, clock and duration, all from one instant', () => {
78
+ const { line } = programMetaLine(
79
+ {
80
+ date: '2026-03-20T01:18:00.000Z',
81
+ start_at: '2026-03-20T01:18:00.000Z',
82
+ end_at: '2026-03-20T02:03:00.000Z',
83
+ timezone: 'America/New_York',
84
+ },
85
+ 'webinar',
86
+ FMT,
87
+ );
88
+ expect(line).toBe('Mar 19, 2026 · 9:18 PM EDT · 45m');
89
+ });
90
+
91
+ it('a scheduled podcast does not present its stored duration as elapsed time', () => {
92
+ const row = { date: '2026-03-20T01:18:00.000Z', duration_seconds: 1800 };
93
+ expect(programMetaLine(row, 'podcast', FMT).typeMeta).not.toBeNull();
94
+ expect(programMetaLine({ ...row, status: 'scheduled' }, 'podcast', FMT).typeMeta).toBeNull();
95
+ });
96
+
97
+ it('an event falls back to nothing rather than a blank separator', () => {
98
+ const { line } = programMetaLine({ date: '2026-03-20T01:18:00.000Z', location_name: ' ' }, 'event', FMT);
99
+ // No zone on this row, so the day is UTC-pinned (the React #418 rule) —
100
+ // and a whitespace-only location contributes nothing at all.
101
+ expect(line).toBe('Mar 20, 2026');
102
+ });
103
+ });
104
+
105
+ describe('formatProgramTimeRange', () => {
106
+ it('an end with no usable start says nothing, rather than showing a FINISH as a start', () => {
107
+ const at = programDateInstant({ timezone: 'America/New_York' });
108
+ expect(formatProgramTimeRange(at, { endAt: '2026-03-20T17:00:00Z' })).toBe('');
109
+ });
110
+
111
+ it('refuses an inverted range, keeping the start that is still true', () => {
112
+ // The sibling duration formatter already refuses this — a card once shipped
113
+ // "-45m" — and rendering "11:00 PM - 9:00 PM" is the same impossible value
114
+ // one field over. Luma has no ingest guard against it.
115
+ const at = programDateInstant({ date: '2026-03-20T03:00:00Z', timezone: 'America/New_York' });
116
+ expect(formatProgramTimeRange(at, { endAt: '2026-03-20T01:00:00Z', withZoneLabel: true })).toBe('11:00 PM EDT');
117
+ });
118
+
119
+ it('labels only the last clock of a range', () => {
120
+ const at = programDateInstant({ date: '2026-03-20T13:00:00Z', timezone: 'America/New_York' });
121
+ expect(formatProgramTimeRange(at, { endAt: '2026-03-20T17:00:00Z', withZoneLabel: true })).toBe(
122
+ '9:00 AM - 1:00 PM EDT',
123
+ );
124
+ });
125
+ });
@@ -0,0 +1,44 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { safeHref } from '../../components/chat/utils/compact-card-classes';
4
+ import { UNSAFE_URL_CHARS, isSameOriginPath } from '../url-safety';
5
+
6
+ /**
7
+ * The shared URL-safety predicate, tested once for BOTH callers — the wire
8
+ * decoder (`linkUrl`) and the render-time guard (`safeHref`). They used to hold
9
+ * their own copies, kept in sync by a comment, and the copies already disagreed
10
+ * on the backslash case: a single-slash path that the URL parser resolves to a
11
+ * third-party origin passed every "starts with exactly one slash" check and
12
+ * reached an anchor tag.
13
+ */
14
+ describe('isSameOriginPath', () => {
15
+ const escapes = ['/\\evil.test/x', '/\\\\evil.test/x', '//evil.test/x', '/\\/evil.test/x', 'https://evil.test/x'];
16
+
17
+ it.each(escapes)('rejects %s — it does not stay on this origin', href => {
18
+ expect(isSameOriginPath(href)).toBe(false);
19
+ });
20
+
21
+ it.each(['/ok/x', '/a/b?q=1#frag', '/%2Fnot-an-authority', '/'])('accepts %s', href => {
22
+ expect(isSameOriginPath(href)).toBe(true);
23
+ });
24
+ });
25
+
26
+ describe('safeHref uses the same rule', () => {
27
+ it('rejects the backslash escape the decoder rejects', () => {
28
+ expect(safeHref('/\\evil.test/x')).toBeNull();
29
+ expect(safeHref('//evil.test/x')).toBeNull();
30
+ });
31
+
32
+ it('still accepts what it is supposed to', () => {
33
+ expect(safeHref('/onboarding-guides/x')).toBe('/onboarding-guides/x');
34
+ expect(safeHref('#section')).toBe('#section');
35
+ expect(safeHref('https://x.test/a')).toBe('https://x.test/a');
36
+ expect(safeHref('mailto:a@b.test')).toBe('mailto:a@b.test');
37
+ });
38
+
39
+ it('rejects control and zero-width characters', () => {
40
+ expect(UNSAFE_URL_CHARS.test('/a' + String.fromCharCode(0) + 'b')).toBe(true);
41
+ expect(safeHref('/a' + String.fromCharCode(0x200b) + 'b')).toBeNull();
42
+ expect(UNSAFE_URL_CHARS.test('/ordinary/path')).toBe(false);
43
+ });
44
+ });