@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,8 @@
2
2
  * Utility functions for formatting data
3
3
  */
4
4
 
5
+ import type { ProgramInstant } from './program-instant';
6
+
5
7
  /**
6
8
  * Format a date to a human-readable string
7
9
  * @param date - The date to format (Date object or ISO string)
@@ -24,10 +26,9 @@ export function formatDate(
24
26
  return 'Invalid Date';
25
27
  }
26
28
 
27
- // Pin to UTC by default so SSR (Vercel = UTC) and the client agree (React
28
- // #418 hydration mismatch). A caller can still override by passing its own
29
- // `timeZone` in `options`.
30
- return dateObj.toLocaleDateString('en-US', { timeZone: 'UTC', ...options });
29
+ // UTC by default (see `formatDateWithTimezone`); a caller may still name a
30
+ // zone via `options.timeZone`, which is passed as THE zone, not a field.
31
+ return formatDateWithTimezone(dateObj, options.timeZone ?? null, options);
31
32
  }
32
33
 
33
34
  /**
@@ -265,54 +266,293 @@ export function formatDurationCompact(seconds: number | null | undefined): strin
265
266
  }
266
267
 
267
268
  /**
268
- * Format a webinar/event start time as the wall-clock in its OWN timezone.
269
+ * THE date/time renderer. Every date or time this package presents goes through
270
+ * `formatDateWithTimezone` (or its clock sibling `formatTimeWithTimezone`) — the
271
+ * named helpers below are presets over it, not separate implementations.
272
+ *
273
+ * Why one: each helper used to decide the zone for itself — `timeZone: 'UTC'`
274
+ * here, none at all there (so the MACHINE's zone), hand-built `MM/DD/YYYY` from
275
+ * `getUTC*` getters, month names looked up in an array — and the answers
276
+ * disagreed. A date rendered without an explicit zone is a different day on the
277
+ * server (Vercel = UTC) than in a browser west of it, which is both a wrong day
278
+ * and a React #418 hydration mismatch. The zone is therefore a REQUIRED decision
279
+ * at every call, made in exactly one of three ways:
269
280
  *
270
- * `date` is an instant (UTC timestamp / ISO string). `timezone` is the event's
271
- * IANA zone (e.g. `'America/New_York'`). Rendering in that explicit zone makes
272
- * the server (Vercel = UTC) and the visitor's browser emit the SAME text —
273
- * fixing the React #418 hydration mismatch — AND shows the true event time
274
- * (4:00 PM EDT, not the 8:00 PM UTC a plain UTC pin would show, nor the
275
- * viewer-local time the old unpinned call produced). Falls back to UTC when no
276
- * zone is given, and tolerates a non-IANA label (legacy data) without throwing.
277
- * The zone LABEL is rendered separately by callers, so it is never appended here.
281
+ * - an IANA zone (`'America/New_York'`): a record that HAS a zone renders in it
282
+ * — an event's wall clock is the event's, whoever is looking;
283
+ * - `null` / `undefined`: pinned to UTC — content dates (published, released,
284
+ * periods) that must read the same on the server and every client;
285
+ * - `VIEWER_TIMEZONE`: the runtime's own zone — ONLY for client-rendered UI whose
286
+ * whole meaning is "your local time" (a date picker, a booking slot in the
287
+ * visitor's zone, a "last active" stamp in an app shell).
278
288
  *
279
- * Returns: "4:00 PM"
289
+ * An unresolvable zone (legacy data) degrades to UTC rather than throwing, so a
290
+ * bad row cannot take down the surface rendering it.
280
291
  */
