VBB: support 7-digit stations

This commit is contained in:
Jannis R 2017-12-16 03:20:11 +01:00
parent b0157c75d5
commit 595c745830
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 11 additions and 6 deletions

View file

@ -128,10 +128,16 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
return parseDepartureRenameRingbahn return parseDepartureRenameRingbahn
} }
const isIBNR = /^\d{9,}$/ const validIBNR = /^\d+$/
const formatStation = (id) => { const formatStation = (id) => {
if (!isIBNR.test(id)) throw new Error('station ID must be an IBNR.') if ('string' !== typeof id) throw new Error('station ID must be a string.')
id = to9Digit(id) const l = id.length
if ((l !== 7 && l !== 9 && l !== 12) || !validIBNR.test(id)) {
throw new Error('station ID must be a valid IBNR.')
}
// The VBB has some 7-digit stations. We don't convert them to 12 digits,
// because it only recognizes in the 7-digit format. see derhuerst/vbb-hafas#22
if (l !== 7) id = to9Digit(id)
return _formatStation(id) return _formatStation(id)
} }

View file

@ -260,10 +260,9 @@ test('departures', co.wrap(function* (t) {
t.end() t.end()
})) }))
// todo test('departures at 7-digit station', co.wrap(function* (t) {
test.skip('departures at 7-digit station', co.wrap(function* (t) {
const eisenach = '8010097' // see derhuerst/vbb-hafas#22 const eisenach = '8010097' // see derhuerst/vbb-hafas#22
yield client.departures(eisenach, {when}) await client.departures(eisenach, {when})
t.pass('did not fail') t.pass('did not fail')
t.end() t.end()