@@ -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