MCPcopy
hub / github.com/PostHog/posthog / formatEvents

Function formatEvents

frontend/src/scenes/events/eventsTableLogic.ts:26–47  ·  view source on GitHub ↗
(events: EventType[], newEvents: EventType[])

Source from the content-addressed store, hash-verified

24const POLL_TIMEOUT = 5000
25
26const formatEvents = (events: EventType[], newEvents: EventType[]): EventsTableRowItem[] => {
27 let eventsFormatted: EventsTableRowItem[] = []
28
29 eventsFormatted = events.map((item) => ({
30 event: item,
31 }))
32 eventsFormatted.forEach((event, index) => {
33 const previous = eventsFormatted[index - 1]
34 if (
35 index > 0 &&
36 event.event &&
37 previous.event &&
38 !dayjs(event.event.timestamp).isSame(previous.event.timestamp, 'day')
39 ) {
40 eventsFormatted.splice(index, 0, { date_break: dayjs(event.event.timestamp).format('LL') })
41 }
42 })
43 if (newEvents.length > 0) {
44 eventsFormatted.splice(0, 0, { new_events: true })
45 }
46 return eventsFormatted
47}
48
49const daysAgo = (days: number): string => now().subtract(days, 'day').toISOString()
50

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…