Fix sort date (move dates with no end date to the back

This commit is contained in:
Christian Cueni 2023-08-17 11:42:59 +02:00
parent 45a70f6b75
commit ee33d999d1
1 changed files with 12 additions and 1 deletions

View File

@ -201,7 +201,18 @@ export const useCourseSessionsStore = defineStore("courseSessions", () => {
allCourseSessions.value?.forEach((cs) => {
allDueDatesReturn.push(...cs.due_dates);
});
allDueDatesReturn.sort((a, b) => dayjs(a.end).diff(dayjs(b.end)));
allDueDatesReturn.sort((a, b) => {
const dateA = dayjs(a.end);
const dateB = dayjs(b.end);
if (!dateA.isValid() && !dateB.isValid()) return 0; // If both are invalid, they are equal
if (!dateA.isValid()) return 1; // If dateA is invalid, it goes after dateB
if (!dateB.isValid()) return -1; // If dateB is invalid, it goes after dateA
return dateA.diff(dateB); // Otherwise, sort by the end date
});
return allDueDatesReturn;
}