anear-js-api 1.2.0 → 1.2.1

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.
@@ -15,6 +15,9 @@ const REFRESH_EVENT_TYPES = new Set([
15
15
  // Temporary disconnects (useful for "halt/pause" and UI indicators):
16
16
  'PARTICIPANT_DISCONNECT',
17
17
  'HOST_DISCONNECT',
18
+ // Permanent exits (should update participant counts and UI):
19
+ 'PARTICIPANT_EXIT',
20
+ 'HOST_EXIT',
18
21
  // Location/heartbeat updates can also want a "refresh current view":
19
22
  'PARTICIPANT_UPDATE',
20
23
  'HOST_UPDATE'
@@ -19,6 +19,81 @@ const PugHelpers = s3ImageAssetsUrl => ({
19
19
  } catch (error) {
20
20
  throw new Error("Invalid JSON for data-click-action:", finalPayload);
21
21
  }
22
+ },
23
+ /**
24
+ * Format a timestamp in the event's timezone (or fallback to local time)
25
+ * General-purpose helper that works for both time and date formatting.
26
+ *
27
+ * @param {number|Date} timestamp - Timestamp in milliseconds or Date object
28
+ * @param {string|null} timezone - IANA timezone ID (e.g., 'America/New_York') or null for local time
29
+ * @param {object} options - Intl.DateTimeFormat options
30
+ * - For time: { hour: 'numeric', minute: '2-digit', hour12: true }
31
+ * - For date: { weekday: 'short', month: 'short', day: 'numeric' }
32
+ * - For both: { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true }
33
+ * @returns {string} Formatted date/time string
34
+ *
35
+ * @example
36
+ * // Format time only
37
+ * formatDateTime(timestamp, app.eventTimezone)
38
+ * // => "3:08 PM"
39
+ *
40
+ * // Format date only
41
+ * formatDateTime(timestamp, app.eventTimezone, { weekday: 'short', month: 'short', day: 'numeric' })
42
+ * // => "Thu, Jan 1"
43
+ *
44
+ * // Format date and time
45
+ * formatDateTime(timestamp, app.eventTimezone, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' })
46
+ * // => "Jan 1, 3:08 PM"
47
+ */
48
+ formatDateTime: (timestamp, timezone, options = { hour: 'numeric', minute: '2-digit', hour12: true }) => {
49
+ const date = timestamp instanceof Date ? timestamp : new Date(timestamp)
50
+
51
+ if (timezone && typeof Intl !== 'undefined' && Intl.DateTimeFormat) {
52
+ const formatter = new Intl.DateTimeFormat('en-US', { ...options, timeZone: timezone })
53
+ return formatter.format(date)
54
+ }
55
+
56
+ // Fallback: format based on what options were requested
57
+ const hasTimeOptions = options.hour !== undefined || options.minute !== undefined
58
+ const hasDateOptions = options.weekday !== undefined || options.month !== undefined || options.day !== undefined || options.year !== undefined
59
+
60
+ // If only time options, use simple time fallback
61
+ if (hasTimeOptions && !hasDateOptions) {
62
+ const hours = date.getHours()
63
+ const minutes = date.getMinutes()
64
+ const ampm = hours >= 12 ? 'PM' : 'AM'
65
+ const displayHours = hours % 12 || 12
66
+ return `${displayHours}:${minutes.toString().padStart(2, '0')} ${ampm}`
67
+ }
68
+
69
+ // If date options (with or without time), use UTC fallback for consistency
70
+ const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
71
+ const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
72
+ const parts = []
73
+
74
+ if (options.weekday === 'short' || options.weekday === 'long') {
75
+ parts.push(days[date.getUTCDay()])
76
+ }
77
+ if (options.month === 'short' || options.month === 'long') {
78
+ parts.push(months[date.getUTCMonth()])
79
+ }
80
+ if (options.day === 'numeric') {
81
+ parts.push(date.getUTCDate())
82
+ }
83
+ if (options.year === 'numeric') {
84
+ parts.push(date.getUTCFullYear())
85
+ }
86
+
87
+ // Add time if requested
88
+ if (hasTimeOptions) {
89
+ const hours = date.getUTCHours()
90
+ const minutes = date.getUTCMinutes()
91
+ const ampm = hours >= 12 ? 'PM' : 'AM'
92
+ const displayHours = hours % 12 || 12
93
+ parts.push(`${displayHours}:${minutes.toString().padStart(2, '0')} ${ampm}`)
94
+ }
95
+
96
+ return parts.join(' ')
22
97
  }
23
98
  })
24
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anear-js-api",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Javascript Developer API for Anear Apps",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {