use chrono::{DateTime, Local, Utc}; use colored::Colorize; use core::cmp::PartialEq; pub trait IsStation { fn name(&self) -> &str; fn scheduled_arrival(&self) -> Option<&DateTime>; fn real_arrival(&self) -> Option<&DateTime>; 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 let epoch = "1970-01-01T00:00:00Z".parse::>().unwrap(); 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++ … >::from(*t).time().format("%T").to_string() }) .unwrap_or("".to_string()) .blue(), { let delay = match (self.real_arrival(), self.scheduled_arrival()) { (Some(a), Some(s)) => (a.time() - s.time()).num_minutes(), _ => 0 }; let text = format!("({:+})", delay); if delay > 0 { text.red() } else { text.green() } }, self.ds100().unwrap_or("??").red(), self.name() ) } }