blob: 013d744c875877ed58b53c8fbaf2c7819e30048f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
extern crate almanac;
extern crate itertools;
use std::env;
use std::io::BufReader;
use std::fs::File;
use itertools::Itertools;
use almanac::Calendar;
use almanac::Date;
use almanac::Duration;
fn main() {
let mut args = env::args().skip(1);
let (first, last) = period(&args.next().unwrap());
let calendars: Vec<_> = args.map(|arg| ics_calendar(&arg)).collect();
let events = calendars
.iter()
.map(|c| c.iter())
.kmerge()
.skip_while(|e| e.end_date() < first)
.take_while(|e| e.start <= last);
for event in events {
println!("{}", 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()
}
|