diff options
Diffstat (limited to '')
-rw-r--r-- | src/traits.rs | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/traits.rs b/src/traits.rs index b4b74e7..b5785be 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -9,19 +9,29 @@ pub trait IsStation { fn ds100(&self) -> Option<&str>; fn to_fancy_string(&self) -> String { - // travelynx literally sends this entire precise date in case of an - // unknown time instead of, like, a null + // travelynx used to send this entire precise date in case of an + // unknown time instead of null. I'm not sure it still does this + // (i have since seen it return null) but keeping this here just + // in case let epoch = "1970-01-01T00:00:00Z".parse::<DateTime<Local>>().unwrap(); + + let format_time = |time: &DateTime<Utc>| -> String { + if time.eq(&epoch) { + "??:??:?? ".to_owned() + } else { // chrono's API for timezones is expressive, but reads like c++ … + <DateTime<Local>>::from(*time).time().format("%T").to_string() + } + }; + format!( "{} {} – {} ({})", self .real_arrival() - .map(|t| if t.eq(&epoch) { - "unknown ".to_owned() - } else { // chrono's API for timezones is expressive, but reads like c++ … - <DateTime<Local>>::from(*t).time().format("%T").to_string() - }) - .unwrap_or("<format error>".to_string()) + .map(format_time) + .unwrap_or_else(|| + self.scheduled_arrival() + .map(format_time).unwrap_or_else(|| "??:??:??".to_string()) + ) .blue(), { let delay = match (self.real_arrival(), self.scheduled_arrival()) { |