optional shift for td/tp (#10)

This commit is contained in:
Mylloon 2024-09-13 19:07:18 +02:00
parent fabcd6dac9
commit 8e7fdaf3c8
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 16 additions and 7 deletions

View file

@ -40,7 +40,7 @@ pub async fn get_start_date(
.map_or("1 septembre".to_owned(), |m| m.as_str().to_owned())
}
pub fn info(semester_opt: Option<i8>, year_opt: Option<i32>, date: &str) -> Info {
pub fn info(semester_opt: Option<i8>, year_opt: Option<i32>, date: &str, skip_week: bool) -> Info {
let semester = get_semester(semester_opt);
let year = get_year(year_opt, semester);
@ -60,8 +60,10 @@ pub fn info(semester_opt: Option<i8>, year_opt: Option<i32>, date: &str) -> Info
let cours_s1 = vec![(date_s1_1, weeks_s1_1), (date_s1_2, weeks_s1_2)];
let cours_s2 = vec![(date_s2_1, weeks_s2_1), (date_s2_2, weeks_s2_2)];
let tdtp_s1 = derive_from_cours(&cours_s1);
let tdtp_s2 = derive_from_cours(&cours_s2);
let delta = i64::from(skip_week);
let tdtp_s1 = derive_from_cours(&cours_s1, delta);
let tdtp_s2 = derive_from_cours(&cours_s2, delta);
HashMap::from([
(
@ -82,13 +84,16 @@ pub fn info(semester_opt: Option<i8>, year_opt: Option<i32>, date: &str) -> Info
}
/// Find TD/TP dates, based on the ones from courses
fn derive_from_cours(courses: &InfoList) -> Vec<(DateTime<Utc>, i64)> {
fn derive_from_cours(courses: &InfoList, delta: i64) -> Vec<(DateTime<Utc>, i64)> {
// TD/TP start one week after courses
let before_break = courses.first().unwrap();
let after_break = courses.last().unwrap();
vec![
(before_break.0 + Duration::weeks(1), before_break.1 - 1),
(after_break.0, after_break.1 + 1),
(
before_break.0 + Duration::weeks(delta),
before_break.1 - delta,
),
(after_break.0, after_break.1 + delta),
]
}

View file

@ -38,6 +38,10 @@ struct Args {
/// First day of your year
#[clap(short, long)]
first_day: Option<String>,
/// If TD/TP start a week after courses
#[clap(short, long)]
week_skip: bool,
}
#[tokio::main]
@ -73,7 +77,7 @@ async fn main() {
};
println!("Récupération des informations par rapport à l'année...");
let info = info::info(args.semester, args.year, &date);
let info = info::info(args.semester, args.year, &date, args.week_skip);
if args.export.is_some() {
// Export the calendar