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,
|
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";
|
||||||
|
if with_tz {
|
||||||
calendar.add_timezone(ics::TimeZone::standard(
|
calendar.add_timezone(ics::TimeZone::standard(
|
||||||
timezone_name,
|
timezone_name,
|
||||||
Standard::new(
|
Standard::new(
|
||||||
|
@ -23,6 +28,7 @@ pub fn export(courses: Vec<crate::timetable::models::Course>, filename: &mut Str
|
||||||
"+0200",
|
"+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()));
|
||||||
|
if with_tz {
|
||||||
date_start.add(TzIDParam::new(timezone_name));
|
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()));
|
||||||
|
if with_tz {
|
||||||
date_end.add(TzIDParam::new(timezone_name));
|
date_end.add(TzIDParam::new(timezone_name));
|
||||||
|
}
|
||||||
event.push(date_end);
|
event.push(date_end);
|
||||||
|
|
||||||
// Room location
|
// Room location
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue