diff options
author | Ruben Pollan | 2018-11-27 10:28:01 -0600 |
---|---|---|
committer | Ruben Pollan | 2018-11-27 10:28:01 -0600 |
commit | 6a14d38bceed38b3a7ccc51f81b6cd845548e6b8 (patch) | |
tree | cac9ece28cbb067e20f84d976cddd1e237b19127 /src | |
parent | ff727ea02ce5019d22f407ee872ead26479ffc2a (diff) |
Read and merge multiple icals
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 1 | ||||
-rw-r--r-- | src/main.rs | 31 |
2 files changed, 22 insertions, 10 deletions
@@ -11,3 +11,4 @@ mod errors; pub use calendar::Calendar; pub use date::Date; pub use chrono::Duration; +pub use event::Event; diff --git a/src/main.rs b/src/main.rs index 6d9544b..ce2284d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,19 +3,30 @@ extern crate almanac; use std::env; use std::io::BufReader; use std::fs::File; -use almanac::Duration; -use almanac::Date; + use almanac::Calendar; +use almanac::Date; +use almanac::Duration; +use almanac::Event; fn main() { - let args: Vec<_> = env::args().collect(); - let file = File::open(&args[1]).unwrap(); - let buf = BufReader::new(file); - let calendar = Calendar::parse(buf).unwrap(); + let first = Date::now(); + let last = first + Duration::days(7); - let now = Date::now(); - let events = calendar.get(&now, &(now + Duration::days(1))); - for e in events { - println!("{}", e); + let mut events: Vec<_> = env::args() + .skip(1) + .map(|arg| ics_calendar(&arg, &first, &last)) + .flatten() + .collect(); + events.sort(); + for event in events { + println!("{}", event); } } + +fn ics_calendar(file_path: &str, first: &Date, last: &Date) -> Vec<Event> { + let file = File::open(file_path).unwrap(); + let buf = BufReader::new(file); + let calendar = Calendar::parse(buf).unwrap(); + calendar.get(first, last) +} |