improve date presentation in event list view

This commit is contained in:
2024-05-12 23:34:07 +02:00
parent 0f16893cf9
commit 57ce71453e
3 changed files with 35 additions and 5 deletions

View File

@ -5,9 +5,12 @@ import {
getWeek,
getDate,
endOfWeek,
startOfToday,
startOfWeek,
isAfter,
eachDayOfInterval,
addWeeks,
parseISO,
} from "date-fns";
import { toLocalTime, formatDate } from "./date";
import { graphql } from "@/gql";
@ -145,3 +148,17 @@ export function organizeEventsByDate(events: SingularEvent[]): EventsByDate {
return eventsByDate;
}
export function getClosestOccurrence(event: EventFragment) {
const today = startOfToday();
const occurrences = event?.occurrences ?? [];
const futureOccurrences = occurrences.filter((occurrence) =>
isAfter(toLocalTime(occurrence.start), today)
);
futureOccurrences.sort(
(a, b) => parseISO(a.start).getTime() - parseISO(b.start).getTime()
);
return futureOccurrences[0];
}