@@ -398,6 +398,7 @@ class PatternRow extends Component {
398398}
399399
400400const ONE_HOUR_IN_SECONDS = 3600
401+ const ONE_DAY_IN_SECONDS = 86400
401402
402403/**
403404 * @param {string } homeTimezone Timezone string
@@ -423,19 +424,23 @@ function getFormattedStopTime (stopTime, homeTimezone, soonText = 'Due', timeFor
423424
424425 const now = moment ( ) . tz ( homeTimezone )
425426 const serviceDay = moment ( stopTime . serviceDay * 1000 ) . tz ( homeTimezone )
426- const currentHomeSecondsAfterMidnight = getHomeSecondsAfterMidnight ( homeTimezone )
427- const differentDay = now . date ( ) !== serviceDay . date ( )
428-
427+ const arrivesAfterMidnight = stopTime . realtimeDeparture >= ONE_DAY_IN_SECONDS
428+ // Calculate current home seconds after midnight. If arrival occurs after
429+ // midnight, adjust the value by one day in seconds.
430+ const currentHomeSecondsAfterMidnight = getHomeSecondsAfterMidnight ( homeTimezone ) + ( arrivesAfterMidnight ? ONE_DAY_IN_SECONDS : 0 )
431+ // Determine if arrival occurs on different day, making sure to account for an
432+ // extra day added to the service day if it arrives after midnight.
433+ const arrivalDay = arrivesAfterMidnight
434+ ? serviceDay . add ( 1 , 'day' )
435+ : serviceDay
436+ const differentDay = now . dayOfYear ( ) !== arrivalDay . dayOfYear ( )
429437 // Determine whether to show departure as countdown (e.g. "5 min") or as HH:mm time
430438 const secondsUntilDeparture = stopTime . realtimeDeparture - currentHomeSecondsAfterMidnight
431- const departsInFuture = stopTime . realtimeDeparture > currentHomeSecondsAfterMidnight
432- // Show the exact time if the departure occurs after midnight and if the
433- // departure happens within an hour.
434- // FIXME: It's unclear why this was designed to show exact time after midnight.
435- // We should determine whether this is the desired behavior.
436- const showCountdown = ! differentDay &&
437- secondsUntilDeparture < ONE_HOUR_IN_SECONDS &&
438- departsInFuture
439+ // Determine if vehicle arrives after midnight in order to advance the day of
440+ // the week when showing arrival time/day.
441+ const departsInFuture = secondsUntilDeparture > 0
442+ // Show the exact time if the departure if the departure happens within an hour.
443+ const showCountdown = secondsUntilDeparture < ONE_HOUR_IN_SECONDS && departsInFuture
439444
440445 // Use "soon text" (e.g., Due) if vehicle is approaching.
441446 const countdownString = secondsUntilDeparture < 60
@@ -447,6 +452,11 @@ function getFormattedStopTime (stopTime, homeTimezone, soonText = 'Due', timeFor
447452 // in New York, but viewing a trip planner for service based in Los Angeles).
448453 inHomeTimezone ? timeFormat : `${ timeFormat } z`
449454 )
455+ // We only want to show the day of the week if the arrival is on a
456+ // different day and we're not showing the countdown string. This avoids
457+ // cases such as when it's Wednesday at 11:55pm and an arrival occurs at
458+ // Thursday 12:19am. We don't want the time to read: 'Thursday, 24 minutes'.
459+ const showDayOfWeek = differentDay && ! showCountdown
450460 return (
451461 < div >
452462 < div style = { { float : 'left' } } >
@@ -459,9 +469,9 @@ function getFormattedStopTime (stopTime, homeTimezone, soonText = 'Due', timeFor
459469 style = { { color : '#888' , fontSize : '0.8em' , marginRight : 2 } } />
460470 }
461471 </ div >
462- < div style = { { marginLeft : 20 , fontSize : differentDay ? 12 : 14 } } >
463- { differentDay &&
464- < div style = { { marginBottom : - 4 } } > { serviceDay . format ( 'dddd' ) } </ div >
472+ < div style = { { marginLeft : 20 , fontSize : showDayOfWeek ? 12 : 14 } } >
473+ { showDayOfWeek &&
474+ < div style = { { marginBottom : - 4 } } > { arrivalDay . format ( 'dddd' ) } </ div >
465475 }
466476 < div >
467477 { showCountdown
0 commit comments