(events: AnalyticsEvent[], period: string)
| 49 | * Filter events by period. Supports "7d", "30d", and "all". |
| 50 | */ |
| 51 | export function filterByPeriod(events: AnalyticsEvent[], period: string): AnalyticsEvent[] { |
| 52 | if (period === 'all') return events; |
| 53 | |
| 54 | const match = period.match(/^(\d+)d$/); |
| 55 | if (!match) return events; |
| 56 | |
| 57 | const days = parseInt(match[1], 10); |
| 58 | const cutoff = new Date(Date.now() - days * 24 * 60 * 60 * 1000); |
| 59 | |
| 60 | return events.filter(e => { |
| 61 | const d = new Date(e.ts); |
| 62 | return !isNaN(d.getTime()) && d >= cutoff; |
| 63 | }); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Format a report string from a list of events. |
no outgoing calls