summaryrefslogtreecommitdiff
path: root/src/lib/event.ts
blob: bcb7cd9c34e5f563bd709f5c2c33fab3b9f73d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import i18next from "i18next";
import { IEventGroup } from "../models/EventGroup.js";

export interface EventListEvent {
    id: string;
    name: string;
    location: string;
    displayDate: string;
    eventHasConcluded: boolean;
    startMoment: moment.Moment;
    endMoment: moment.Moment;
    eventGroup?: IEventGroup;
}

export const bucketEventsByMonth = (
    acc: Record<string, any>[],
    event: EventListEvent,
) => {
    event.startMoment.locale(i18next.language);
    const month = event.startMoment.format(i18next.t("common.year-month-format" ));
    const matchingBucket = acc.find((bucket) => bucket.title === month);
    if (!matchingBucket) {
        acc.push({
            title: month,
            events: [event],
        });
    } else {
        matchingBucket.events.push(event);
    }
    return acc;
};