diff options
author | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-12 16:32:05 +0100 |
---|---|---|
committer | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-12 16:33:39 +0100 |
commit | dbc6a2bb978d15eea8093f83c8a5826bbdee85f4 (patch) | |
tree | 99c035b813dd319505cd949d8dd3fefbf06a6eb3 /src/utils | |
parent | c61a8075a98c4674694f3ab25f15cca54f9958f8 (diff) |
implement parsing of khlines and conversion to instances
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/fileutil.rs | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/utils/fileutil.rs b/src/utils/fileutil.rs index 3484086..9b304e1 100644 --- a/src/utils/fileutil.rs +++ b/src/utils/fileutil.rs @@ -4,8 +4,8 @@ use std::path::{Path, PathBuf}; use std::{fs, io}; use std::fs::OpenOptions; -use utils::dateutil; use icalwrap::IcalVCalendar; +use khline::KhLine; pub fn file_iter(dir: &Path) -> impl Iterator<Item = PathBuf> { use walkdir::WalkDir; @@ -80,21 +80,11 @@ fn read_calendar_from_path(path: &Path) -> Result<IcalVCalendar, String> { } pub fn read_calendars_from_files(files: &mut Iterator<Item = String>) -> Result<Vec<IcalVCalendar>, String> { - files.map(|file| read_khaleesi_line(&file)).collect() -} - -pub fn read_khaleesi_line(kline: &str) -> Result<IcalVCalendar, String> { - let parts: Vec<&str> = kline.splitn(2, ' ').collect(); - if let Some(timestamp) = dateutil::datetime_from_timestamp(parts[0]) { - let path = Path::new(parts[1]); - let calendar = read_calendar_from_path(path)?; - let calendar = calendar.with_internal_timestamp(timestamp); - Ok(calendar) - } else { - let path = Path::new(parts[0]); - let calendar = read_calendar_from_path(path)?; - Ok(calendar) - } + files + .map(|line| line.parse::<KhLine>()) + .flatten() + .map(|khline| khline.to_cal()) + .collect() } #[cfg(test)] |