forked from Anri/cal8tor
option to not use timezone
This commit is contained in:
parent
9d64fd65a4
commit
4015b3777f
2 changed files with 27 additions and 13 deletions
12
src/ics.rs
12
src/ics.rs
|
@ -9,11 +9,16 @@ use ics::{
|
|||
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");
|
||||
|
||||
// Add Europe/Paris timezone
|
||||
let timezone_name = "Europe/Paris";
|
||||
if with_tz {
|
||||
calendar.add_timezone(ics::TimeZone::standard(
|
||||
timezone_name,
|
||||
Standard::new(
|
||||
|
@ -23,6 +28,7 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut Str
|
|||
"+0200",
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
// Create events which contains the information regarding the course
|
||||
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
|
||||
let mut date_start = DtStart::new(dt_ical(course.dtstart.unwrap()));
|
||||
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()));
|
||||
if with_tz {
|
||||
date_end.add(TzIDParam::new(timezone_name));
|
||||
}
|
||||
event.push(date_end);
|
||||
|
||||
// Room location
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue