2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2019-08-23 16:21:44 +02:00
|
|
|
const findRemarks = require('./find-remarks')
|
2018-06-11 11:29:32 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseStopover = (ctx, st, date) => { // st = raw stopover
|
|
|
|
const {profile, opt} = ctx
|
|
|
|
|
|
|
|
const arr = profile.parseWhen(ctx, date, st.aTimeS, st.aTimeR, st.aTZOffset, st.aCncl)
|
2020-08-01 16:51:42 +02:00
|
|
|
const arrPl = profile.parsePlatform(ctx, st.aPlatfS || (st.aPltfS && st.aPltfS.txt) || null, st.aPlatfR || (st.aPltfR && st.aPltfR.txt) || null, st.aCncl)
|
2019-10-20 00:19:11 +02:00
|
|
|
const dep = profile.parseWhen(ctx, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl)
|
2020-08-01 16:51:42 +02:00
|
|
|
const depPl = profile.parsePlatform(ctx, st.dPlatfS || (st.dPltfS && st.dPltfS.txt) || null, st.dPlatfR || (st.dPltfR && st.dPltfR.txt) || null, st.dCncl)
|
2019-10-20 00:19:11 +02:00
|
|
|
|
|
|
|
const res = {
|
|
|
|
stop: st.location || null,
|
|
|
|
arrival: arr.when,
|
|
|
|
plannedArrival: arr.plannedWhen,
|
|
|
|
arrivalDelay: arr.delay,
|
|
|
|
arrivalPlatform: arrPl.platform,
|
|
|
|
plannedArrivalPlatform: arrPl.plannedPlatform,
|
|
|
|
departure: dep.when,
|
|
|
|
plannedDeparture: dep.plannedWhen,
|
|
|
|
departureDelay: dep.delay,
|
|
|
|
departurePlatform: depPl.platform,
|
|
|
|
plannedDeparturePlatform: depPl.plannedPlatform
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
|
|
|
|
if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform
|
|
|
|
if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen
|
|
|
|
if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform
|
|
|
|
|
|
|
|
// mark stations the train passes without stopping
|
|
|
|
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
|
|
|
|
|
|
|
if (st.aCncl || st.dCncl) {
|
|
|
|
res.cancelled = true
|
|
|
|
Object.defineProperty(res, 'canceled', {value: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opt.remarks && Array.isArray(st.msgL)) {
|
|
|
|
res.remarks = findRemarks(st.msgL).map(([remark]) => remark)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
module.exports = parseStopover
|