mirror of
				https://github.com/public-transport/db-vendo-client.git
				synced 2025-10-31 08:06:33 +02:00 
			
		
		
		
	parseStopover: cancelled arrival & departure 🐛
also clean up parseMovement and add DRY todos
This commit is contained in:
		
							parent
							
								
									287883eda9
								
							
						
					
					
						commit
						bdad9c6ef6
					
				
					 3 changed files with 29 additions and 23 deletions
				
			
		|  | @ -22,14 +22,14 @@ const createParseDeparture = (profile, stations, lines, remarks) => { | |||
| 		} | ||||
| 		// todo: res.trip from rawLine.prodCtx.num?
 | ||||
| 
 | ||||
| 		// todo: DRY with parseStopover
 | ||||
| 		// todo: DRY with parseJourneyLeg
 | ||||
| 		if (d.stbStop.dTimeR && d.stbStop.dTimeS) { | ||||
| 			const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR) | ||||
| 			const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS) | ||||
| 			res.delay = Math.round((realtime - planned) / 1000) | ||||
| 		} else res.delay = null | ||||
| 
 | ||||
| 		// todo: follow public-transport/friendly-public-transport-format#27 here
 | ||||
| 		// see also derhuerst/vbb-rest#19
 | ||||
| 		if (d.stbStop.aCncl || d.stbStop.dCncl) { | ||||
| 			res.cancelled = true | ||||
| 			Object.defineProperty(res, 'canceled', {value: true}) | ||||
|  |  | |||
|  | @ -71,21 +71,21 @@ const createParseJourneyLeg = (profile, stations, lines, remarks) => { | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		// todo: follow public-transport/friendly-public-transport-format#27 here
 | ||||
| 		// see also derhuerst/vbb-rest#19
 | ||||
| 		if (pt.arr.aCncl) { | ||||
| 		// todo: DRY with parseDeparture
 | ||||
| 		// todo: DRY with parseStopover
 | ||||
| 		if (pt.arr.aCncl || pt.dep.dCncl) { | ||||
| 			res.cancelled = true | ||||
| 			Object.defineProperty(res, 'canceled', {value: true}) | ||||
| 			res.arrival = res.arrivalPlatform = res.arrivalDelay = null | ||||
| 			const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) | ||||
| 			res.formerScheduledArrival = arr.toISO() | ||||
| 		} | ||||
| 		if (pt.dep.dCncl) { | ||||
| 			res.cancelled = true | ||||
| 			Object.defineProperty(res, 'canceled', {value: true}) | ||||
| 			res.departure = res.departurePlatform = res.departureDelay = null | ||||
| 			const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) | ||||
| 			res.formerScheduledDeparture = dep.toISO() | ||||
| 			if (pt.arr.aCncl) { | ||||
| 				res.arrival = res.arrivalPlatform = res.arrivalDelay = null | ||||
| 				const arr = profile.parseDateTime(profile, j.date, pt.arr.aTimeS) | ||||
| 				res.formerScheduledArrival = arr.toISO() | ||||
| 			} | ||||
| 			if (pt.dep.dCncl) { | ||||
| 				res.departure = res.departurePlatform = res.departureDelay = null | ||||
| 				const dep = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) | ||||
| 				res.formerScheduledDeparture = dep.toISO() | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return res | ||||
|  |  | |||
|  | @ -19,15 +19,21 @@ const createParseStopover = (profile, stations, lines, remarks, date) => { | |||
| 		// mark stations the train passes without stopping
 | ||||
| 		if(st.dInS === false && st.aOutS === false) res.passBy = true | ||||
| 
 | ||||
| 		// todo: follow public-transport/friendly-public-transport-format#27 here
 | ||||
| 		// see also derhuerst/vbb-rest#19
 | ||||
| 		if (st.aCncl) { | ||||
| 		// todo: DRY with parseDeparture
 | ||||
| 		// todo: DRY with parseJourneyLeg
 | ||||
| 		if (st.aCncl || st.dCncl) { | ||||
| 			res.cancelled = true | ||||
| 			res.arrival = null | ||||
| 		} | ||||
| 		if (st.dCncl) { | ||||
| 			res.cancelled = true | ||||
| 			res.departure = null | ||||
| 			Object.defineProperty(res, 'canceled', {value: true}) | ||||
| 			if (st.aCncl) { | ||||
| 				res.arrival = res.arrivalDelay = null | ||||
| 				const arr = profile.parseDateTime(profile, d.date, st.aTimeS) | ||||
| 				res.formerScheduledArrival = arr.toISO() | ||||
| 			} | ||||
| 			if (st.dCncl) { | ||||
| 				res.departure = res.departureDelay = null | ||||
| 				const arr = profile.parseDateTime(profile, d.date, st.dTimeS) | ||||
| 				res.formerScheduledDeparture = arr.toISO() | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return res | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue