(events)
| 56 | } |
| 57 | |
| 58 | function mapHourlyEventsToLocalTime(events) { |
| 59 | const now = new Date(); |
| 60 | const start = new Date(now); |
| 61 | start.setHours(0, 0, 0, 0); |
| 62 | |
| 63 | const hours = Array.from({ length: 24 }, (_, i) => { |
| 64 | const hDate = new Date(start.getTime() + i * 3600 * 1000); |
| 65 | let h = hDate.getHours(); |
| 66 | const ampm = h >= 12 ? "PM" : "AM"; |
| 67 | h = h % 12 || 12; |
| 68 | return { |
| 69 | formattedHour: `${h}${ampm}`, |
| 70 | hour: hDate.getHours(), |
| 71 | date: hDate.toISOString().slice(0, 10), |
| 72 | count: 0, |
| 73 | isCurrent: |
| 74 | now.getHours() === hDate.getHours() && |
| 75 | now.getDate() === hDate.getDate(), |
| 76 | }; |
| 77 | }); |
| 78 | |
| 79 | events.forEach((e) => { |
| 80 | const utc = new Date(e.hour + "Z"); |
| 81 | const loc = new Date( |
| 82 | utc.getTime() + |
| 83 | utc.getTimezoneOffset() * 60000 + |
| 84 | now.getTimezoneOffset() * -60000 |
| 85 | ); |
| 86 | const idx = hours.findIndex( |
| 87 | (h) => |
| 88 | h.date === loc.toISOString().slice(0, 10) && h.hour === loc.getHours() |
| 89 | ); |
| 90 | if (idx !== -1) hours[idx].count += Number(e.count) || 0; |
| 91 | }); |
| 92 | |
| 93 | return hours; |
| 94 | } |
| 95 | |
| 96 | function buildTableCard(titleLeft, titleRight, rows) { |
| 97 | return dom( |
no outgoing calls
no test coverage detected