mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-11-04 10:06:32 +02:00 
			
		
		
		
	bugfixes 🐛, rename dep.ref -> dep.journeyId
This commit is contained in:
		
							parent
							
								
									275c9e54d7
								
							
						
					
					
						commit
						3ea4fd3e40
					
				
					 4 changed files with 15 additions and 9 deletions
				
			
		| 
						 | 
					@ -2,14 +2,14 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const moment = require('moment-timezone')
 | 
					const moment = require('moment-timezone')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const parseDateTime = (profile, date, time) => {
 | 
					const parseDateTime = (timezone, date, time) => {
 | 
				
			||||||
	let offset = 0 // in days
 | 
						let offset = 0 // in days
 | 
				
			||||||
	if (time.length > 6) {
 | 
						if (time.length > 6) {
 | 
				
			||||||
		offset = +time.slice(0, -6)
 | 
							offset = +time.slice(0, -6)
 | 
				
			||||||
		time = time.slice(-6)
 | 
							time = time.slice(-6)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return moment.tz(date + 'T' + time, profile.timezone)
 | 
						return moment.tz(date + 'T' + time, timezone)
 | 
				
			||||||
	.add(offset, 'days')
 | 
						.add(offset, 'days')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,10 +14,10 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
 | 
				
			||||||
	const parseDeparture = (d) => {
 | 
						const parseDeparture = (d) => {
 | 
				
			||||||
		const when = profile.parseDateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
 | 
							const when = profile.parseDateTime(tz, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
 | 
				
			||||||
		const res = {
 | 
							const res = {
 | 
				
			||||||
			ref: d.jid,
 | 
								journeyId: d.jid,
 | 
				
			||||||
			station: stations[parseInt(d.stbStop.locX)] || null,
 | 
								station: stations[parseInt(d.stbStop.locX)] || null,
 | 
				
			||||||
			when: when.format(),
 | 
								when: when.format(),
 | 
				
			||||||
			direction: d.dirTxt,
 | 
								direction: profile.parseStationName(d.dirTxt),
 | 
				
			||||||
			line: lines[parseInt(d.prodX)] || null,
 | 
								line: lines[parseInt(d.prodX)] || null,
 | 
				
			||||||
			remarks: d.remL ? d.remL.map(findRemark) : [],
 | 
								remarks: d.remL ? d.remL.map(findRemark) : [],
 | 
				
			||||||
			trip: +d.jid.split('|')[1] // todo: this seems brittle
 | 
								trip: +d.jid.split('|')[1] // todo: this seems brittle
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,7 +16,7 @@ const {
 | 
				
			||||||
	assertValidLocation,
 | 
						assertValidLocation,
 | 
				
			||||||
	assertValidLine,
 | 
						assertValidLine,
 | 
				
			||||||
	assertValidStopover,
 | 
						assertValidStopover,
 | 
				
			||||||
	when, isValidWhen
 | 
						when, isValidWhen // todo: timezone
 | 
				
			||||||
} = require('./util.js')
 | 
					} = require('./util.js')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const assertValidStationProducts = (t, p) => {
 | 
					const assertValidStationProducts = (t, p) => {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										14
									
								
								test/vbb.js
									
										
									
									
									
								
							
							
						
						
									
										14
									
								
								test/vbb.js
									
										
									
									
									
								
							| 
						 | 
					@ -6,21 +6,27 @@ const stations = require('vbb-stations-autocomplete')
 | 
				
			||||||
const tapePromise = require('tape-promise').default
 | 
					const tapePromise = require('tape-promise').default
 | 
				
			||||||
const tape = require('tape')
 | 
					const tape = require('tape')
 | 
				
			||||||
const co = require('co')
 | 
					const co = require('co')
 | 
				
			||||||
 | 
					const shorten = require('vbb-short-station-name')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const createClient = require('..')
 | 
					const createClient = require('..')
 | 
				
			||||||
const vbbProfile = require('../p/vbb')
 | 
					const vbbProfile = require('../p/vbb')
 | 
				
			||||||
const modes = require('../p/vbb/modes')
 | 
					const modes = require('../p/vbb/modes')
 | 
				
			||||||
const {
 | 
					const {
 | 
				
			||||||
	assertValidStation, assertValidFrameStation,
 | 
						assertValidStation: _assertValidStation,
 | 
				
			||||||
	assertValidPoi,
 | 
						assertValidPoi,
 | 
				
			||||||
	assertValidAddress,
 | 
						assertValidAddress,
 | 
				
			||||||
	assertValidLocation,
 | 
						assertValidLocation,
 | 
				
			||||||
	assertValidLine: _assertValidLine,
 | 
						assertValidLine: _assertValidLine,
 | 
				
			||||||
	assertValidStopover,
 | 
						assertValidStopover,
 | 
				
			||||||
	hour, when,
 | 
						hour, when,
 | 
				
			||||||
	assertValidWhen
 | 
						assertValidWhen // todo: timezone
 | 
				
			||||||
} = require('./util')
 | 
					} = require('./util')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const assertValidStation = (t, s, coordsOptional = false) => {
 | 
				
			||||||
 | 
						_assertValidStation(t, s, coordsOptional)
 | 
				
			||||||
 | 
						t.equal(s.name, shorten(s.name))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const assertValidStationProducts = (t, p) => {
 | 
					const assertValidStationProducts = (t, p) => {
 | 
				
			||||||
	t.ok(p)
 | 
						t.ok(p)
 | 
				
			||||||
	t.equal(typeof p.suburban, 'boolean')
 | 
						t.equal(typeof p.suburban, 'boolean')
 | 
				
			||||||
| 
						 | 
					@ -233,8 +239,8 @@ test('departures', co.wrap(function* (t) {
 | 
				
			||||||
	t.ok(Array.isArray(deps))
 | 
						t.ok(Array.isArray(deps))
 | 
				
			||||||
	t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
 | 
						t.deepEqual(deps, deps.sort((a, b) => t.when > b.when))
 | 
				
			||||||
	for (let dep of deps) {
 | 
						for (let dep of deps) {
 | 
				
			||||||
		t.equal(typeof dep.ref, 'string')
 | 
							t.equal(typeof dep.journeyId, 'string')
 | 
				
			||||||
		t.ok(dep.ref)
 | 
							t.ok(dep.journeyId)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		t.equal(dep.station.name, 'U Spichernstr.')
 | 
							t.equal(dep.station.name, 'U Spichernstr.')
 | 
				
			||||||
		assertValidStation(t, dep.station)
 | 
							assertValidStation(t, dep.station)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue