mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
journeys: whenRepresents option
This commit is contained in:
parent
16c3f01118
commit
deb88297a0
3 changed files with 22 additions and 1 deletions
|
@ -41,6 +41,7 @@ With `opt`, you can override the default options, which look like this:
|
|||
```js
|
||||
{
|
||||
when: new Date(),
|
||||
whenRepresents: 'departure', // use 'arrival' for journeys arriving before `when`
|
||||
earlierThan: null, // ref to get journeys earlier than the last query
|
||||
laterThan: null, // ref to get journeys later than the last query
|
||||
results: 5, // how many journeys?
|
||||
|
|
7
index.js
7
index.js
|
@ -79,6 +79,7 @@ const createClient = (profile, request = _request) => {
|
|||
results: 5, // how many journeys?
|
||||
via: null, // let journeys pass this station?
|
||||
passedStations: false, // return stations on the way?
|
||||
whenRepresents: 'departure', // use 'arrival' for journeys arriving before `when`
|
||||
transfers: 5, // maximum of 5 transfers
|
||||
transferTime: 0, // minimum time for a single transfer in minutes
|
||||
// todo: does this work with every endpoint?
|
||||
|
@ -90,6 +91,10 @@ const createClient = (profile, request = _request) => {
|
|||
if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
|
||||
opt.when = opt.when || new Date()
|
||||
|
||||
if (opt.whenRepresents !== 'departure' && opt.whenRepresents !== 'arrival') {
|
||||
throw new Error('opt.whenRepresents must be `departure` or `arrival`.')
|
||||
}
|
||||
|
||||
const filters = [
|
||||
profile.formatProducts(opt.products || {})
|
||||
]
|
||||
|
@ -122,10 +127,10 @@ const createClient = (profile, request = _request) => {
|
|||
arrLocL: [to],
|
||||
jnyFltrL: filters,
|
||||
getTariff: !!opt.tickets,
|
||||
outFrwd: opt.whenRepresents !== 'arrival',
|
||||
|
||||
// todo: what is req.gisFltrL?
|
||||
getPT: true, // todo: what is this?
|
||||
outFrwd: true, // todo: what is this?
|
||||
getIV: false, // todo: walk & bike as alternatives?
|
||||
getPolyline: !!opt.polylines
|
||||
}
|
||||
|
|
15
test/vbb.js
15
test/vbb.js
|
@ -168,6 +168,21 @@ test('journeys – fails with no product', co(function* (t) {
|
|||
}
|
||||
}))
|
||||
|
||||
test('journeys – with arrival time', co(function* (t) {
|
||||
const journeys = yield client.journeys(spichernstr, bismarckstr, {
|
||||
results: 3,
|
||||
when,
|
||||
whenRepresents: 'arrival'
|
||||
})
|
||||
|
||||
for (let j of journeys) {
|
||||
const arr = +new Date(j.arrival)
|
||||
t.ok(arr <= when)
|
||||
}
|
||||
|
||||
t.end()
|
||||
}))
|
||||
|
||||
test('earlier/later journeys', co(function* (t) {
|
||||
const model = yield client.journeys(spichernstr, bismarckstr, {
|
||||
results: 3, when
|
||||
|
|
Loading…
Add table
Reference in a new issue