Skip to content

Commit

Permalink
Sort lesson absences by time on preceding absences modal (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
caebr authored Jun 11, 2021
1 parent 4449b7a commit fd99109
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/app/presence-control/utils/lessons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function getPrecedingAbsences(
absence.LessonRef.From < lesson?.LessonDateTimeFrom
),
'Id'
).sort();
).sort(lessonAbsenceTimeComparator);
}

export function getPresenceControlEntriesForLesson(
Expand Down Expand Up @@ -143,3 +143,24 @@ function lessonPresencesComparator(
): number {
return a.StudentFullName.localeCompare(b.StudentFullName);
}

/**
* Sorts by LessonRef.From and LessonRef.To, if present.
*/
function lessonAbsenceTimeComparator(
a: LessonAbsence,
b: LessonAbsence
): number {
if (
a.LessonRef.From &&
a.LessonRef.To &&
b.LessonRef.From &&
b.LessonRef.To
) {
if (a.LessonRef.From.getTime() - b.LessonRef.From.getTime() === 0) {
return a.LessonRef.To.getTime() - b.LessonRef.To.getTime();
}
return a.LessonRef.From.getTime() - b.LessonRef.From.getTime();
}
return 0;
}

0 comments on commit fd99109

Please sign in to comment.