From bf08591d73c13bc94b66d557cb7ad6a9487f0503 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Mon, 10 Dec 2018 16:25:59 +0100 Subject: Print the missing unfinished events --- src/main.rs | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 707b814..03eab2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,31 @@ fn main() { .kmerge() .skip_while(|e| e.end_date() < first) .take_while(|e| e.start <= last); + print_events(events) +} +fn period(arg: &str) -> (Date, Date) { + let days = match arg { + "day" => 1, + "week" => 7, + "month" => 30, + _ => panic!("Invalid time frame, try: day, week or month"), + }; + let first = Date::now(); + let last = first + Duration::days(days); + (first, last) +} + +fn ics_calendar(file_path: &str) -> Calendar { + let file = File::open(file_path).unwrap(); + let buf = BufReader::new(file); + Calendar::parse(buf).unwrap() +} + +fn print_events(events: impl Iterator) { let mut day = Date::new(); let mut unfinish = vec![]; + for event in events { if !day.same_day(&event.start) { if !unfinish.is_empty() { @@ -45,29 +67,23 @@ fn main() { print_day(day); } } + print_event(&event); if event.end_date() > event.start + Duration::days(1) { unfinish.push(event); } } -} - -fn period(arg: &str) -> (Date, Date) { - let days = match arg { - "day" => 1, - "week" => 7, - "month" => 30, - _ => panic!("Invalid time frame, try: day, week or month"), - }; - let first = Date::now(); - let last = first + Duration::days(days); - (first, last) -} -fn ics_calendar(file_path: &str) -> Calendar { - let file = File::open(file_path).unwrap(); - let buf = BufReader::new(file); - Calendar::parse(buf).unwrap() + while !unfinish.is_empty() { + day = day + Duration::days(1); + print_day(day); + for (i, event) in unfinish.clone().iter().enumerate() { + print_event(event); + if event.end_date() <= day + Duration::days(1) { + unfinish.remove(i); + } + } + } } fn print_day(date: Date) { -- cgit v1.2.3