diff options
Diffstat (limited to 'src/iceportal.rs')
-rw-r--r-- | src/iceportal.rs | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/iceportal.rs b/src/iceportal.rs index 1b36556..a81d5d3 100644 --- a/src/iceportal.rs +++ b/src/iceportal.rs @@ -1,7 +1,8 @@ +use chrono::NaiveDateTime; use serde::Deserialize; use serde_json::Value; -use crate::travelynx::TrainRef; +use crate::{travelynx::TrainRef, types::IsStation, serde::*}; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] @@ -24,9 +25,10 @@ struct Trip { #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")] -struct Stop { +pub struct Stop { info: StopInfo, - station: Station + station: Station, + timetable: Timetable } #[derive(Deserialize, Debug)] @@ -43,6 +45,33 @@ struct Station { name: String } +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +struct Timetable { + #[serde(deserialize_with = "option_naive_read_unixtime")] + scheduled_arrival_time: Option<NaiveDateTime>, + #[serde(deserialize_with = "option_naive_read_unixtime")] + actual_arrival_time: Option<NaiveDateTime> +} + +impl IsStation for Stop { + fn name (&self) -> &str { + &self.station.name + } + + fn scheduled_arrival (&self) -> Option<&chrono::NaiveDateTime> { + self.timetable.scheduled_arrival_time.as_ref() + } + + fn real_arrival (&self) -> Option<&chrono::NaiveDateTime> { + self.timetable.actual_arrival_time.as_ref() + } + + fn ds100 (&self) -> &str { + "??" + } +} + impl TripInfo { @@ -64,4 +93,8 @@ impl TripInfo { no: self.trip.vzn.clone() } } + + pub fn trip (&self) -> crate::types::Trip<'_,Stop> { + crate::types::Trip(&self.trip.stops) + } } |