add post-break weeks

This commit is contained in:
Mylloon 2022-08-16 14:41:51 +02:00
parent 1fea0a4e40
commit 8cb99e69af
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 27 additions and 20 deletions

View file

@ -205,8 +205,8 @@ type T = (
type D = std::collections::HashMap< type D = std::collections::HashMap<
// Semester // Semester
usize, usize,
// List of start and end times of course weeks // List of start and repetition of course weeks
Vec<(chrono::DateTime<Utc>, chrono::DateTime<Utc>)>, Vec<(chrono::DateTime<Utc>, i64)>,
>; >;
/// Build the timetable /// Build the timetable
@ -242,26 +242,33 @@ pub fn build(timetable: T, dates: D) -> Vec<models::Course> {
let mut semester = Vec::new(); let mut semester = Vec::new();
// Start date of the back-to-school week // Start date of the back-to-school week
let mut date = dates.get(&timetable.1 .0).unwrap().get(0).unwrap().0; let data = dates.get(&timetable.1 .0).unwrap().get(0).unwrap();
for day in timetable.1 .1 { let mut date = data.0;
for mut course in day.courses.into_iter().flatten() { // For each weeks
// Get the hours for _ in 0..(data.1) {
let start = schedules.get(course.start).unwrap().0; for day in &timetable.1 .1 {
let end = schedules.get(course.start + course.size - 1).unwrap().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 // Add the changed datetimes
course.dtstart = Some( course.dtstart = Some(
Utc.ymd(date.year(), date.month(), date.day()) Utc.ymd(date.year(), date.month(), date.day())
.and_hms(start.0, start.1, 0), .and_hms(start.0, start.1, 0),
); );
course.dtend = Some( course.dtend = Some(
Utc.ymd(date.year(), date.month(), date.day()) Utc.ymd(date.year(), date.month(), date.day())
.and_hms(end.0, end.1, 0), .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 semester

View file

@ -1,4 +1,4 @@
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Course { pub struct Course {
/// Course's name /// Course's name
pub name: String, pub name: String,