From 8cb99e69afad2621e7e1c647363f4d8dc08816c7 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 16 Aug 2022 14:41:51 +0200 Subject: [PATCH] add post-break weeks --- src/timetable.rs | 45 ++++++++++++++++++++++++----------------- src/timetable/models.rs | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index fb9c40e..1fda417 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -205,8 +205,8 @@ type T = ( type D = std::collections::HashMap< // Semester usize, - // List of start and end times of course weeks - Vec<(chrono::DateTime, chrono::DateTime)>, + // List of start and repetition of course weeks + Vec<(chrono::DateTime, i64)>, >; /// Build the timetable @@ -242,26 +242,33 @@ pub fn build(timetable: T, dates: D) -> Vec { let mut semester = Vec::new(); // Start date of the back-to-school week - let mut date = dates.get(&timetable.1 .0).unwrap().get(0).unwrap().0; - for day in timetable.1 .1 { - for mut course in day.courses.into_iter().flatten() { - // Get the hours - let start = schedules.get(course.start).unwrap().0; - let end = schedules.get(course.start + course.size - 1).unwrap().1; + let data = dates.get(&timetable.1 .0).unwrap().get(0).unwrap(); + let mut date = data.0; + // 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; - // 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); } semester diff --git a/src/timetable/models.rs b/src/timetable/models.rs index 01cdda7..0387ee7 100644 --- a/src/timetable/models.rs +++ b/src/timetable/models.rs @@ -1,4 +1,4 @@ -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Course { /// Course's name pub name: String,