journeys: whenRepresents option

This commit is contained in:
Jannis R 2018-05-24 12:13:24 +02:00 committed by Jannis Redmann
parent 16c3f01118
commit deb88297a0
3 changed files with 22 additions and 1 deletions

View file

@ -41,6 +41,7 @@ With `opt`, you can override the default options, which look like this:
```js ```js
{ {
when: new Date(), when: new Date(),
whenRepresents: 'departure', // use 'arrival' for journeys arriving before `when`
earlierThan: null, // ref to get journeys earlier than the last query earlierThan: null, // ref to get journeys earlier than the last query
laterThan: null, // ref to get journeys later than the last query laterThan: null, // ref to get journeys later than the last query
results: 5, // how many journeys? results: 5, // how many journeys?

View file

@ -79,6 +79,7 @@ const createClient = (profile, request = _request) => {
results: 5, // how many journeys? results: 5, // how many journeys?
via: null, // let journeys pass this station? via: null, // let journeys pass this station?
passedStations: false, // return stations on the way? passedStations: false, // return stations on the way?
whenRepresents: 'departure', // use 'arrival' for journeys arriving before `when`
transfers: 5, // maximum of 5 transfers transfers: 5, // maximum of 5 transfers
transferTime: 0, // minimum time for a single transfer in minutes transferTime: 0, // minimum time for a single transfer in minutes
// todo: does this work with every endpoint? // 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) if (opt.via) opt.via = profile.formatLocation(profile, opt.via)
opt.when = opt.when || new Date() 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 = [ const filters = [
profile.formatProducts(opt.products || {}) profile.formatProducts(opt.products || {})
] ]
@ -122,10 +127,10 @@ const createClient = (profile, request = _request) => {
arrLocL: [to], arrLocL: [to],
jnyFltrL: filters, jnyFltrL: filters,
getTariff: !!opt.tickets, getTariff: !!opt.tickets,
outFrwd: opt.whenRepresents !== 'arrival',
// todo: what is req.gisFltrL? // todo: what is req.gisFltrL?
getPT: true, // todo: what is this? getPT: true, // todo: what is this?
outFrwd: true, // todo: what is this?
getIV: false, // todo: walk & bike as alternatives? getIV: false, // todo: walk & bike as alternatives?
getPolyline: !!opt.polylines getPolyline: !!opt.polylines
} }

View file

@ -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) { test('earlier/later journeys', co(function* (t) {
const model = yield client.journeys(spichernstr, bismarckstr, { const model = yield client.journeys(spichernstr, bismarckstr, {
results: 3, when results: 3, when