db-vendo-client/parse/stopover.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
const parseWhen = require('./when')
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 dep = parseWhen(profile, date, st.dTimeS, st.dTimeR, st.dTZOffset, 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: st.aPlatfR || st.aPlatfS || null,
departure: dep.when,
plannedDeparture: dep.plannedWhen,
departureDelay: dep.delay,
departurePlatform: st.dPlatfR || st.dPlatfS || null
2017-11-11 22:35:41 +01:00
}
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen
if (st.aPlatfR && st.aPlatfS && st.aPlatfR !== st.aPlatfS) {
res.scheduledArrivalPlatform = st.aPlatfS
}
if (st.dPlatfR && st.dPlatfS && st.dPlatfR !== st.dPlatfS) {
res.scheduledDeparturePlatform = st.dPlatfS
}
// 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