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: 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})

View file

@ -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

View file

@ -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