-
Notifications
You must be signed in to change notification settings - Fork 0
/
match-stopover.js
31 lines (27 loc) · 940 Bytes
/
match-stopover.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
const debug = require('debug')('find-hafas-data-in-another-hafas:match-stopover')
const {plannedDepartureOf, plannedArrivalOf} = require('./lib/helpers')
const createMatchStopover = (matchStopOrStation) => {
const matchStopover = (stopoverA) => {
const matchStopA = matchStopOrStation(stopoverA.stop)
const depA = plannedDepartureOf(stopoverA)
const arrA = plannedArrivalOf(stopoverA)
const matchStopover = (stopoverB) => {
if (!matchStopA(stopoverB.stop)) {
debug('matching stops failed', stopoverA.stop, stopoverB.stop)
return false
}
const depB = plannedDepartureOf(stopoverB)
const arrB = plannedArrivalOf(stopoverB)
if (
(depB !== null && depB === depA) ||
(arrB !== null && arrB === arrA)
) return true
debug('matching date/time failed', {arrA, depA, arrB, depB})
return false
}
return matchStopover
}
return matchStopover
}
module.exports = createMatchStopover