summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2022-11-28 07:54:10 +0100
committerstuebinm2022-11-28 07:54:10 +0100
commit436071f0ac974f8b018e6d41143907946a97dcf9 (patch)
treedd550611a7922def63a4bd956fa591a0064ae691
parent8e2213d802d74c5df3429b7e29be6b3b3fa0ba78 (diff)
handle unknown times at stations
(travelynx sends these as the literal epoch value, which led to really confusing results, printing exactly the time zone offset as arrival time)
Diffstat (limited to '')
-rw-r--r--src/traits.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/traits.rs b/src/traits.rs
index a24a689..091709a 100644
--- a/src/traits.rs
+++ b/src/traits.rs
@@ -1,5 +1,6 @@
use chrono::{DateTime, Local, Utc};
use colored::Colorize;
+use core::cmp::PartialEq;
pub trait IsStation {
fn name(&self) -> &str;
@@ -8,12 +9,19 @@ pub trait IsStation {
fn ds100(&self) -> &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
+ let epoch = "1970-01-01T00:00:00Z".parse::<DateTime<Local>>().unwrap();
format!(
"{} {} – {} ({})",
self
- .real_arrival() // chrono's API for timezones is expressive, but reads like c++ …
- .map(|t| <DateTime<Local>>::from(*t).time().to_string())
- .unwrap_or("??:??:??".to_string())
+ .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())
.blue(),
{
let delay = match (self.real_arrival(), self.scheduled_arrival()) {