diff --git a/docs/radar.md b/docs/radar.md index c719bec1..4db46136 100644 --- a/docs/radar.md +++ b/docs/radar.md @@ -76,7 +76,9 @@ The response may look like this: } }, arrival: null, - departure: '2017-12-17T19:16:00.000+01:00' + arrivalDelay: null, + departure: '2017-12-17T19:16:00.000+01:00', + departureDelay: null } /* … */ ], frames: [ { origin: { @@ -123,11 +125,15 @@ The response may look like this: nextStops: [ { station: { /* S+U Alexanderplatz/Dircksenstr. */ }, arrival: null, - departure: '2017-12-17T19:52:00.000+01:00' + arrivalDelay: null, + departure: '2017-12-17T19:52:00.000+01:00', + departureDelay: null }, { station: { /* Memhardstr. */ }, arrival: '2017-12-17T19:54:00.000+01:00', - departure: '2017-12-17T19:54:00.000+01:00' + arrivalDelay: null, + departure: '2017-12-17T19:54:00.000+01:00', + departureDelay: null }, /* … */ ], frames: [ { origin: { /* S+U Alexanderplatz/Dircksenstr. */ }, diff --git a/parse/movement.js b/parse/movement.js index bf2378ef..e03a3821 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -17,11 +17,23 @@ const createParseMovement = (profile, locations, lines, remarks) => { ? profile.parseDateTime(profile, m.date, s.aTimeR || s.aTimeS) : null - return { + const res = { station: locations[s.locX], departure: dep ? dep.toISO() : null, arrival: arr ? arr.toISO() : null } + + if (m.dTimeR && m.dTimeS) { + const plannedDep = profile.parseDateTime(profile, m.date, s.dTimeS) + res.departureDelay = Math.round((dep - plannedDep) / 1000) + } else res.departureDelay = null + + if (m.aTimeR && m.aTimeS) { + const plannedArr = profile.parseDateTime(profile, m.date, s.aTimeS) + res.arrivalDelay = Math.round((arr - plannedArr) / 1000) + } else res.arrivalDelay = null + + return res } const res = { diff --git a/test/util.js b/test/util.js index 90c3f69d..6a374bac 100644 --- a/test/util.js +++ b/test/util.js @@ -81,6 +81,12 @@ const isValidDateTime = (w) => { const assertValidStopover = (t, s, coordsOptional = false) => { if ('arrival' in s) t.ok(isValidDateTime(s.arrival)) if ('departure' in s) t.ok(isValidDateTime(s.departure)) + if (s.arrivalDelay !== null && s.arrivalDelay !== undefined) { + t.equal(typeof s.arrivalDelay, 'number') + } + if (s.departureDelay !== null && s.departureDelay !== undefined) { + t.equal(typeof s.departureDelay, 'number') + } if (!('arrival' in s) && !('departure' in s)) { t.fail('stopover doesn\'t contain arrival or departure') }