mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
fix date of next-day DEVI leg in an overnight journey 🐛
follow-up of a2870f6a follow-up of 6e6285c7 fixes #301
This commit is contained in:
parent
c85f083db5
commit
26c56f8dc6
2 changed files with 30 additions and 3 deletions
|
@ -1,7 +1,13 @@
|
|||
import {DateTime, FixedOffsetZone, IANAZone} from 'luxon'
|
||||
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
|
||||
|
||||
const parseDateTime = ({profile}, date, time, tzOffset = null, timestamp = false) => {
|
||||
const parseDaysOffset = (_, time) => {
|
||||
return time.length > 6 ? parseInt(time.slice(0, -6)) : 0
|
||||
}
|
||||
|
||||
const parseDateTime = (ctx, date, time, tzOffset = null, timestamp = false) => {
|
||||
const {profile} = ctx
|
||||
|
||||
const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)]
|
||||
if (!pDate[0] || !pDate[1] || !pDate[2]) {
|
||||
throw new Error('invalid date format: ' + date)
|
||||
|
@ -12,7 +18,7 @@ const parseDateTime = ({profile}, date, time, tzOffset = null, timestamp = false
|
|||
throw new Error('invalid time format: ' + time)
|
||||
}
|
||||
|
||||
const daysOffset = time.length > 6 ? parseInt(time.slice(0, -6)) : 0
|
||||
const daysOffset = parseDaysOffset(ctx, time)
|
||||
|
||||
let timezone
|
||||
if (tzOffset !== null) {
|
||||
|
|
|
@ -15,7 +15,28 @@ import {findRemarks} from './find-remarks.js'
|
|||
const parseJourney = (ctx, j) => { // j = raw jouney
|
||||
const {profile, opt} = ctx
|
||||
|
||||
const legs = j.secL.map(l => profile.parseJourneyLeg(ctx, l, j.date))
|
||||
const legs = []
|
||||
for (const l of j.secL) {
|
||||
let date = j.date
|
||||
// Next-day DEVI legs in an overnight journey lack both
|
||||
// - the "01" prefix in {dep.d,arr.a}Time{S,R} and
|
||||
// - the jny.trainStartDate field.
|
||||
// However, we can use the previous leg's effective date.
|
||||
const prevLeg = legs[legs.length - 1] || null
|
||||
if (l.type === 'DEVI' && prevLeg?.arrival) {
|
||||
// todo: parse effective date from jny.ctxRecon/gis.ctx instead?
|
||||
// todo: prefer plannedArrival?
|
||||
date = [
|
||||
prevLeg.arrival.slice(0, 4), // year
|
||||
prevLeg.arrival.slice(5, 7), // month
|
||||
prevLeg.arrival.slice(8, 10), // day
|
||||
].join('')
|
||||
}
|
||||
|
||||
const leg = profile.parseJourneyLeg(ctx, l, date)
|
||||
legs.push(leg)
|
||||
}
|
||||
|
||||
const res = {
|
||||
type: 'journey',
|
||||
legs,
|
||||
|
|
Loading…
Add table
Reference in a new issue