mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
parse: default to null
This commit is contained in:
parent
fb43a4e43b
commit
73d083f418
4 changed files with 9 additions and 10 deletions
|
@ -15,10 +15,10 @@ const createParseDeparture = (timezone, stations, lines, remarks) => {
|
|||
const when = parseDateTime(timezone, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
||||
const res = {
|
||||
ref: d.jid,
|
||||
station: stations[parseInt(d.stbStop.locX)], // todo: default to null
|
||||
station: stations[parseInt(d.stbStop.locX)] || null,
|
||||
when: when.format(),
|
||||
direction: d.dirTxt,
|
||||
line: lines[parseInt(d.prodX)], // todo: default to null
|
||||
line: lines[parseInt(d.prodX)] || null,
|
||||
remarks: d.remL ? d.remL.map(findRemark) : [],
|
||||
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
||||
}
|
||||
|
|
|
@ -38,8 +38,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
|||
const dep = parseDateTime(tz, j.date, pt.dep.dTimeR || pt.dep.dTimeS)
|
||||
const arr = parseDateTime(tz, j.date, pt.arr.aTimeR || pt.arr.aTimeS)
|
||||
const res = {
|
||||
// todo: what about null?
|
||||
origin: clone(stations[parseInt(pt.dep.locX)]),
|
||||
origin: clone(stations[parseInt(pt.dep.locX)]) || null,
|
||||
destination: clone(stations[parseInt(pt.arr.locX)]),
|
||||
departure: dep.format(),
|
||||
arrival: arr.format()
|
||||
|
@ -55,7 +54,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
|||
res.mode = 'walking'
|
||||
} else if (pt.type === 'JNY') {
|
||||
res.id = pt.jny.jid
|
||||
res.line = lines[parseInt(pt.jny.prodX)] // todo: default null
|
||||
res.line = lines[parseInt(pt.jny.prodX)] || null
|
||||
res.direction = pt.jny.dirTxt // todo: parse this
|
||||
|
||||
if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS
|
||||
|
@ -71,7 +70,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
|||
|
||||
if (pt.jny.freq && pt.jny.freq.jnyL) {
|
||||
const parseAlternative = (a) => ({
|
||||
line: lines[parseInt(a.prodX)], // todo: default null
|
||||
line: lines[parseInt(a.prodX)] || null,
|
||||
when: parseDateTime(tz, j.date, a.stopL[0].dTimeS).format() // todo: realtime
|
||||
})
|
||||
res.alternatives = pt.jny.freq.jnyL
|
||||
|
|
|
@ -28,7 +28,7 @@ const createParseMovement = (tz, locations, lines, remarks) => {
|
|||
|
||||
const res = {
|
||||
direction: m.dirTxt,
|
||||
line: lines[m.prodX], // default to null
|
||||
line: lines[m.prodX] || null,
|
||||
coordinates: m.pos ? {
|
||||
latitude: m.pos.y / 1000000,
|
||||
longitude: m.pos.x / 1000000
|
||||
|
@ -40,8 +40,8 @@ const createParseMovement = (tz, locations, lines, remarks) => {
|
|||
if (m.ani && Array.isArray(m.ani.mSec)) {
|
||||
for (let i = 0; i < m.ani.mSec.length; i++) {
|
||||
res.frames.push({
|
||||
origin: locations[m.ani.fLocX[i]], // todo: default to null
|
||||
destination: locations[m.ani.tLocX[i]], // todo: default to null
|
||||
origin: locations[m.ani.fLocX[i]] || null,
|
||||
destination: locations[m.ani.tLocX[i]] || null,
|
||||
t: m.ani.mSec[i]
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const parseDateTime = require('./date-time')
|
|||
const createParseStopover = (tz, stations, lines, remarks, connection) => {
|
||||
const parseStopover = (st) => {
|
||||
const res = {
|
||||
station: stations[parseInt(st.locX)] // default to null
|
||||
station: stations[parseInt(st.locX)] || null
|
||||
}
|
||||
if (st.aTimeR || st.aTimeS) {
|
||||
const arr = parseDateTime(tz, connection.date, st.aTimeR || st.aTimeS)
|
||||
|
|
Loading…
Add table
Reference in a new issue