From 4015b3777fd17c2e7c7cdb5c03f156e00f9dbff9 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 3 Jan 2025 10:41:42 +0100 Subject: [PATCH] option to not use timezone --- src/ics.rs | 34 ++++++++++++++++++++++------------ src/main.rs | 6 +++++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/ics.rs b/src/ics.rs index 0a7b31c..b83ebe2 100644 --- a/src/ics.rs +++ b/src/ics.rs @@ -9,20 +9,26 @@ use ics::{ Event, ICalendar, Standard, }; -pub fn export(courses: Vec, filename: &mut String) { +pub fn export( + courses: Vec, + filename: &mut String, + with_tz: bool, +) { let mut calendar = ICalendar::new("2.0", "cal7tor"); // Add Europe/Paris timezone let timezone_name = "Europe/Paris"; - calendar.add_timezone(ics::TimeZone::standard( - timezone_name, - Standard::new( - // Add a Z because it's UTC - dt_ical(chrono::Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()) + "Z", - "+0100", - "+0200", - ), - )); + if with_tz { + calendar.add_timezone(ics::TimeZone::standard( + timezone_name, + Standard::new( + // Add a Z because it's UTC + dt_ical(chrono::Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()) + "Z", + "+0100", + "+0200", + ), + )); + } // Create events which contains the information regarding the course for course in courses { @@ -50,12 +56,16 @@ pub fn export(courses: Vec, filename: &mut Str // Start time of the course let mut date_start = DtStart::new(dt_ical(course.dtstart.unwrap())); - date_start.add(TzIDParam::new(timezone_name)); + if with_tz { + date_start.add(TzIDParam::new(timezone_name)); + } event.push(date_start); // End time of the course let mut date_end = DtEnd::new(dt_ical(course.dtend.unwrap())); - date_end.add(TzIDParam::new(timezone_name)); + if with_tz { + date_end.add(TzIDParam::new(timezone_name)); + } event.push(date_end); // Room location diff --git a/src/main.rs b/src/main.rs index 2a3ddd0..d3b6bd8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,10 @@ struct Args { /// If TD/TP start a week after courses #[clap(short, long)] week_skip: bool, + + /// If the exported ICS file should not use the timezone + #[clap(short, long)] + no_tz: bool, } #[tokio::main] @@ -80,7 +84,7 @@ async fn main() { let mut filename = args.export.unwrap(); let builded_timetable = timetable::build(&timetable, &info); - ics::export(builded_timetable, &mut filename); + ics::export(builded_timetable, &mut filename, !args.no_tz); println!("Fichier .ICS construit et exporté => {filename}"); } else {