MCPcopy Create free account
hub / github.com/garrytan/gstack / filterByPeriod

Function filterByPeriod

scripts/analytics.ts:51–64  ·  view source on GitHub ↗
(events: AnalyticsEvent[], period: string)

Source from the content-addressed store, hash-verified

49 * Filter events by period. Supports "7d", "30d", and "all".
50 */
51export 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.

Callers 3

runScriptFunction · 0.90
analytics.test.tsFile · 0.90
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

runScriptFunction · 0.72