Skip to content

Commit 1ad91a8

Browse files
antoKeinanenAdventune
andauthoredJul 28, 2024··
fix: timetable default index (#31)
* fix: timetable default index * fix: compare start dates correctly * fix: code style --------- Co-authored-by: Samu Kupiainen <[email protected]>
1 parent e2a6b14 commit 1ad91a8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎api/eventService.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Colors } from '@/styles';
2+
import dayjs from 'dayjs';
23

34
type ApiEventLocation = {
45
term_id: number;
@@ -105,15 +106,14 @@ export const determineStartDayIndex = (events: AssemblyEvent[]): number => {
105106
}
106107

107108
const days = [...new Set(events.map((event) => event.start))];
108-
const start_day_index = days.findIndex((day) => doorsOpen.start === day);
109+
const startDayIndex = days.findIndex((day) => dayjs(doorsOpen.start).isSame(day, 'day'));
109110

110-
if (start_day_index === -1) {
111+
if (startDayIndex === -1) {
111112
console.error("Failed to find matching day for 'Doors Open' event");
112113
return 0;
113114
}
114115

115-
// the index returned by findIndex if off by one
116-
return start_day_index - 1;
116+
return startDayIndex;
117117
};
118118

119119
const API_BASE_PATH = `https://wp.assembly.org/${determineEvent()}/index.php?rest_route=/api/v1`;

0 commit comments

Comments
 (0)
Please sign in to comment.