From d634c7b90f29e8d1c9545889b79943110075d158 Mon Sep 17 00:00:00 2001 From: Yuta1409 Date: Mon, 8 Apr 2024 15:59:50 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B:=20correction=20when=20first?= =?UTF-8?q?=20loading=20timetable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../week_schedule/cubit/week_schedule_cubit.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart index 8584283..880c4af 100644 --- a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart @@ -51,18 +51,25 @@ class WeekScheduleCubit extends Cubit { } DateTime findClosestDate(List allEvents) { + DateTime currentDate = DateTime.now(); + + // If today is monday, return today date + if (currentDate.weekday == DateTime.monday) { + return currentDate; + } + // Sort the schedules by date allEvents.sort((a, b) => a.date.compareTo(b.date)); // Find the schedule with the date closest to today for (var schedule in allEvents) { - if (schedule.date.isAfter(DateTime.now()) || - schedule.date.isAtSameMomentAs(DateTime.now())) { + if (schedule.date.isAfter(currentDate) || + schedule.date.isAtSameMomentAs(currentDate)) { return schedule.date; } } - return DateTime.now(); + return currentDate; } int findTodayIndex(List allEvents) { From 2e4e4fdd3ab212910d22f367c1e0d417ccd2b482 Mon Sep 17 00:00:00 2001 From: Yuta1409 Date: Mon, 8 Apr 2024 18:04:12 +0200 Subject: [PATCH 2/3] :bug: adaptation of timetable display with date --- .../week_schedule/cubit/week_schedule_cubit.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart index 880c4af..0299b6b 100644 --- a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart @@ -53,18 +53,12 @@ class WeekScheduleCubit extends Cubit { DateTime findClosestDate(List allEvents) { DateTime currentDate = DateTime.now(); - // If today is monday, return today date - if (currentDate.weekday == DateTime.monday) { - return currentDate; - } - - // Sort the schedules by date - allEvents.sort((a, b) => a.date.compareTo(b.date)); - - // Find the schedule with the date closest to today + // si la date d'aujourd'hui n'est pas dans la liste des événements, on retourne la date suivante qui à un evènement for (var schedule in allEvents) { - if (schedule.date.isAfter(currentDate) || - schedule.date.isAtSameMomentAs(currentDate)) { + if (schedule.date.isAfter(currentDate) && + schedule.events.any((event) => + event.entity.activite != "Pas cours" && + event.entity.activite != "FERIE")) { return schedule.date; } } From febae4f95418c5cf40ab3e734c661e8a1c70914a Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 10 Apr 2024 10:12:37 +0200 Subject: [PATCH 3/3] :bug:: fix date algo --- frontend/app_student/.run/main_prod.run.xml | 6 ----- .../cubit/week_schedule_cubit.dart | 23 ++++++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) delete mode 100644 frontend/app_student/.run/main_prod.run.xml diff --git a/frontend/app_student/.run/main_prod.run.xml b/frontend/app_student/.run/main_prod.run.xml deleted file mode 100644 index 7a31433..0000000 --- a/frontend/app_student/.run/main_prod.run.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart index 0299b6b..0401094 100644 --- a/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart +++ b/frontend/app_student/lib/week_schedule/cubit/week_schedule_cubit.dart @@ -50,16 +50,23 @@ class WeekScheduleCubit extends Cubit { } } - DateTime findClosestDate(List allEvents) { + DateTime findClosestDate(List daySchedules) { DateTime currentDate = DateTime.now(); - // si la date d'aujourd'hui n'est pas dans la liste des événements, on retourne la date suivante qui à un evènement - for (var schedule in allEvents) { - if (schedule.date.isAfter(currentDate) && - schedule.events.any((event) => - event.entity.activite != "Pas cours" && - event.entity.activite != "FERIE")) { - return schedule.date; + for (var day in daySchedules) { + if (day.date == currentDate) { + currentDate = day.date; + return currentDate; + } else { + try { + var nextDayWithEvent = daySchedules.firstWhere( + (daySchedule) => daySchedule.date.isAfter(currentDate)); + currentDate = nextDayWithEvent.date; + return currentDate; + } catch (e) { + // No next day with an event found, continue to the next day + continue; + } } }