34 lines
1.2 KiB
Nim
34 lines
1.2 KiB
Nim
import ../types
|
|
import ./date
|
|
import options
|
|
import json
|
|
|
|
proc parseStopoverPart(common: CommonData, mode: string, h: HafasStopParams): StopoverPart =
|
|
|
|
if (mode != "arrival"):
|
|
result.plannedPlatform = h.dPlatfS
|
|
result.prognosedPlatform = h.dPlatfR
|
|
result.plannedTime = parseDate(common, h.dTimeS, h.dTZOffset)
|
|
result.prognosedTime = parseDate(common, h.dTimeR, h.dTZOffset)
|
|
else:
|
|
result.plannedPlatform = h.aPlatfS
|
|
result.prognosedPlatform = h.aPlatfR
|
|
result.plannedTime = parseDate(common, h.aTimeS, h.aTZOffset)
|
|
result.prognosedTime = parseDate(common, h.aTimeR, h.aTZOffset)
|
|
|
|
proc mkParseStopover*(common: CommonData): proc =
|
|
proc parseStopover(s: JsonNode): Stopover =
|
|
let typeStr = s{"type"}.getStr()
|
|
if typeStr != "N":
|
|
echo pretty(s)
|
|
raise newException(CatchableError, "Unimplemented hafas stopover type: " & typeStr)
|
|
|
|
let h = s.to(HafasStopParams)
|
|
result.stop = common.points[s{"locX"}.getInt()].stop.get
|
|
result.cancelled = h.aCncl.get(false) or h.dCncl.get(false)
|
|
result.arrival = common.parseStopoverPart("arrival", h)
|
|
result.departure = common.parseStopoverPart("departure", h)
|
|
|
|
return parseStopover
|
|
|