@openpeepshq/common 0.6.3 → 0.6.4

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.
@@ -16,6 +16,12 @@ export declare const reinterpretIsoInTimeZone: (iso: string | undefined, fromTim
16
16
  export declare const utcIsoToWallClockDate: (iso: string, timeZone: string) => Date;
17
17
  /** Treat `date`'s local components as wall time in `timeZone`. */
18
18
  export declare const wallClockDateToUtcIso: (date: Date, timeZone: string) => string;
19
+ /**
20
+ * Zone to display an event in: the viewer's zone wins, the event zone is the
21
+ * last resort. `undefined` means no resolvable zone — formatters fall through
22
+ * to the ambient device zone.
23
+ */
24
+ export declare const eventDisplayTimeZone: (eventTimeZone?: string | null, viewerTimeZone?: string | null) => string | undefined;
19
25
  /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
20
26
  export declare const eventTimeZoneOptions: (timeZone?: string | null) => Pick<Intl.DateTimeFormatOptions, "timeZone">;
21
27
  /** Clock time in the event timezone, always including a short zone name. */
@@ -98,6 +98,16 @@ export const wallClockDateToUtcIso = (date, timeZone) => {
98
98
  const local = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
99
99
  return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
100
100
  };
101
+ /**
102
+ * Zone to display an event in: the viewer's zone wins, the event zone is the
103
+ * last resort. `undefined` means no resolvable zone — formatters fall through
104
+ * to the ambient device zone.
105
+ */
106
+ export const eventDisplayTimeZone = (eventTimeZone, viewerTimeZone) => isIanaTimeZone(viewerTimeZone)
107
+ ? viewerTimeZone
108
+ : isIanaTimeZone(eventTimeZone)
109
+ ? eventTimeZone
110
+ : undefined;
101
111
  /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
102
112
  export const eventTimeZoneOptions = (timeZone) => {
103
113
  const resolved = isIanaTimeZone(timeZone) ? timeZone : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/common",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -136,6 +136,21 @@ export const wallClockDateToUtcIso = (date: Date, timeZone: string): string => {
136
136
  return zonedDateTimeToUtcIso(local, timeZone) ?? date.toISOString();
137
137
  };
138
138
 
139
+ /**
140
+ * Zone to display an event in: the viewer's zone wins, the event zone is the
141
+ * last resort. `undefined` means no resolvable zone — formatters fall through
142
+ * to the ambient device zone.
143
+ */
144
+ export const eventDisplayTimeZone = (
145
+ eventTimeZone?: string | null,
146
+ viewerTimeZone?: string | null,
147
+ ): string | undefined =>
148
+ isIanaTimeZone(viewerTimeZone)
149
+ ? viewerTimeZone
150
+ : isIanaTimeZone(eventTimeZone)
151
+ ? eventTimeZone
152
+ : undefined;
153
+
139
154
  /** Intl `timeZone` option when `timeZone` is a valid IANA identifier. */
140
155
  export const eventTimeZoneOptions = (
141
156
  timeZone?: string | null,