2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const parseDateTime = require('./date-time')
|
|
|
|
|
|
|
|
// todos from derhuerst/hafas-client#2
|
|
|
|
// - stdStop.dCncl
|
|
|
|
// - stdStop.dPlatfS, stdStop.dPlatfR
|
|
|
|
// todo: what is d.jny.dirFlg?
|
|
|
|
// todo: d.stbStop.dProgType
|
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
const createParseDeparture = (timezone, stations, lines, remarks) => {
|
|
|
|
const findRemark = rm => remarks[parseInt(rm.remX)] || null
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
const parseDeparture = (d) => {
|
2017-11-11 23:56:09 +01:00
|
|
|
const when = parseDateTime(timezone, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
|
|
|
const res = {
|
|
|
|
ref: d.jid,
|
2017-11-12 00:36:13 +01:00
|
|
|
station: stations[parseInt(d.stbStop.locX)] || null,
|
2017-11-11 23:56:09 +01:00
|
|
|
when: when.format(),
|
|
|
|
direction: d.dirTxt,
|
2017-11-12 00:36:13 +01:00
|
|
|
line: lines[parseInt(d.prodX)] || null,
|
2017-11-11 23:56:09 +01:00
|
|
|
remarks: d.remL ? d.remL.map(findRemark) : [],
|
|
|
|
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d.stbStop.dTimeR && d.stbStop.dTimeS) {
|
2017-11-11 23:56:09 +01:00
|
|
|
const realtime = parseDateTime(timezone, d.date, d.stbStop.dTimeR)
|
|
|
|
const planned = parseDateTime(timezone, d.date, d.stbStop.dTimeS)
|
|
|
|
res.delay = Math.round((realtime - planned) / 1000)
|
|
|
|
} else res.delay = null
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseDeparture
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseDeparture
|