aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs50
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) {