mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
when not cancelled: {when, delay} -> {when, plannedWhen, delay} {arrival, arrivalDelay} -> {arrival, plannedArrival, arrivalDelay} {departure, departureDelay} -> {departure, plannedDeparture, departureDelay} when cancelled: {when: null, delay: null, scheduledWhen} -> {when: null, plannedWhen, prognosedWhen, delay} {arrival: null, arrivalDelay: null, scheduledArrival, formerArrivalDelay} -> {arrival: null, plannedArrival, arrivalDelay, prognosedArrival} {departure: null, departureDelay: null, scheduledDeparture, formerDepartureDelay} -> {departure: null, plannedDeparture, departureDelay, prognosedDeparture}
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
'use strict'
|
|
|
|
const parseWhen = require('./when')
|
|
const findRemarks = require('./find-remarks')
|
|
|
|
const createParseStopover = (profile, opt, data, date) => {
|
|
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)
|
|
|
|
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
|
|
}
|
|
|
|
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})
|
|
}
|
|
|
|
if (opt.remarks && Array.isArray(st.msgL)) {
|
|
res.remarks = findRemarks(st.msgL).map(([remark]) => remark)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
return parseStopover
|
|
}
|
|
|
|
module.exports = createParseStopover
|