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 * test fix of dbnav time zone bug * exclude `test/parse/dbnav-journey.js` from spell check
34 lines
1 KiB
JavaScript
34 lines
1 KiB
JavaScript
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};
|