parseStopover: cancelled arrival & departure 🐛

also clean up parseMovement and add DRY todos
This commit is contained in:
Jannis R 2018-03-17 17:14:47 +01:00
parent 287883eda9
commit bdad9c6ef6
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 29 additions and 23 deletions

View file

@ -22,14 +22,14 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
} }
// todo: res.trip from rawLine.prodCtx.num? // todo: res.trip from rawLine.prodCtx.num?
// todo: DRY with parseStopover
// todo: DRY with parseJourneyLeg
if (d.stbStop.dTimeR && d.stbStop.dTimeS) { if (d.stbStop.dTimeR && d.stbStop.dTimeS) {
const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR) const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR)
const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS) const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS)
res.delay = Math.round((realtime - planned) / 1000) res.delay = Math.round((realtime - planned) / 1000)
} else res.delay = null } 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) { if (d.stbStop.aCncl || d.stbStop.dCncl) {
res.cancelled = true res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true}) Object.defineProperty(res, 'canceled', {value: true})

View file

@ -71,21 +71,21 @@ const createParseJourneyLeg = (profile, stations, lines, remarks) => {
} }
} }
// todo: follow public-transport/friendly-public-transport-format#27 here // todo: DRY with parseDeparture
// see also derhuerst/vbb-rest#19 // todo: DRY with parseStopover
if (pt.arr.aCncl) { if (pt.arr.aCncl || pt.dep.dCncl) {
res.cancelled = true res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true}) Object.defineProperty(res, 'canceled', {value: true})
res.arrival = res.arrivalPlatform = res.arrivalDelay = null if (pt.arr.aCncl) {
const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) res.arrival = res.arrivalPlatform = res.arrivalDelay = null
res.formerScheduledArrival = arr.toISO() const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS)
} res.formerScheduledArrival = arr.toISO()
if (pt.dep.dCncl) { }
res.cancelled = true if (pt.dep.dCncl) {
Object.defineProperty(res, 'canceled', {value: true}) res.departure = res.departurePlatform = res.departureDelay = null
res.departure = res.departurePlatform = res.departureDelay = null const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS)
const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) res.formerScheduledDeparture = dep.toISO()
res.formerScheduledDeparture = dep.toISO() }
} }
return res return res

View file

@ -19,15 +19,21 @@ const createParseStopover = (profile, stations, lines, remarks, date) => {
// mark stations the train passes without stopping // mark stations the train passes without stopping
if(st.dInS === false && st.aOutS === false) res.passBy = true if(st.dInS === false && st.aOutS === false) res.passBy = true
// todo: follow public-transport/friendly-public-transport-format#27 here // todo: DRY with parseDeparture
// see also derhuerst/vbb-rest#19 // todo: DRY with parseJourneyLeg
if (st.aCncl) { if (st.aCncl || st.dCncl) {
res.cancelled = true res.cancelled = true
res.arrival = null Object.defineProperty(res, 'canceled', {value: true})
} if (st.aCncl) {
if (st.dCncl) { res.arrival = res.arrivalDelay = null
res.cancelled = true const arr = profile.parseDateTime(profile, d.date, st.aTimeS)
res.departure = null 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 return res