aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuben Pollan2018-12-10 02:56:54 +0100
committerRuben Pollan2018-12-10 02:56:54 +0100
commitbaeba8f78097fe13183c71a04355b78b0fdd0920 (patch)
tree02ccb4b6d8de5dd28d308ec3915beb5e0c232000 /src
parent3097964b7bc8a96df8c619e3006a745db870175e (diff)
Configurable period
Diffstat (limited to 'src')
-rw-r--r--src/main.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index d531687..013d744 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,10 +11,10 @@ use almanac::Date;
use almanac::Duration;
fn main() {
- let first = Date::now();
- let last = first + Duration::days(7);
+ let mut args = env::args().skip(1);
+ let (first, last) = period(&args.next().unwrap());
- let calendars: Vec<_> = env::args().skip(1).map(|arg| ics_calendar(&arg)).collect();
+ let calendars: Vec<_> = args.map(|arg| ics_calendar(&arg)).collect();
let events = calendars
.iter()
.map(|c| c.iter())
@@ -27,6 +27,18 @@ fn main() {
}
}
+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);