Skip to content

Commit adffe7d

Browse files
authored
Strip date of milliseconds to fix 4:07 error (#301)
* Strip date of milliseconds to fix 4:07 error * Refactor
1 parent c4fa980 commit adffe7d

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ services:
1313
- /usr/src/app/node_modules
1414

1515
ghopper:
16-
image: cornellappdev/transit-ghopper:v1.2.1
16+
image: cornellappdev/transit-ghopper:v1.2.6
1717
ports:
1818
- "8988:8988"
1919

@@ -28,7 +28,7 @@ services:
2828
- "8987:8987"
2929

3030
live-tracking:
31-
image: cornellappdev/transit-python:v1.2.2
31+
image: cornellappdev/transit-python:v1.2.6
3232
env_file: python.envrc
3333
ports:
3434
- "5000:5000"

docker-compose/ghopper/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN apt-get update
99
RUN apt-get -y install maven wget
1010

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

1414
WORKDIR /usr/src/app/graphhopper
1515
RUN ./graphhopper.sh build

src/utils/ParseRouteUtils.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,26 @@ function parseWalkingRoute(
429429
}
430430
}
431431

432+
/**
433+
* Ensure that the route times are in this format: "2020-08-27T23:11:58Z".
434+
* Sometimes, we will get dates in the format of "2020-08-27T23:11:58.741+0000"
435+
* and if this is the case, strip the milliseconds off. Otherwise, return the
436+
* date we were given.
437+
* @param date
438+
* @returns formatted date string
439+
*/
440+
function formatDate(date: string): string {
441+
if (date) {
442+
const dateBeforeMs = date.split('.')[0];
443+
if (date === dateBeforeMs) {
444+
// date already does not have milliseconds
445+
return date;
446+
}
447+
return `${dateBeforeMs}Z`;
448+
}
449+
return date;
450+
}
451+
432452
/**
433453
* Transform route object from graphhopper into one readable by the client, an array of
434454
* five routes. Includes delay calculations, asynchronous.
@@ -469,7 +489,8 @@ function parseRoutes(
469489

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

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

498519
const directions = await Promise.all(legs.map(async (currLeg, j, legsArray) => {
499520
let { type } = currLeg;
500-
let startTime = currLeg.departureTime;
501-
let endTime = currLeg.arrivalTime;
521+
let startTime = formatDate(currLeg.departureTime);
522+
let endTime = formatDate(currLeg.arrivalTime);
502523

503524
if (busRoute.transfers === -1) {
504525
startTime = departureTime;

0 commit comments

Comments
 (0)