281
- export function formatTimeWithTimezone(date: Date | string | null | undefined, timezone?: string | null): string {
282
- if (!date) return '';
283
-
284
- const dateObj = typeof date === 'string' ? new Date(date) : date;
285
- const opts: Intl.DateTimeFormatOptions = {
292
+ export const VIEWER_TIMEZONE = 'viewer';
293
+
294
+ type DateInput = Date | string | number | null | undefined;
295
+
296
+ /** The shapes this package renders, by name. A raw `Intl` field set is also
297
+ * accepted for a one-off shape; the ZONE is never taken from it — it is the
298
+ * explicit `timezone` argument, so no caller can smuggle a default back in. */
299
+ export type ZonedDateStyle =
300
+ | 'medium'
301
+ | 'weekday'
302
+ | 'long'
303
+ | 'numeric'
304
+ | 'monthYear'
305
+ | 'monthYearShort'
306
+ | 'numericDateTime'
307
+ | 'mediumDateTime'
308
+ | 'weekdayDateTimeZoned'
309
+ | 'shortWeekdayDateTime'
310
+ | 'numericDateTime24h'
311
+ | 'localeDateTime';
312
+
313
+ const ZONED_DATE_STYLES: Record<ZonedDateStyle, Intl.DateTimeFormatOptions> = {
314
+ /** Mar 19, 2026 */
315
+ medium: { year: 'numeric', month: 'short', day: 'numeric' },
316
+ /** Thursday, March 19 */
317
+ weekday: { weekday: 'long', day: 'numeric', month: 'long' },
318
+ /** March 19, 2026 */
319
+ long: { year: 'numeric', month: 'long', day: 'numeric' },
320
+ /** 03/19/2026 */
321
+ numeric: { year: 'numeric', month: '2-digit', day: '2-digit' },
322
+ /** March 2026 */
323
+ monthYear: { year: 'numeric', month: 'long' },
324
+ /** Mar 2026 */
325
+ monthYearShort: { year: 'numeric', month: 'short' },
326
+ /** 03/19/2026, 9:18 PM */
327
+ numericDateTime: {
328
+ year: 'numeric',
329
+ month: '2-digit',
330
+ day: '2-digit',
286
331
  hour: 'numeric',
287
332
  minute: '2-digit',
288
333
  hour12: true,
289
- timeZone: timezone || 'UTC',
290
- };
334
+ },
335
+ /** Mar 19, 2026, 9:18 PM */
336
+ mediumDateTime: { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' },
337
+ /** Thursday, March 19 at 9:18 PM EDT */
338
+ weekdayDateTimeZoned: {
339
+ weekday: 'long',
340
+ month: 'long',
341
+ day: 'numeric',
342
+ hour: 'numeric',
343
+ minute: '2-digit',
344
+ timeZoneName: 'short',
345
+ },
346
+ /** Thu, Mar 19, 9:18 PM */
347
+ shortWeekdayDateTime: { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' },
348
+ /** 03/19/2026, 21:18 */
349
+ numericDateTime24h: {
350
+ year: 'numeric',
351
+ month: '2-digit',
352
+ day: '2-digit',
353
+ hour: '2-digit',
354
+ minute: '2-digit',
355
+ hour12: false,
356
+ },
357
+ /** 3/19/2026, 9:18:00 PM — the runtime's own default date-time shape */
358
+ localeDateTime: {
359
+ year: 'numeric',
360
+ month: 'numeric',
361
+ day: 'numeric',
362
+ hour: 'numeric',
363
+ minute: '2-digit',
364
+ second: '2-digit',
365
+ },
366
+ };
367
+
368
+ /** Constructing an `Intl.DateTimeFormat` is expensive and these are called per
369
+ * row; one instance per (locale, zone, fields) is enough. */
370
+ const FORMATTERS = new Map<string, Intl.DateTimeFormat>();
371
+
372
+ function zonedFormatter(locale: string | undefined, fields: Intl.DateTimeFormatOptions, timeZone: string | undefined) {
373
+ const key = JSON.stringify([locale ?? null, timeZone ?? null, fields]);
374
+ let fmt = FORMATTERS.get(key);
375
+ if (!fmt) {
376
+ fmt = new Intl.DateTimeFormat(locale, { ...fields, timeZone });
377
+ FORMATTERS.set(key, fmt);
378
+ }
379
+ return fmt;
380
+ }
381
+
382
+ /**
383
+ * THE zone rule, applied once: an IANA zone renders in that zone, `null` pins to
384
+ * UTC, `VIEWER_TIMEZONE` uses the runtime's zone — and an UNRESOLVABLE zone
385
+ * degrades to UTC instead of throwing, so a bad row cannot take down the
386
+ * surface rendering it. (A bare "EST" does not degrade: it resolves as a fixed
387
+ * UTC-5 alias, a different wall clock from America/New_York under DST — a data
388
+ * problem this cannot see.)
389
+ */
390
+ function formatterFor(
391
+ timezone: string | null | undefined,
392
+ fields: Intl.DateTimeFormatOptions,
393
+ locale: string | undefined,
394
+ ): Intl.DateTimeFormat {
395
+ const zone = timezone === VIEWER_TIMEZONE ? undefined : timezone || 'UTC';
291
396
  try {
292
- return dateObj.toLocaleTimeString('en-US', opts);
397
+ return zonedFormatter(locale, fields, zone);
293
398
  } catch {
294
- // Non-IANA `timezone` (e.g. a bare "EST" label) makes Intl throw a
295
- // RangeError. Fall back to a UTC-pinned render so we stay deterministic
296
- // (still no #418) instead of crashing.
297
- return dateObj.toLocaleTimeString('en-US', { ...opts, timeZone: 'UTC' });
399
+ return zonedFormatter(locale, fields, 'UTC');
298
400
  }
299
401
  }
300
402
 
403
+ function toValidDate(date: DateInput): Date | null {
404
+ if (date === null || date === undefined || date === '') return null;
405
+ const d = date instanceof Date ? date : new Date(date);
406
+ return Number.isNaN(d.getTime()) ? null : d;
407
+ }
408
+
409
+ /**
410
+ * Render a date (and, for a date-time style, its time) in an explicit zone.
411
+ * Returns `''` for a missing or unparseable value.
412
+ *
413
+ * `options.viewerLocale` renders in the runtime's own LOCALE instead of the
414
+ * fixed `en-US` — for client-only UI that should read the way its user writes
415
+ * dates. The locale is never implied, for the same hydration reason as the zone.
416
+ */
417
+ export function formatDateWithTimezone(
418
+ date: DateInput,
419
+ timezone?: string | null,
420
+ style: ZonedDateStyle | Intl.DateTimeFormatOptions = 'medium',
421
+ options?: { viewerLocale?: boolean },
422
+ ): string {
423
+ const dateObj = toValidDate(date);
424
+ if (!dateObj) return '';
425
+ const { timeZone: _ignored, ...fields } = typeof style === 'string' ? ZONED_DATE_STYLES[style] : style;
426
+ return formatterFor(timezone, fields, options?.viewerLocale ? undefined : 'en-US').format(dateObj);
427
+ }
428
+
429
+ /**
430
+ * `2026/03/19, 21:18` — a sortable, locale-independent date-time for dense
431
+ * operator UI (log lines, device "last seen").
432
+ *
433
+ * No locale renders this shape, so it is assembled from `formatToParts` of the
434
+ * SAME formatter every other date uses: the zone decision cannot drift from the
435
+ * rest of the package. It replaces two copies that built the string by hand from
436
+ * `getUTC*` getters and printed `NaN/NaN/NaN` for an unparseable value.
437
+ */
438
+ export function formatDateTimeYmd(date: DateInput, timezone?: string | null, options?: { separator?: string }): string {
439
+ const dateObj = toValidDate(date);
440
+ if (!dateObj) return '';
441
+ const parts = formatterFor(
442
+ timezone,
443
+ { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' },
444
+ 'en-US',
445
+ ).formatToParts(dateObj);
446
+ const part = (type: Intl.DateTimeFormatPartTypes) => parts.find(p => p.type === type)?.value ?? '';
447
+ return `${part('year')}/${part('month')}/${part('day')}${options?.separator ?? ', '}${part('hour')}:${part('minute')}`;
448
+ }
449
+
450
+ /**
451
+ * A wall-clock time in an explicit zone — the clock sibling of
452
+ * `formatDateWithTimezone`, rendered by it, so the pair cannot disagree about
453
+ * which zone a date and the time beside it are stated in.
454
+ *
455
+ * `withZoneLabel` appends the short zone name ("4:00 PM EDT") for plain joined
456
+ * strings where there is no room for a separately styled label.
457
+ *
458
+ * Returns: "4:00 PM", or "4:00 PM EDT" with `withZoneLabel`.
459
+ */
460
+ export function formatTimeWithTimezone(
461
+ date: DateInput,
462
+ timezone?: string | null,
463
+ options?: { withZoneLabel?: boolean; viewerLocale?: boolean },
464
+ ): string {
465
+ return formatDateWithTimezone(
466
+ date,
467
+ timezone,
468
+ {
469
+ hour: 'numeric',
470
+ minute: '2-digit',
471
+ // A viewer-locale clock uses the locale's own 12/24h convention.
472
+ ...(options?.viewerLocale ? {} : { hour12: true }),
473
+ ...(options?.withZoneLabel ? { timeZoneName: 'short' as const } : {}),
474
+ },
475
+ { viewerLocale: options?.viewerLocale },
476
+ );
477
+ }
478
+
479
+ /**
480
+ * THE program date — the date half of what `formatWebinarTimeMeta` renders as
481
+ * the time half, taking the same already-resolved `ProgramInstant` so the two
482
+ * cannot name different moments.
483
+ *
484
+ * Every program surface used to write this branch itself:
485
+ * `zoned.instant ? formatDateWithTimezone(...) :
486
+ * formatUtc(new Date(item.date), 'EEEE d MMMM')` — four copies, and they did
487
+ * not agree. Three stated the condition off the resolved instant and the
488
+ * fourth off a local timezone variable; worse, the two branches rendered
489
+ * DIFFERENT SHAPES, so whether a row happened to declare a zone decided
490
+ * whether its headline read "Thursday, March 19" or "Thursday 19 March".
491
+ *
492
+ * There is no UTC branch here because there never needed to be one:
493
+ * `formatDateWithTimezone` already pins to UTC when handed no zone, which is
494
+ * the same React #418 fix the hand-rolled `formatUtc` twins existed for — they
495
+ * were a date-fns re-implementation of a fallback that was already inside the
496
+ * function they sat next to.
497
+ */
498
+ export function formatProgramDate(at: ProgramInstant, style: ZonedDateStyle = 'medium'): string {
499
+ // `timezone` is already null for a day-valued row, so this one call covers
500
+ // the zoned render, the no-zone render and the override render alike.
501
+ return formatDateWithTimezone(at.instant ?? at.utcDate, at.timezone, style);
502
+ }
503
+
504
+ /**
505
+ * Do these two endpoints describe a forward-running interval?
506
+ *
507
+ * THE ordering rule for every renderer in this file. A range that runs
508
+ * backwards is not a short range, it is a false one: a card shipped "-45m"
509
+ * from a row whose `end_at` preceded its `start_at`, and the clock renderer
510
+ * printed "11:00 PM - 9:00 PM" from the same shape. Both refuse it here.
511
+ *
512
+ * The host app enforces the same rule at INGEST (it drops such an `end_at`
513
+ * rather than storing it) and states the comparison itself, because the module
514
+ * that owns it there is a dependency-free leaf its mapper tests rely on. Two
515
+ * statements of one comparison, across a package boundary, knowingly — if this
516
+ * one changes, that one has to.
517
+ */
518
+ export function isOrderedRange(from: Date | string | null | undefined, to: Date | string | null | undefined): boolean {
519
+ if (!from || !to) return false;
520
+ const a = (typeof from === 'string' ? new Date(from) : from).getTime();
521
+ const b = (typeof to === 'string' ? new Date(to) : to).getTime();
522
+ return Number.isFinite(a) && Number.isFinite(b) && b > a;
523
+ }
524
+
301
525
  /**
302
526
  * Calculate and format duration between two timestamps
303
527
  * Used for webinar durations
304
528
  * Returns: "1h 30m" or "45m"
529
+ *
530
+ * Returns `''` — the same "nothing to show" this function already returns for a
531
+ * missing endpoint — when the range is not a positive, real duration. An event
532
+ * whose `end_at` precedes its `start_at` is corrupt data, and the unguarded
533
+ * subtraction printed it literally: a live webinar row rendered "-45m" on the
534
+ * card. An unparseable timestamp printed "NaNm" the same way. A renderer shows
535
+ * nothing rather than an impossible value; the write path is what must reject
536
+ * the row. (Note the negative case never even reached the `>= 60` branch, so
537
+ * -90 minutes rendered as "-90m" rather than "-1h 30m" — the output was not
538
+ * just wrong, it was inconsistently wrong.)
305
539
  */
306
540
  export function formatDurationFromRange(
307
541
  startAt: string | Date | null | undefined,
308
542
  endAt: string | Date | null | undefined,
309
543
  ): string {
310
- if (!startAt || !endAt) return '';
311
-
312
- const start = typeof startAt === 'string' ? new Date(startAt) : startAt;
313
- const end = typeof endAt === 'string' ? new Date(endAt) : endAt;
314
- const durationMs = end.getTime() - start.getTime();
315
- const minutes = Math.round(durationMs / 60000);
544
+ // ONE statement of "is this a forward-running interval", shared with
545
+ // `formatProgramTimeRange`. This function's guard and that one's were written
546
+ // separately — the second one's comment even named this as its sibling — and
547
+ // an ordering rule stated twice is a rule that can disagree with itself about
548
+ // the same row.
549
+ if (!isOrderedRange(startAt, endAt)) return '';
550
+
551
+ // Non-null past the guard above, which rejects null/unparseable endpoints.
552
+ const start = typeof startAt === 'string' ? new Date(startAt) : (startAt as Date);
553
+ const end = typeof endAt === 'string' ? new Date(endAt) : (endAt as Date);
554
+ const minutes = Math.round((end.getTime() - start.getTime()) / 60000);
555
+ if (minutes <= 0) return '';
316
556
 
317
557
  if (minutes >= 60) {
318
558
  const hours = Math.floor(minutes / 60);
@@ -371,12 +611,7 @@ export function formatDateUTC(value: string | number | null | undefined, options
371
611
 
372
612
  if (!Number.isFinite(ms)) return fallback;
373
613
 
374
- return new Date(ms).toLocaleDateString('en-US', {
375
- year: 'numeric',
376
- month: 'short',
377
- day: 'numeric',
378
- timeZone: timezone === 'local' ? undefined : 'UTC',
379
- });
614
+ return formatDateWithTimezone(ms, timezone === 'local' ? VIEWER_TIMEZONE : null, 'medium');
380
615
  }
381
616
 
382
617
  /**
@@ -391,7 +626,7 @@ export function formatEntryMonthUTC(
391
626
  style: 'short' | 'long' = 'short',
392
627
  ): string | null {
393
628
  if (!entryMonth) return null;
394
- return new Date(entryMonth).toLocaleDateString('en-US', { month: style, year: 'numeric', timeZone: 'UTC' });
629
+ return formatDateWithTimezone(entryMonth, null, style === 'long' ? 'monthYear' : 'monthYearShort');
395
630
  }
396
631
 
397
632
  /**
@@ -399,11 +634,10 @@ export function formatEntryMonthUTC(
399
634
  * (privacy policy, terms of service). Locale-stable: always en-US.
400
635
  */
401
636
  export function formatLegalDate(dateInput: string): string {
402
- return new Intl.DateTimeFormat('en-US', {
403
- year: 'numeric',
404
- month: '2-digit',
405
- day: '2-digit',
406
- }).format(new Date(dateInput));
637
+ // Was rendered with NO zone, so a document dated `2026-03-01` read 02/28/2026
638
+ // for any reader west of UTC — and differently on the server. A legal date is
639
+ // a calendar date: UTC-pinned, like every other content date.
640
+ return formatDateWithTimezone(dateInput, null, 'numeric');
407
641
  }
408
642
 
409
643
  /**
@@ -539,16 +773,12 @@ export function getTrendColors(
539
773
  */
540
774
  export function formatDateRange(start: string | null | undefined, end: string | null | undefined): string {
541
775
  if (!start || !end) return '';
542
- const fmt = (s: string): string => {
543
- const bareMatch = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
544
- const d = bareMatch ? new Date(Number(bareMatch[1]), Number(bareMatch[2]) - 1, Number(bareMatch[3])) : new Date(s);
545
- if (Number.isNaN(d.getTime())) return s;
546
- return d.toLocaleDateString(undefined, {
547
- month: 'short',
548
- day: 'numeric',
549
- year: 'numeric',
550
- });
551
- };
776
+ // A bare `YYYY-MM-DD` is a calendar date: rendered UTC-pinned it reads as the
777
+ // day written, on any machine. It used to be rebuilt as a LOCAL midnight and
778
+ // rendered in the viewer's zone and locale, which got the day right only by
779
+ // pairing two local conversions, and differed between server and client.
780
+ const fmt = (s: string): string =>
781
+ formatDateWithTimezone(s, /^\d{4}-\d{2}-\d{2}$/.test(s) ? null : VIEWER_TIMEZONE, 'medium') || s;
552
782
  return `${fmt(start)} — ${fmt(end)}`;
553
783
  }
554
784
 
@@ -565,18 +795,11 @@ export function formatDateRange(start: string | null | undefined, end: string |
565
795
  * date-only fields).
566
796
  */
567
797
  export function formatDateTimeAt(dateString: string): string {
568
- const date = new Date(dateString);
569
- const dateStr = date.toLocaleDateString('en-US', {
570
- month: 'short',
571
- day: 'numeric',
572
- year: 'numeric',
573
- });
574
- const timeStr = date.toLocaleTimeString('en-US', {
575
- hour: 'numeric',
576
- minute: '2-digit',
577
- hour12: true,
578
- });
579
- return `${dateStr} at ${timeStr}`;
798
+ // Viewer-local by design (see above): the date and the time are stated in the
799
+ // SAME zone, by the same renderer.
800
+ const dateStr = formatDateWithTimezone(dateString, VIEWER_TIMEZONE, 'medium');
801
+ const timeStr = formatTimeWithTimezone(dateString, VIEWER_TIMEZONE);
802
+ return dateStr && timeStr ? `${dateStr} at ${timeStr}` : '';
580
803
  }
581
804
 
582
805
  /**
@@ -734,3 +957,81 @@ export function formatBioText(aboutHtml: string | null | undefined, fallback: st
734
957
 
735
958
  return stripHtml(aboutHtml).trim() || fallback;
736
959
  }
960
+
961
+ /**
962
+ * THE program CLOCK — one time, or a start–end range, in the resolved zone.
963
+ *
964
+ * The third member of the set beside `formatProgramDate` (the day) and
965
+ * `formatWebinarTimeMeta` (time + duration), and it exists because the page
966
+ * header rebuilt it locally: an `instant ?? utcDate` fallback and a
967
+ * zone-labelled render — the same things the meta
968
+ * helper owns, re-applied at the call site, which is exactly what that
969
+ * helper's docblock says goes wrong. The header also appended the RAW IANA
970
+ * name while the slot beneath it used the short name, so one component
971
+ * printed "America/New_York" and "EDT" six lines apart.
972
+ *
973
+ * Only the LAST clock carries the zone label, so a range reads
974
+ * "9:00 AM - 5:00 PM EDT" rather than labelling both ends.
975
+ */
976
+ export function formatProgramTimeRange(
977
+ at: ProgramInstant,
978
+ opts: { startAt?: string | null; endAt?: string | null; withZoneLabel?: boolean } = {},
979
+ ): string {
980
+ // `instant` is null when the row declares no zone; `utcDate` is the canonical
981
+ // value then, and the formatter's own UTC pin renders it deterministically.
982
+ // Resolved ONCE — spelling this chain twice is how the previous version of
983
+ // this pair drifted apart.
984
+ const source = at.instant ?? at.utcDate ?? opts.startAt;
985
+ const label = opts.withZoneLabel === true;
986
+ // Each of these builds an `Intl.DateTimeFormat`, so they are computed once
987
+ // rather than per branch.
988
+ const bare = formatTimeWithTimezone(source, at.timezone);
989
+ const labelled = label ? formatTimeWithTimezone(source, at.timezone, { withZoneLabel: true }) : bare;
990
+ // An INVERTED range is not rendered as a range. Its sibling
991
+ // `formatDurationFromRange` already refuses exactly this — its docblock
992
+ // records the "-45m" that shipped on a card — and this renderer guarded the
993
+ // unusable-endpoint cases but stopped one step short of the ordering check,
994
+ // so a corrupt row read "11:00 PM - 9:00 PM EDT". The START is still true, so
995
+ // it is kept; only the impossible pairing is dropped.
996
+ const ordered = isOrderedRange(source, opts.endAt);
997
+ const end = ordered && opts.endAt ? formatTimeWithTimezone(opts.endAt, at.timezone, { withZoneLabel: label }) : '';
998
+ // An end with no usable start is not a range, and rendering it alone puts a
999
+ // FINISH time where the reader expects a start. Say nothing instead.
1000
+ if (!bare) return '';
1001
+ // Only the LAST clock carries the label, so a range reads "9:00 AM - 5:00 PM EDT".
1002
+ return end ? `${bare} - ${end}` : labelled;
1003
+ }
1004
+
1005
+ /**
1006
+ * "4:00 PM EDT · 45m" — a webinar's time and duration as one meta string.
1007
+ *
1008
+ * Extracted because this exact three-line composition existed in the chat card
1009
+ * and the public page header, and they DRIFTED: the card was corrected to read
1010
+ * the resolved display instant while the page still read the raw `start_at`.
1011
+ *
1012
+ * The split is the point: the TIME comes from the resolved `instant`, the
1013
+ * DURATION from `startAt`/`endAt`, because elapsed time is not a display date.
1014
+ * Both sides of the separator are gated, so neither a suppressed duration nor
1015
+ * an unrenderable time can leave one dangling.
1016
+ *
1017
+ * It takes the RESOLVED `ProgramInstant`, exactly as `formatProgramDate` does.
1018
+ * While it took `instant` / `timezone` as
1019
+ * loose fields, all four callers re-projected them off the same resolved value
1020
+ * and no two projections matched — so a zoneless webinar rendered "4:00 PM UTC"
1021
+ * on the public card and "4:00 PM" on the chat card, which exist to mirror each
1022
+ * other, and the detail page fell back to a different source instant from the
1023
+ * card's. Taking the value whole is what makes those disagreements unsayable.
1024
+ */
1025
+ export function formatWebinarTimeMeta(
1026
+ at: ProgramInstant,
1027
+ opts: { startAt: string | null; endAt: string | null; withZoneLabel?: boolean },
1028
+ ): string {
1029
+ // The CLOCK is `formatProgramTimeRange`'s, not a second rendering of it: this
1030
+ // function restated the same decisions (the instant fallback, the labelled
1031
+ // render) thirty lines below the sibling that
1032
+ // owns them, and the two had already drifted apart on the fallback chain.
1033
+ // Only the DURATION is this function's own contribution.
1034
+ const duration = formatDurationFromRange(opts.startAt, opts.endAt);
1035
+ const time = formatProgramTimeRange(at, { startAt: opts.startAt, withZoneLabel: opts.withZoneLabel });
1036
+ return [time, duration].filter(Boolean).join(' · ');
1037
+ }
@@ -138,7 +138,15 @@ export {
138
138
  formatDurationMMSS,
139
139
  formatDurationCompact,
140
140
  formatTimeWithTimezone,
141
+ formatDateWithTimezone,
142
+ formatDateTimeYmd,
143
+ VIEWER_TIMEZONE,
144
+ formatWebinarTimeMeta,
145
+ formatProgramDate,
146
+ formatProgramTimeRange,
147
+ type ZonedDateStyle,
141
148
  formatDurationFromRange,
149
+ isOrderedRange,
142
150
  type FormatDateUTCOptions,
143
151
  formatDateUTC,
144
152
  formatEntryMonthUTC,
@@ -393,3 +401,19 @@ export * from './csv';
393
401
  export * from './social-platforms';
394
402
  // The ODS badge palette a row whose colour is data picks from (departments).
395
403
  export { BADGE_PALETTE, isBadgePaletteKey, pickBadgePaletteColor, type BadgePaletteKey } from './badge-palette';
404
+
405
+ // "Which instant does a program render, in which zone, and does it have a
406
+ // clock" — THE resolver every webinar/event/podcast surface reads, in this
407
+ // package and in the hub. Exported because the hub re-derived it by hand while
408
+ // it was package-private, and the copies drifted.
409
+ export {
410
+ programDateInstant,
411
+ programMetaFormatters,
412
+ programMetaLine,
413
+ programStr,
414
+ webinarTiming,
415
+ } from './program-instant';
416
+ // The concrete renderer bundle, so every surface in BOTH repos builds its meta
417
+ // line from one set rather than mirroring the triple.
418
+ export { PROGRAM_META_RENDERERS } from './program-meta-renderers';
419
+ export type { ProgramDateFields, ProgramInstant, ProgramMetaRenderers } from './program-instant';