From 49186ae2d1fa5782c4b6dfad32042b123fa36fd7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 7 Jun 2018 18:52:12 +0200 Subject: [PATCH] journey leg passed stations: parse & expose delays backporting 21c273c to master --- parse/departure.js | 2 ++ parse/journey-leg.js | 2 ++ parse/stopover.js | 20 +++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/parse/departure.js b/parse/departure.js index 158eb1ea..1a496bc7 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -30,6 +30,8 @@ const createParseDeparture = (profile, stations, lines, remarks) => { res.delay = Math.round((realtime - planned) / 1000) } else res.delay = null + // todo: DRY with parseStopover + // todo: DRY with parseJourneyLeg if (d.stbStop.aCncl || d.stbStop.dCncl) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 65032de2..20772d2e 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -23,6 +23,8 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) => arrival: arr.toISO() } + // todo: DRY with parseDeparture + // todo: DRY with parseStopover if (pt.dep.dTimeR && pt.dep.dTimeS) { const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR) const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) diff --git a/parse/stopover.js b/parse/stopover.js index d96a6498..52f69b17 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -5,16 +5,34 @@ const createParseStopover = (profile, stations, lines, remarks, date) => { const parseStopover = (st) => { const res = { - station: stations[parseInt(st.locX)] || null + station: stations[parseInt(st.locX)] || null, + arrival: null, + arrivalDelay: null, + departure: null, + departureDelay: null } + + // todo: DRY with parseDeparture + // todo: DRY with parseJourneyLeg if (st.aTimeR || st.aTimeS) { const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS) res.arrival = arr.toISO() } + if (st.aTimeR && st.aTimeS) { + const realtime = profile.parseDateTime(profile, date, st.aTimeR) + const planned = profile.parseDateTime(profile, date, st.aTimeS) + res.arrivalDelay = Math.round((realtime - planned) / 1000) + } + if (st.dTimeR || st.dTimeS) { const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS) res.departure = dep.toISO() } + if (st.dTimeR && st.dTimeS) { + const realtime = profile.parseDateTime(profile, date, st.dTimeR) + const planned = profile.parseDateTime(profile, date, st.dTimeS) + res.departureDelay = Math.round((realtime - planned) / 1000) + } // mark stations the train passes without stopping if(st.dInS === false && st.aOutS === false) res.passBy = true