Skip to content

Commit

Permalink
fix(timetable): sort combined timetable data by date
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 committed Jan 16, 2025
1 parent 63e0a3d commit 96d2b04
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/utils/timetable-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export async function getFriendlyTimetable(
* // ],
* // }
**/

export function getGroupedTimetable(
timetable: FriendlyTimetableEntry[],
exams: Exam[]
Expand All @@ -133,22 +134,29 @@ export function getGroupedTimetable(
}
}),
]

// Sort combinedData by date
combinedData.sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
)

const dates = [
...new Set(
combinedData.map(
(item) => new Date(item.date).toISOString().split('T')[0]
)
),
]

const groups = dates.map((date) => ({
title: new Date(date),
data: combinedData.filter(
(item) => new Date(item.date).toISOString().split('T')[0] === date
),
}))

return groups as TimetableSections[]
}

export function convertTimetableToWeekViewEvents(
entries: FriendlyTimetableEntry[],
color: string,
Expand Down

0 comments on commit 96d2b04

Please sign in to comment.