blob: 09631b9afe9f8b53a2d84abbaaf23dd07ac15550 (
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("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;
};
|