From 732f56f0be5716bb09534554e456aac63aba5594 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 16 Aug 2022 14:50:22 +0200 Subject: [PATCH] include the after-break --- src/timetable.rs | 51 +++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index 1fda417..eb5d98a 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -242,33 +242,40 @@ pub fn build(timetable: T, dates: D) -> Vec { let mut semester = Vec::new(); // Start date of the back-to-school week - let data = dates.get(&timetable.1 .0).unwrap().get(0).unwrap(); - let mut date = data.0; + let break_data = dates.get(&timetable.1 .0).unwrap(); + let before_break = break_data.get(0).unwrap(); + let mut date = before_break.0; + let mut rep = before_break.1; // For each weeks - for _ in 0..(data.1) { - for day in &timetable.1 .1 { - for mut course in day.courses.clone().into_iter().flatten() { - // Get the hours - let start = schedules.get(course.start).unwrap().0; - // -1 because we only add when the size is > 1 - let end = schedules.get(course.start + course.size - 1).unwrap().1; + for _ in 0..2 { + for _ in 0..rep { + for day in &timetable.1 .1 { + for mut course in day.courses.clone().into_iter().flatten() { + // Get the hours + let start = schedules.get(course.start).unwrap().0; + // -1 because we only add when the size is > 1 + let end = schedules.get(course.start + course.size - 1).unwrap().1; - // Add the changed datetimes - course.dtstart = Some( - Utc.ymd(date.year(), date.month(), date.day()) - .and_hms(start.0, start.1, 0), - ); - course.dtend = Some( - Utc.ymd(date.year(), date.month(), date.day()) - .and_hms(end.0, end.1, 0), - ); + // Add the changed datetimes + course.dtstart = Some( + Utc.ymd(date.year(), date.month(), date.day()) + .and_hms(start.0, start.1, 0), + ); + course.dtend = Some( + Utc.ymd(date.year(), date.month(), date.day()) + .and_hms(end.0, end.1, 0), + ); - semester.push(course); + semester.push(course); + } + date += Duration::days(1); } - date += Duration::days(1); + // From friday to monday + date += Duration::days(2); } - // From friday to monday - date += Duration::days(2); + let after_break = break_data.get(1).unwrap(); + date = after_break.0; + rep = after_break.1; } semester