2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-12-28 16:56:27 +01:00
|
|
|
const createParseJourneyLeg = require('./journey-leg')
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
const clone = obj => Object.assign({}, obj)
|
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
const createParseJourney = (profile, stations, lines, remarks) => {
|
2017-12-28 16:56:27 +01:00
|
|
|
const parseLeg = createParseJourneyLeg(profile, stations, lines, remarks)
|
2017-11-11 22:35:41 +01:00
|
|
|
|
|
|
|
// todo: c.sDays
|
|
|
|
// todo: c.dep.dProgType, c.arr.dProgType
|
|
|
|
// todo: c.conSubscr
|
|
|
|
// todo: c.trfRes x vbb-parse-ticket
|
2017-11-12 01:23:34 +01:00
|
|
|
const parseJourney = (j) => {
|
2017-12-28 16:56:27 +01:00
|
|
|
const legs = j.secL.map(leg => parseLeg(j, leg))
|
2017-12-07 20:21:14 +01:00
|
|
|
const res = {
|
2018-03-02 00:35:54 +01:00
|
|
|
type: 'journey',
|
2017-12-28 16:56:27 +01:00
|
|
|
legs,
|
|
|
|
origin: legs[0].origin,
|
|
|
|
destination: legs[legs.length - 1].destination,
|
|
|
|
departure: legs[0].departure,
|
|
|
|
arrival: legs[legs.length - 1].arrival
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2017-12-28 16:56:27 +01:00
|
|
|
if (legs.some(p => p.cancelled)) {
|
2017-12-07 20:21:14 +01:00
|
|
|
res.cancelled = true
|
2018-03-08 03:26:39 +01:00
|
|
|
Object.defineProperty(res, 'canceled', {value: true})
|
2017-12-07 20:21:14 +01:00
|
|
|
res.departure = res.arrival = null
|
2018-03-08 03:26:39 +01:00
|
|
|
|
|
|
|
const firstLeg = j.secL[0]
|
|
|
|
const dep = profile.parseDateTime(profile, j.date, firstLeg.dep.dTimeS)
|
|
|
|
res.formerScheduledDeparture = dep.toISO()
|
|
|
|
|
|
|
|
const lastLeg = j.secL[j.secL.length - 1]
|
|
|
|
const arr = profile.parseDateTime(profile, j.date, lastLeg.arr.aTimeS)
|
|
|
|
res.formerScheduledArrival = arr.toISO()
|
2017-12-07 20:21:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseJourney
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseJourney
|