From 0be66c25955b7b21bf6fe298eee8d957ed371f3c Mon Sep 17 00:00:00 2001
From: Julian Leucker <leuckerj@gmail.com>
Date: Tue, 25 Jun 2024 12:01:41 +0200
Subject: [PATCH] Fix tardiness length validation

---
 .../coursebook/personal_notes/TardinessNote.vue       | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/personal_notes/TardinessNote.vue b/aleksis/apps/alsijil/frontend/components/coursebook/personal_notes/TardinessNote.vue
index e5733941d..a65c6bf5f 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/personal_notes/TardinessNote.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/personal_notes/TardinessNote.vue
@@ -4,6 +4,7 @@ import {
   deletePersonalNotes,
   updatePersonalNotes,
 } from "./personal_notes.graphql";
+import { DateTime } from "luxon";
 import personalNoteRelatedMixin from "./personalNoteRelatedMixin";
 import mutateMixin from "aleksis.core/mixins/mutateMixin.js";
 import DeleteDialog from "aleksis.core/components/generic/dialogs/DeleteDialog.vue";
@@ -18,8 +19,11 @@ export default {
       return this.participation.noteWithTardiness;
     },
     lessonLength() {
-      // TODO: calculate lesson length in minutes
-      return 60;
+      const lessonStart = DateTime.fromISO(this.documentation.datetimeStart);
+      const lessonEnd = DateTime.fromISO(this.documentation.datetimeEnd);
+
+      let diff = lessonEnd.diff(lessonStart, 'minutes');
+      return diff.toObject().minutes;
     },
     model: {
       get() {
@@ -98,8 +102,7 @@ export default {
       };
     },
     lessonLengthRule(time) {
-      // FIXME: translation
-      return time <= lessonLength || this.$t("alsijil.personal_notes.lesson_length_exceeded");
+      return time == null || time <= this.lessonLength || this.$t("alsijil.personal_notes.lesson_length_exceeded");
     }
   },
   data() {
-- 
GitLab