Skip to content

Commit b863a9d

Browse files
committed
rest.exe: bugixes 🐛
1 parent 6aa80d9 commit b863a9d

File tree

6 files changed

+23
-12
lines changed

6 files changed

+23
-12
lines changed

parse-rest/arrival-or-departure.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const createParseArrOrDep = (type) => {
3131
}
3232

3333
if (opt.remarks && Array.isArray(d.notes)) {
34-
res.hints = d.notes.map(h => profile.parseHint(profile, h, data))
34+
res.hints = d.notes.map(h => profile.parseHint(ctx, h))
3535
}
3636

3737
return res

parse-rest/journey-leg.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const parseIsoDuration = require('parse-iso-duration')
4+
const sortBy = require('lodash/sortBy')
45

56
const parseJourneyLeg = (ctx, l) => { // l = leg
67
const {profile, opt} = ctx
@@ -14,14 +15,14 @@ const parseJourneyLeg = (ctx, l) => { // l = leg
1415
}
1516

1617
// todo: does `dest.rtAlighting` actually if the arrival is cancelled?
17-
const arr = profile.parseWhen(ctx, dest.date, dest.rtDate, dest.time, dest.rtTime, dest.rtTz, !dest.rtAlighting)
18+
const arr = profile.parseWhen(ctx, dest.date, dest.rtDate, dest.time, dest.rtTime, dest.rtTz, dest.rtAlighting === false)
1819
res.arrival = arr.when
1920
res.plannedArrival = arr.plannedWhen
2021
res.arrivalDelay = arr.delay
2122
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
2223

2324
// todo: does `orig.rtBoarding` actually if the departure is cancelled?
24-
const dep = profile.parseWhen(ctx, orig.date, orig.rtDate, orig.time, orig.rtTime, orig.tz, !orig.rtBoarding)
25+
const dep = profile.parseWhen(ctx, orig.date, orig.rtDate, orig.time, orig.rtTime, orig.tz, orig.rtBoarding === false)
2526
res.departure = dep.when
2627
res.plannedDeparture = dep.plannedWhen
2728
res.departureDelay = dep.delay
@@ -62,7 +63,8 @@ const parseJourneyLeg = (ctx, l) => { // l = leg
6263
res.direction = l.direction && profile.parseStationName(ctx, l.direction) || null
6364

6465
if (opt.stopovers && l.stops) {
65-
res.stopovers = l.stops.map(st => profile.parseStopover(ctx, st))
66+
res.stopovers = sortBy(l.stops, 'routeIdx')
67+
.map(st => profile.parseStopover(ctx, st))
6668
}
6769
}
6870

parse-rest/location.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,28 @@ const {parse} = require('qs')
44

55
const leadingZeros = /^0+/
66

7+
const parseNr = nr => parseFloat(nr.slice(0, 2) + '.' + nr.slice(2))
8+
79
const parseLocation = (ctx, l) => {
810
const {profile, opt} = ctx
911

1012
const id = parse(l.id, {delimiter: '@'})
11-
const latitude = 'number' === typeof l.lat ? l.lat : (id.Y ? id.Y / 100000 : null)
12-
const longitude = 'number' === typeof l.long ? l.long : (id.X ? id.X / 100000 : null)
13+
const latitude = 'number' === typeof l.lat ?
14+
l.lat :
15+
(id.Y ? parseNr(id.Y) : null)
16+
const longitude = 'number' === typeof l.lon ?
17+
l.lon :
18+
(id.X ? parseNr(id.X) : null)
1319

1420
const res = {
1521
type: 'location',
1622
id: (l.extId || id.L || id.b || '').replace(leadingZeros, '') || null,
1723
latitude, longitude
1824
}
1925

20-
if (l.type === 'S' || l.type === 'ST') {
26+
// todo: l.notes https://github.com/public-transport/hafas-client/issues/130
27+
28+
if (l.type === 'S' || l.type === 'ST' || id.A === '1') {
2129
const stop = {
2230
type: 'stop',
2331
id: res.id,

parse-rest/stopover.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
const parseStopover = (ctx, st) => {
44
const {profile} = ctx
55

6-
const arr = profile.parseWhen(ctx, st.arrDate, st.rtArrDate, st.arrTime, st.rtArrTime, st.arrTz, !st.rtAlighting)
6+
const arr = profile.parseWhen(ctx, st.arrDate, st.rtArrDate, st.arrTime, st.rtArrTime, st.arrTz, st.rtAlighting === false)
77
// todo: is there a `st.rtArrTrack`?
8-
const arrPl = profile.parsePlatform(ctx, st.arrTrack, null, !st.rtAlighting)
9-
const dep = profile.parseWhen(ctx, st.depDate, st.rtDepDate, st.depTime, st.rtDepTime, st.depTz, !st.rtBoarding)
8+
const arrPl = profile.parsePlatform(ctx, st.arrTrack, null, st.rtAlighting === false)
9+
const dep = profile.parseWhen(ctx, st.depDate, st.rtDepDate, st.depTime, st.rtDepTime, st.depTz, st.rtBoarding === false)
1010
// todo: is there a `st.rtDepTrack`?
11-
const depPl = profile.parsePlatform(ctx, st.depTrack, null, !st.rtBoarding)
11+
const depPl = profile.parsePlatform(ctx, st.depTrack, null, st.rtBoarding === false)
1212

1313
const res = {
1414
stop: profile.parseLocation(ctx, st) || null,

parse-rest/when.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const _parseWhen = require('../parse/when')
55

66
const parseWhen = (ctx, date, rtDate, time, rtTime, tzOffset, cncl = false) => {
77
// todo: compute `rtTime` offset using `rtDate`
8+
date = rtDate || date
89
if (date) date = date.replace(/-/g, '')
910
if (time) time = time.replace(/:/g, '')
1011
if (rtTime) rtTime = rtTime.replace(/:/g, '')

rest-exe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const createRestClient = (profile, token, userAgent) => {
228228
query.date = profile.formatDate({profile, opt}, when)
229229
query.time = profile.formatTime({profile, opt}, when)
230230

231-
return await request(method, query)
231+
return await request(method, opt, query)
232232
}
233233

234234
const departures = async (stop, opt = {}) => {

0 commit comments

Comments
 (0)