2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-18 21:11:35 +01:00
|
|
|
// todo: arrivalDelay, departureDelay or only delay ?
|
|
|
|
// todo: arrivalPlatform, departurePlatform
|
2018-06-07 16:00:28 +02:00
|
|
|
const createParseStopover = (profile, stations, lines, hints, date) => {
|
2017-11-11 22:35:41 +01:00
|
|
|
const parseStopover = (st) => {
|
|
|
|
const res = {
|
2018-03-29 02:45:15 +02:00
|
|
|
station: stations[parseInt(st.locX)] || null,
|
|
|
|
arrival: null,
|
|
|
|
departure: null
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
if (st.aTimeR || st.aTimeS) {
|
2018-03-17 16:41:57 +01:00
|
|
|
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) {
|
2018-03-17 16:41:57 +01:00
|
|
|
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
|
|
|
}
|
2017-12-18 21:11:35 +01:00
|
|
|
|
2017-12-29 09:00:18 +01:00
|
|
|
// mark stations the train passes without stopping
|
|
|
|
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
|
|
|
|
2018-03-17 17:14:47 +01:00
|
|
|
// todo: DRY with parseDeparture
|
|
|
|
// todo: DRY with parseJourneyLeg
|
|
|
|
if (st.aCncl || st.dCncl) {
|
2017-12-18 21:11:35 +01:00
|
|
|
res.cancelled = true
|
2018-03-17 17:14:47 +01:00
|
|
|
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)
|
2018-03-17 17:14:47 +01:00
|
|
|
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)
|
2018-03-17 17:14:47 +01:00
|
|
|
res.formerScheduledDeparture = arr.toISO()
|
|
|
|
}
|
2017-12-18 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseStopover
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseStopover
|