db-vendo-client/parse/stopover.js

58 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
const findRemark = require('./find-remark')
// todo: arrivalDelay, departureDelay or only delay ?
// todo: arrivalPlatform, departurePlatform
const createParseStopover = (profile, stations, lines, hints, warnings, date) => {
2017-11-11 22:35:41 +01:00
const parseStopover = (st) => {
const res = {
station: stations[parseInt(st.locX)] || null,
arrival: null,
departure: null
2017-11-11 22:35:41 +01:00
}
if (st.aTimeR || st.aTimeS) {
const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS)
2017-12-11 19:40:46 +01:00
res.arrival = arr.toISO()
2017-11-11 22:35:41 +01:00
}
if (st.dTimeR || st.dTimeS) {
const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS)
2017-12-11 19:40:46 +01:00
res.departure = dep.toISO()
2017-11-11 22:35:41 +01:00
}
// mark stations the train passes without stopping
if(st.dInS === false && st.aOutS === false) res.passBy = true
// todo: DRY with parseDeparture
// todo: DRY with parseJourneyLeg
if (st.aCncl || st.dCncl) {
res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true})
if (st.aCncl) {
res.arrival = res.arrivalDelay = null
2018-04-05 14:23:14 +02:00
const arr = profile.parseDateTime(profile, date, st.aTimeS)
res.formerScheduledArrival = arr.toISO()
}
if (st.dCncl) {
res.departure = res.departureDelay = null
2018-04-05 14:23:14 +02:00
const arr = profile.parseDateTime(profile, date, st.dTimeS)
res.formerScheduledDeparture = arr.toISO()
}
}
if (Array.isArray(st.msgL)) {
res.remarks = []
for (let ref of st.msgL) {
const remark = findRemark(hints, warnings, ref)
if (remark) res.remarks.push(remark)
}
}
2017-11-11 22:35:41 +01:00
return res
}
return parseStopover
}
module.exports = createParseStopover