mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
bugfixes 🐛, rename dep.ref -> dep.journeyId
This commit is contained in:
parent
275c9e54d7
commit
3ea4fd3e40
4 changed files with 15 additions and 9 deletions
|
@ -2,14 +2,14 @@
|
|||
|
||||
const moment = require('moment-timezone')
|
||||
|
||||
const parseDateTime = (profile, date, time) => {
|
||||
const parseDateTime = (timezone, date, time) => {
|
||||
let offset = 0 // in days
|
||||
if (time.length > 6) {
|
||||
offset = +time.slice(0, -6)
|
||||
time = time.slice(-6)
|
||||
}
|
||||
|
||||
return moment.tz(date + 'T' + time, profile.timezone)
|
||||
return moment.tz(date + 'T' + time, timezone)
|
||||
.add(offset, 'days')
|
||||
}
|
||||
|
||||
|
|
|
@ -14,10 +14,10 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
|
|||
const parseDeparture = (d) => {
|
||||
const when = profile.parseDateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
||||
const res = {
|
||||
ref: d.jid,
|
||||
journeyId: d.jid,
|
||||
station: stations[parseInt(d.stbStop.locX)] || null,
|
||||
when: when.format(),
|
||||
direction: d.dirTxt,
|
||||
direction: profile.parseStationName(d.dirTxt),
|
||||
line: lines[parseInt(d.prodX)] || null,
|
||||
remarks: d.remL ? d.remL.map(findRemark) : [],
|
||||
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
||||
|
|
|
@ -16,7 +16,7 @@ const {
|
|||
assertValidLocation,
|
||||
assertValidLine,
|
||||
assertValidStopover,
|
||||
when, isValidWhen
|
||||
when, isValidWhen // todo: timezone
|
||||
} = require('./util.js')
|
||||
|
||||
const assertValidStationProducts = (t, p) => {
|
||||
|
|
14
test/vbb.js
14
test/vbb.js
|
@ -6,21 +6,27 @@ const stations = require('vbb-stations-autocomplete')
|
|||
const tapePromise = require('tape-promise').default
|
||||
const tape = require('tape')
|
||||
const co = require('co')
|
||||
const shorten = require('vbb-short-station-name')
|
||||
|
||||
const createClient = require('..')
|
||||
const vbbProfile = require('../p/vbb')
|
||||
const modes = require('../p/vbb/modes')
|
||||
const {
|
||||
assertValidStation, assertValidFrameStation,
|
||||
assertValidStation: _assertValidStation,
|
||||
assertValidPoi,
|
||||
assertValidAddress,
|
||||
assertValidLocation,
|
||||
assertValidLine: _assertValidLine,
|
||||
assertValidStopover,
|
||||
hour, when,
|
||||
assertValidWhen
|
||||
assertValidWhen // todo: timezone
|
||||
} = require('./util')
|
||||
|
||||
const assertValidStation = (t, s, coordsOptional = false) => {
|
||||
_assertValidStation(t, s, coordsOptional)
|
||||
t.equal(s.name, shorten(s.name))
|
||||
}
|
||||
|
||||
const assertValidStationProducts = (t, p) => {
|
||||
t.ok(p)
|
||||
t.equal(typeof p.suburban, 'boolean')
|
||||
|
@ -233,8 +239,8 @@ test('departures', co.wrap(function* (t) {
|
|||
t.ok(Array.isArray(deps))
|
||||
t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
|
||||
for (let dep of deps) {
|
||||
t.equal(typeof dep.ref, 'string')
|
||||
t.ok(dep.ref)
|
||||
t.equal(typeof dep.journeyId, 'string')
|
||||
t.ok(dep.journeyId)
|
||||
|
||||
t.equal(dep.station.name, 'U Spichernstr.')
|
||||
assertValidStation(t, dep.station)
|
||||
|
|
Loading…
Add table
Reference in a new issue