diff options
author | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-12 16:42:58 +0100 |
---|---|---|
committer | Vincent Breitmoser <look@my.amazin.horse> | 2019-01-12 17:00:27 +0100 |
commit | 1a212dae8d08b828a4d93621ddae0f023f85066e (patch) | |
tree | 542b37074b60957a42656f0d1613f7a8c474e569 /src/khline.rs | |
parent | 9b073905177c0c81dc61307eec09077ccbce8b0e (diff) |
khline: strip khaleesi dir from path (normalize)
Diffstat (limited to 'src/khline.rs')
-rw-r--r-- | src/khline.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/khline.rs b/src/khline.rs index 338153f..1db68c9 100644 --- a/src/khline.rs +++ b/src/khline.rs @@ -1,10 +1,11 @@ use std::fmt; use std::str::FromStr; -use std::path::PathBuf; +use std::path::{PathBuf,Path}; use chrono::prelude::*; use icalwrap::{IcalVCalendar,IcalVEvent}; use utils::{fileutil,dateutil}; +use defaults; pub struct KhLine { path: PathBuf, @@ -34,11 +35,17 @@ impl KhLine { pub fn to_event(&self) -> Result<IcalVEvent, String> { self.to_cal().map(|cal| cal.get_principal_event()) } + + fn get_normalized_path(&self) -> &Path { + self.path + .strip_prefix(defaults::get_caldir()) + .unwrap_or(&self.path) + } } impl fmt::Display for KhLine { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let path_string = self.path.to_string_lossy(); + let path_string = self.get_normalized_path().to_string_lossy(); match self.time { Some(time) => { let time_string = format!("{:010}", time.timestamp()); |