From bdad9c6ef6b05c77847b2a9dfbc9720b39ac319b Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sat, 17 Mar 2018 17:14:47 +0100 Subject: [PATCH] parseStopover: cancelled arrival & departure :bug: also clean up parseMovement and add DRY todos --- parse/departure.js | 4 ++-- parse/journey-leg.js | 26 +++++++++++++------------- parse/stopover.js | 22 ++++++++++++++-------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/parse/departure.js b/parse/departure.js index b074b426..3868c988 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -22,14 +22,14 @@ const createParseDeparture = (profile, stations, lines, remarks) => { } // todo: res.trip from rawLine.prodCtx.num? + // todo: DRY with parseStopover + // todo: DRY with parseJourneyLeg if (d.stbStop.dTimeR && d.stbStop.dTimeS) { const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR) const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS) res.delay = Math.round((realtime - planned) / 1000) } else res.delay = null - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 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 c226da83..30477270 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -71,21 +71,21 @@ const createParseJourneyLeg = (profile, stations, lines, remarks) => { } } - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 - if (pt.arr.aCncl) { + // todo: DRY with parseDeparture + // todo: DRY with parseStopover + if (pt.arr.aCncl || pt.dep.dCncl) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) - res.arrival = res.arrivalPlatform = res.arrivalDelay = null - const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) - res.formerScheduledArrival = arr.toISO() - } - if (pt.dep.dCncl) { - res.cancelled = true - Object.defineProperty(res, 'canceled', {value: true}) - res.departure = res.departurePlatform = res.departureDelay = null - const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) - res.formerScheduledDeparture = dep.toISO() + if (pt.arr.aCncl) { + res.arrival = res.arrivalPlatform = res.arrivalDelay = null + const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) + res.formerScheduledArrival = arr.toISO() + } + if (pt.dep.dCncl) { + res.departure = res.departurePlatform = res.departureDelay = null + const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) + res.formerScheduledDeparture = dep.toISO() + } } return res diff --git a/parse/stopover.js b/parse/stopover.js index 0140ff57..2a445bd6 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -19,15 +19,21 @@ const createParseStopover = (profile, stations, lines, remarks, date) => { // mark stations the train passes without stopping if(st.dInS === false && st.aOutS === false) res.passBy = true - // todo: follow public-transport/friendly-public-transport-format#27 here - // see also derhuerst/vbb-rest#19 - if (st.aCncl) { + // todo: DRY with parseDeparture + // todo: DRY with parseJourneyLeg + if (st.aCncl || st.dCncl) { res.cancelled = true - res.arrival = null - } - if (st.dCncl) { - res.cancelled = true - res.departure = null + Object.defineProperty(res, 'canceled', {value: true}) + if (st.aCncl) { + res.arrival = res.arrivalDelay = null + const arr = profile.parseDateTime(profile, d.date, st.aTimeS) + res.formerScheduledArrival = arr.toISO() + } + if (st.dCncl) { + res.departure = res.departureDelay = null + const arr = profile.parseDateTime(profile, d.date, st.dTimeS) + res.formerScheduledDeparture = arr.toISO() + } } return res