diff options
author | Joris | 2022-03-19 22:03:58 +0100 |
---|---|---|
committer | Joris | 2022-03-19 22:03:58 +0100 |
commit | 35cc74578e969bae4812afd2ff041eba3746142d (patch) | |
tree | c0ef18d3c81554f0e70c91fcb1006d587470365c /src/model/time.rs | |
parent | 199624dc03ead28ddc7454147457512d9568c593 (diff) |
Allow to repeat an event until a specific date
Also provide a shortcut to modify a repetead event from a specific
occurence. This set the end repetition date under the hood and create a
new repeated event.
Diffstat (limited to 'src/model/time.rs')
-rw-r--r-- | src/model/time.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/model/time.rs b/src/model/time.rs new file mode 100644 index 0000000..10cf6d3 --- /dev/null +++ b/src/model/time.rs @@ -0,0 +1,22 @@ +use chrono::{NaiveTime, Timelike}; + +pub fn pprint(t: NaiveTime) -> String { + if t.minute() == 0 { + format!("{}h", t.hour()) + } else { + format!("{}h{}", t.hour(), t.minute()) + } +} + +pub fn parse(t: &str) -> Option<NaiveTime> { + match t.split('h').collect::<Vec<&str>>()[..] { + [hours, minutes] => { + if minutes.trim().is_empty() { + NaiveTime::from_hms_opt(hours.parse().ok()?, 0, 0) + } else { + NaiveTime::from_hms_opt(hours.parse().ok()?, minutes.parse().ok()?, 0) + } + } + _ => None, + } +} |