Skip to content

Commit

Permalink
try to fix derhuerst/vbb-rest#18 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Nov 15, 2017
1 parent 30a3910 commit f1f0047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/departures.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const departures = (station, opt) => {
dep.direction = shorten(dep.direction)
return dep
})
.sort((a, b) => a.when > b.when)
.sort((a, b) => new Date(a.when) - new Date(b.when))
: []
})
}
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,21 @@ test('departures at 7-digit station', (t) => {
.catch(t.ifError)
})

test('departures should be sorted', (t) => {
hafas.departures('900000230091', { // Portsdam Sternwarte
when,
duration: 120 // see derhuerst/vbb-rest#18
})
.then((deps) => {
const sorted = deps.sort((a, b) => {
return new Date(a.when) - new Date(b.when)
})
t.deepEqual(sorted, deps, 'deps are not sorted by when field')
t.end()
})
.catch(t.ifError)
})



test('nearby', (t) => {
Expand Down

0 comments on commit f1f0047

Please sign in to comment.