aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-12-09 16:01:34 +0100
committerJoris2022-12-09 16:01:34 +0100
commit241089e3a1427c2968b296cc6c4112e45b78c278 (patch)
treed086991e2d90b46486783288ced5c1f5da80860f
parent4cc4d624f8a33db77e32e85f3ff2a7e61d5577ce (diff)
Format time as HH:MM
-rw-r--r--src/model/time.rs8
1 files changed, 2 insertions, 6 deletions
diff --git a/src/model/time.rs b/src/model/time.rs
index 10cf6d3..b29b74d 100644
--- a/src/model/time.rs
+++ b/src/model/time.rs
@@ -1,15 +1,11 @@
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())
- }
+ format!("{}:{:0>2}", t.hour(), t.minute())
}
pub fn parse(t: &str) -> Option<NaiveTime> {
- match t.split('h').collect::<Vec<&str>>()[..] {
+ match t.split(':').collect::<Vec<&str>>()[..] {
[hours, minutes] => {
if minutes.trim().is_empty() {
NaiveTime::from_hms_opt(hours.parse().ok()?, 0, 0)