mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
parse scheduled days of a journey
This commit is contained in:
parent
0e8ed62f23
commit
02e0e513ef
4 changed files with 43 additions and 4 deletions
|
@ -69,7 +69,8 @@ With `opt`, you can override the default options, which look like this:
|
|||
remarks: true, // parse & expose hints & warnings?
|
||||
// Consider walking to nearby stations at the beginning of a journey?
|
||||
startWithWalking: true,
|
||||
language: 'en' // language to get results in
|
||||
language: 'en', // language to get results in
|
||||
scheduledDays: false // parse which days each journey is valid on
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -300,3 +301,18 @@ departure of first (later) journey 2017-12-17T19:19:00.000+01:00
|
|||
```
|
||||
|
||||
If you pass `polylines: true`, each journey leg will have a `polyline` field. Refer to [the section in the `trip()` docs](trip.md#polyline-option) for details.
|
||||
|
||||
If you pass `scheduledDays: true`, each journey will have a `scheduledDays` field looking like this:
|
||||
|
||||
```js
|
||||
{
|
||||
'2018-01-01': true,
|
||||
'2018-01-02': false,
|
||||
// …
|
||||
'2018-10-12': true,
|
||||
'2018-10-13': true,
|
||||
// …
|
||||
'2019-01-02': false,
|
||||
'2019-01-03': false
|
||||
}
|
||||
```
|
||||
|
|
3
index.js
3
index.js
|
@ -140,7 +140,8 @@ const createClient = (profile, userAgent, request = _request) => {
|
|||
polylines: false, // return leg shapes?
|
||||
remarks: true, // parse & expose hints & warnings?
|
||||
// Consider walking to nearby stations at the beginning of a journey?
|
||||
startWithWalking: true
|
||||
startWithWalking: true,
|
||||
scheduledDays: false
|
||||
}, opt)
|
||||
if (opt.via) opt.via = profile.formatLocation(profile, opt.via, 'opt.via')
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
|||
const {locations, lines, hints, warnings, polylines} = data
|
||||
// todo: pt.status, pt.isPartCncl
|
||||
// todo: pt.isRchbl, pt.chRatingRT, pt.chgDurR, pt.minChg
|
||||
// todo: pt.sDays
|
||||
// todo: pt.dep.dProgType, pt.arr.dProgType
|
||||
// todo: what is pt.jny.dirFlg?
|
||||
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
'use strict'
|
||||
|
||||
const {DateTime} = require('luxon')
|
||||
const findRemark = require('./find-remark')
|
||||
|
||||
const parseScheduledDays = (sDaysB, profile) => {
|
||||
sDaysB = Buffer.from(sDaysB, 'hex')
|
||||
const res = Object.create(null)
|
||||
|
||||
let d = DateTime.fromObject({
|
||||
zone: profile.timezone, locale: profile.locale,
|
||||
year: new Date().getFullYear(),
|
||||
month: 1, day: 1,
|
||||
hour: 0, minute: 0, second: 0, millisecond: 0
|
||||
})
|
||||
for (let b = 0; b < sDaysB.length; b++) {
|
||||
for (let i = 0; i < 8; i++) {
|
||||
res[d.toISODate()] = (sDaysB[b] & Math.pow(2, 7 - i)) > 0
|
||||
d = d.plus({days: 1})
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
const createParseJourney = (profile, opt, data) => {
|
||||
const parseLeg = profile.parseJourneyLeg(profile, opt, data)
|
||||
const {hints, warnings} = data
|
||||
|
||||
// todo: c.sDays
|
||||
// todo: c.conSubscr
|
||||
// todo: c.trfRes x vbb-parse-ticket
|
||||
// todo: c.sotRating, c.isSotCon, c.sotCtxt
|
||||
|
@ -32,6 +51,10 @@ const createParseJourney = (profile, opt, data) => {
|
|||
}
|
||||
}
|
||||
|
||||
if (opt.scheduledDays) {
|
||||
res.scheduledDays = parseScheduledDays(j.sDays.sDaysB, profile)
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue