diff --git a/lib/BasicCSA.js b/lib/BasicCSA.js index db22d7f..8cefb81 100644 --- a/lib/BasicCSA.js +++ b/lib/BasicCSA.js @@ -19,7 +19,7 @@ var ResultStream = function (query) { //TODO: , footpathsTo) { this._earliestArrivalTimes = {}; // Priority queue of pending earliest arrival times this._pending = new PriorityQueue({ comparator: function(connectionA, connectionB) { - return connectionB.arrivalTime.getTime() - connectionA.arrivalTime.getTime(); + return connectionA.arrivalTime - connectionB.arrivalTime; }}); //check the fields of the query object and assign them to the object. Validate them against possible errors @@ -76,6 +76,7 @@ ResultStream.prototype._transform = function (connection, encoding, done) { // When a connection is found whose departure time exceeds the target stop's earliest arrival time, we have found a result if (!this._hasEmitted && this._earliestArrivalTimes[this._arrivalStop] && connection.departureTime > this._earliestArrivalTimes[this._arrivalStop].arrivalTime) { this.emit("result", this._reconstructRoute()); + this._hasEmitted = true; } if (this._earliestArrivalTimes[departureStop] && this._earliestArrivalTimes[departureStop].arrivalTime <= connection.departureTime) { @@ -124,6 +125,7 @@ ResultStream.prototype._flush = function (done) { // If there was no connection with departure time exceeding earliest arrival time if (!this._hasEmitted && this._earliestArrivalTimes[this._arrivalStop]) { this.emit("result", this._reconstructRoute()); + this._hasEmitted = true; } done(); }; diff --git a/package.json b/package.json index 1ba70a3..49b391f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "csa", - "version": "0.0.9", + "version": "0.0.10", "description": "Route Planner on top of data published using Connections", "main": "lib/csa.js", "keywords": [