db-vendo-client/parse/stopover.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
const parseWhen = require('./when')
const parsePlatform = require('./platform')
const findRemarks = require('./find-remarks')
2018-06-26 12:52:33 +02:00
const createParseStopover = (profile, opt, data, date) => {
2017-11-11 22:35:41 +01:00
const parseStopover = (st) => {
const arr = parseWhen(profile, date, st.aTimeS, st.aTimeR, st.aTZOffset, st.aCncl)
const arrPl = parsePlatform(profile, st.aPlatfS, st.aPlatfR, st.aCncl)
const dep = parseWhen(profile, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl)
const depPl = parsePlatform(profile, st.dPlatfS, st.dPlatfR, st.dCncl)
2017-11-11 22:35:41 +01: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
}
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})
}
2018-06-28 13:45:56 +02:00
if (opt.remarks && Array.isArray(st.msgL)) {
res.remarks = findRemarks(st.msgL).map(([remark]) => remark)
}
2017-11-11 22:35:41 +01:00
return res
}
return parseStopover
}
module.exports = createParseStopover