aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.rs43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/main.rs b/src/main.rs
index a4728a1..43cdc5b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,13 +19,6 @@ use chrono::{DateTime, TimeZone, Utc};
use std::fs::File;
use std::io::BufReader;
-#[derive(Default)]
-struct Event {
- start: Option<DateTime<Utc>>,
- end: Option<DateTime<Utc>>,
- summary: String,
-}
-
fn parse_datetime(datetime: Option<String>) -> Option<DateTime<Utc>> {
if let Some(mut dt) = datetime {
if dt.is_empty() {
@@ -42,6 +35,26 @@ fn parse_datetime(datetime: Option<String>) -> Option<DateTime<Utc>> {
}
}
+fn print_event(event: &ical::parser::ical::component::IcalEvent) {
+ let mut start: Option<DateTime<Utc>> = None;
+ let mut end: Option<DateTime<Utc>> = None;
+ let mut summary = String::new();
+
+ for ref p in &event.properties {
+ match p.name.as_ref() {
+ "DTSTART" => start = parse_datetime(p.value.clone()),
+ "DTEND" => end = parse_datetime(p.value.clone()),
+ "SUMMARY" => summary = p.value.clone().unwrap_or("".to_string()),
+ _ => (),
+ }
+ }
+
+ println!("---> {} - {}: {}",
+ start.unwrap_or(Utc::now()),
+ end.unwrap_or(Utc::now()),
+ summary);
+}
+
fn main() {
let buf = BufReader::new(File::open("test.ics").unwrap());
let calendars: Vec<_> = ical::IcalParser::new(buf)
@@ -51,21 +64,7 @@ fn main() {
for c in calendars {
for e in c.events {
- let mut ev = Event::default();
-
- for p in e.properties {
- match p.name.as_ref() {
- "DTSTART" => ev.start = parse_datetime(p.value),
- "DTEND" => ev.end = parse_datetime(p.value),
- "SUMMARY" => ev.summary = p.value.unwrap_or("".to_string()),
- _ => (),
- }
- }
-
- println!("---> {} - {}: {}",
- ev.start.unwrap_or(Utc::now()),
- ev.end.unwrap_or(Utc::now()),
- ev.summary);
+ print_event(&e);
}
}
}