diff options
author | Ruben Pollan | 2018-12-10 16:25:59 +0100 |
---|---|---|
committer | Ruben Pollan | 2018-12-10 16:30:25 +0100 |
commit | bf08591d73c13bc94b66d557cb7ad6a9487f0503 (patch) | |
tree | 52fc68f4fc105003d68800e57515ba8ae90b999b | |
parent | d0bb1ac385d1e81c07317f3148c4e2e6ddae3cfd (diff) |
Print the missing unfinished events
-rw-r--r-- | src/main.rs | 50 |
1 files 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<Item = Event>) { 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) { |