2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
add planned(Arrival|Departure|When), scheduled* -> planned*/prognosed* :boom:
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}
2019-08-23 18:51:03 +02:00
|
|
|
const parseWhen = require('./when')
|
2019-08-27 14:28:53 +02:00
|
|
|
const parsePlatform = require('./platform')
|
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)
|
|
|
|
const arrPl = profile.parsePlatform(ctx, st.aPlatfS, st.aPlatfR, st.aCncl)
|
|
|
|
const dep = profile.parseWhen(ctx, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl)
|
|
|
|
const depPl = profile.parsePlatform(ctx, st.dPlatfS, st.dPlatfR, st.dCncl)
|
|
|
|
|
|
|
|
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
|