mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
fix dbnav time zone bug
This commit is contained in:
parent
a6e84be2df
commit
4b68385bf7
2 changed files with 36 additions and 0 deletions
|
@ -8,6 +8,7 @@ import {formatStopReq} from './stop-req.js';
|
||||||
import {formatNearbyReq} from './nearby-req.js';
|
import {formatNearbyReq} from './nearby-req.js';
|
||||||
import {formatStationBoardReq} from './station-board-req.js';
|
import {formatStationBoardReq} from './station-board-req.js';
|
||||||
import {parseStop} from './parse-stop.js';
|
import {parseStop} from './parse-stop.js';
|
||||||
|
import {parseJourney} from './parse-journey.js';
|
||||||
|
|
||||||
const profile = {
|
const profile = {
|
||||||
...baseProfile,
|
...baseProfile,
|
||||||
|
@ -24,6 +25,7 @@ const profile = {
|
||||||
formatStationBoardReq,
|
formatStationBoardReq,
|
||||||
formatLocationFilter,
|
formatLocationFilter,
|
||||||
|
|
||||||
|
parseJourney,
|
||||||
parseStop,
|
parseStop,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
34
p/dbnav/parse-journey.js
Normal file
34
p/dbnav/parse-journey.js
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import {parseJourney as parseJourneyDefault} from '../../parse/journey.js';
|
||||||
|
|
||||||
|
const parseJourney = (ctx, jj) => {
|
||||||
|
const legs = (jj.verbindung || jj).verbindungsAbschnitte;
|
||||||
|
if (legs.length > 0) {
|
||||||
|
legs[0] = preprocessJourneyLeg(legs[0]);
|
||||||
|
}
|
||||||
|
if (legs.length > 1) {
|
||||||
|
legs[legs.length - 1] = preprocessJourneyLeg(legs.at(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseJourneyDefault(ctx, jj);
|
||||||
|
};
|
||||||
|
|
||||||
|
const preprocessJourneyLeg = (pt) => { // fixes https://github.com/public-transport/db-vendo-client/issues/24
|
||||||
|
if (pt.typ === 'FUSSWEG' || pt.typ === 'TRANSFER') {
|
||||||
|
pt.ezAbgangsDatum = correctRealtimeTimeZone(pt.abgangsDatum, pt.ezAbgangsDatum);
|
||||||
|
pt.ezAnkunftsDatum = correctRealtimeTimeZone(pt.ankunftsDatum, pt.ezAnkunftsDatum);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pt;
|
||||||
|
};
|
||||||
|
|
||||||
|
const correctRealtimeTimeZone = (planned, realtime) => {
|
||||||
|
if (planned && realtime) {
|
||||||
|
const timeZoneOffsetRegex = /([+-]\d\d:\d\d|Z)$/;
|
||||||
|
const timeZoneOffsetPlanned = timeZoneOffsetRegex.exec(planned)[0];
|
||||||
|
return realtime.replace(timeZoneOffsetRegex, timeZoneOffsetPlanned);
|
||||||
|
}
|
||||||
|
|
||||||
|
return realtime;
|
||||||
|
};
|
||||||
|
|
||||||
|
export {parseJourney};
|
Loading…
Add table
Reference in a new issue