Skip to content

Commit

Permalink
Strip date of milliseconds to fix 4:07 error (#301)
Browse files Browse the repository at this point in the history
* Strip date of milliseconds to fix 4:07 error

* Refactor
  • Loading branch information
alanna-zhou authored Aug 28, 2020
1 parent c4fa980 commit adffe7d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- /usr/src/app/node_modules

ghopper:
image: cornellappdev/transit-ghopper:v1.2.1
image: cornellappdev/transit-ghopper:v1.2.6
ports:
- "8988:8988"

Expand All @@ -28,7 +28,7 @@ services:
- "8987:8987"

live-tracking:
image: cornellappdev/transit-python:v1.2.2
image: cornellappdev/transit-python:v1.2.6
env_file: python.envrc
ports:
- "5000:5000"
2 changes: 1 addition & 1 deletion docker-compose/ghopper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update
RUN apt-get -y install maven wget

RUN git clone --single-branch -b 0.13 https://github.com/graphhopper/graphhopper.git
RUN wget https://s3.amazonaws.com/tcat-gtfs/tcat-ny-us.zip
COPY tcat-ny-us.zip /usr/src/app/tcat-ny-us.zip

WORKDIR /usr/src/app/graphhopper
RUN ./graphhopper.sh build
Expand Down
27 changes: 24 additions & 3 deletions src/utils/ParseRouteUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,26 @@ function parseWalkingRoute(
}
}

/**
* Ensure that the route times are in this format: "2020-08-27T23:11:58Z".
* Sometimes, we will get dates in the format of "2020-08-27T23:11:58.741+0000"
* and if this is the case, strip the milliseconds off. Otherwise, return the
* date we were given.
* @param date
* @returns formatted date string
*/
function formatDate(date: string): string {
if (date) {
const dateBeforeMs = date.split('.')[0];
if (date === dateBeforeMs) {
// date already does not have milliseconds
return date;
}
return `${dateBeforeMs}Z`;
}
return date;
}

/**
* Transform route object from graphhopper into one readable by the client, an array of
* five routes. Includes delay calculations, asynchronous.
Expand Down Expand Up @@ -469,7 +489,8 @@ function parseRoutes(

// string 2018-02-21T17:27:00Z
let { departureTime } = legs[0];
let arriveTime = legs[numberOfLegs - 1].arrivalTime;
departureTime = formatDate(departureTime);
let arriveTime = formatDate(legs[numberOfLegs - 1].arrivalTime);

// Readjust the walking start and end times by accounting for the buffer
// times that were initially passed into Graphhopper to get routes
Expand Down Expand Up @@ -497,8 +518,8 @@ function parseRoutes(

const directions = await Promise.all(legs.map(async (currLeg, j, legsArray) => {
let { type } = currLeg;
let startTime = currLeg.departureTime;
let endTime = currLeg.arrivalTime;
let startTime = formatDate(currLeg.departureTime);
let endTime = formatDate(currLeg.arrivalTime);

if (busRoute.transfers === -1) {
startTime = departureTime;
Expand Down

0 comments on commit adffe7d

Please sign in to comment.