option to not use timezone

This commit is contained in:
Mylloon 2025-01-03 10:41:42 +01:00
parent 9d64fd65a4
commit 4015b3777f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 27 additions and 13 deletions

View file

@ -9,20 +9,26 @@ use ics::{
Event, ICalendar, Standard, Event, ICalendar, Standard,
}; };
pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut String) { pub fn export(
courses: Vec<crate::timetable::models::Course>,
filename: &mut String,
with_tz: bool,
) {
let mut calendar = ICalendar::new("2.0", "cal7tor"); let mut calendar = ICalendar::new("2.0", "cal7tor");
// Add Europe/Paris timezone // Add Europe/Paris timezone
let timezone_name = "Europe/Paris"; let timezone_name = "Europe/Paris";
calendar.add_timezone(ics::TimeZone::standard( if with_tz {
timezone_name, calendar.add_timezone(ics::TimeZone::standard(
Standard::new( timezone_name,
// Add a Z because it's UTC Standard::new(
dt_ical(chrono::Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()) + "Z", // Add a Z because it's UTC
"+0100", dt_ical(chrono::Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()) + "Z",
"+0200", "+0100",
), "+0200",
)); ),
));
}
// Create events which contains the information regarding the course // Create events which contains the information regarding the course
for course in courses { for course in courses {
@ -50,12 +56,16 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut Str
// Start time of the course // Start time of the course
let mut date_start = DtStart::new(dt_ical(course.dtstart.unwrap())); 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); event.push(date_start);
// End time of the course // End time of the course
let mut date_end = DtEnd::new(dt_ical(course.dtend.unwrap())); 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); event.push(date_end);
// Room location // Room location

View file

@ -38,6 +38,10 @@ struct Args {
/// If TD/TP start a week after courses /// If TD/TP start a week after courses
#[clap(short, long)] #[clap(short, long)]
week_skip: bool, week_skip: bool,
/// If the exported ICS file should not use the timezone
#[clap(short, long)]
no_tz: bool,
} }
#[tokio::main] #[tokio::main]
@ -80,7 +84,7 @@ async fn main() {
let mut filename = args.export.unwrap(); let mut filename = args.export.unwrap();
let builded_timetable = timetable::build(&timetable, &info); 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}"); println!("Fichier .ICS construit et exporté => {filename}");
} else { } else {