mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
parse departures
This commit is contained in:
parent
09866a9a08
commit
bc611ab7b9
1 changed files with 25 additions and 3 deletions
28
parse.js
28
parse.js
|
@ -4,13 +4,13 @@ const moment = require('moment-timezone')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const dateTime = (timezone) => (date, time) => {
|
const dateTime = (tz, date, time) => {
|
||||||
let offset = 0 // in days
|
let offset = 0 // in days
|
||||||
if (time.length > 6) {
|
if (time.length > 6) {
|
||||||
offset = +time.slice(0, -6)
|
offset = +time.slice(0, -6)
|
||||||
time = time.slice(-6)
|
time = time.slice(-6)
|
||||||
}
|
}
|
||||||
return moment.tz(date + 'T' + time, timezone)
|
return moment.tz(date + 'T' + time, tz)
|
||||||
.add(offset, 'days')
|
.add(offset, 'days')
|
||||||
.valueOf()
|
.valueOf()
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,29 @@ const remark = (r) => null // todo
|
||||||
|
|
||||||
|
|
||||||
const agency = (a) => a.name
|
const agency = (a) => a.name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// todo: what is d.jny.dirFlg?
|
||||||
|
// todo: d.stbStop.dProgType
|
||||||
|
// todo: what is d.stbStop.dTimeR?
|
||||||
|
// tz = timezone, s = stations, p = products, r = remarks
|
||||||
|
const departure = (tz, s, p, r) => (d) => {
|
||||||
|
const result = {
|
||||||
|
station: s[parseInt(d.stbStop.locX)]
|
||||||
|
, when: new Date(dateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS))
|
||||||
|
, direction: shorten(d.dirTxt) // todo: parse this
|
||||||
|
, product: p[parseInt(d.prodX)]
|
||||||
|
, remarks: d.remL ? d.remL.map((rm) => r[parseInt(rm.remX)]) : null
|
||||||
|
, trip: +d.jid.split('|')[1]
|
||||||
|
}
|
||||||
|
if (d.stbStop.dTimeR && d.stbStop.dTimeS) result.delay =
|
||||||
|
dateTime(tz, d.date, d.stbStop.dTimeR) - dateTime(tz, d.date, d.stbStop.dTimeS)
|
||||||
|
return result
|
||||||
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dateTime,
|
dateTime,
|
||||||
location, product, remark, agency
|
location, product, remark, agency,
|
||||||
|
departure
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue