@@ -6,7 +6,7 @@ import moment from 'moment'
6
6
7
7
import ViewTripButton from '../../viewers/view-trip-button'
8
8
import { getIcon } from '../../../util/itinerary'
9
- import { formatDuration } from '../../../util/time'
9
+ import { formatDuration , getTimeFormat } from '../../../util/time'
10
10
11
11
// TODO: support multi-route legs for profile routing
12
12
@@ -38,7 +38,7 @@ class TransitLegBody extends Component {
38
38
}
39
39
40
40
render ( ) {
41
- const { customIcons, leg, operator } = this . props
41
+ const { customIcons, leg, operator, timeFormat } = this . props
42
42
const {
43
43
agencyBrandingUrl,
44
44
agencyName,
@@ -108,7 +108,7 @@ class TransitLegBody extends Component {
108
108
109
109
{ /* The Alerts body, if visible */ }
110
110
< VelocityTransitionGroup enter = { { animation : 'slideDown' } } leave = { { animation : 'slideUp' } } >
111
- { alertsExpanded && < AlertsBody alerts = { leg . alerts } /> }
111
+ { alertsExpanded && < AlertsBody alerts = { leg . alerts } timeFormat = { timeFormat } /> }
112
112
</ VelocityTransitionGroup >
113
113
{ /* The "Ride X Min / X Stops" Row, including IntermediateStops body */ }
114
114
{ leg . intermediateStops && leg . intermediateStops . length > 0 && (
@@ -151,7 +151,8 @@ class TransitLegBody extends Component {
151
151
152
152
const mapStateToProps = ( state , ownProps ) => {
153
153
return {
154
- operator : state . otp . config . operators . find ( operator => operator . id === ownProps . leg . agencyId )
154
+ operator : state . otp . config . operators . find ( operator => operator . id === ownProps . leg . agencyId ) ,
155
+ timeFormat : getTimeFormat ( state . otp . config )
155
156
}
156
157
}
157
158
@@ -184,22 +185,29 @@ class AlertsBody extends Component {
184
185
}
185
186
186
187
render ( ) {
188
+ const { timeFormat } = this . props
187
189
return (
188
190
< div className = 'transit-alerts' >
189
- { this . props . alerts . sort ( ( a , b ) => ( a . effectiveStartDate < b . effectiveStartDate ) ? 1 : - 1 ) . map ( ( alert , k ) => {
190
- const effectiveStartDate = moment ( alert . effectiveStartDate )
191
- let effectiveDateString = 'Effective as of '
192
- const daysAway = moment ( ) . diff ( effectiveStartDate , 'days' )
193
- if ( Math . abs ( daysAway ) <= 1 ) effectiveDateString += moment ( effectiveStartDate ) . format ( 'h:MMa, ' )
194
- effectiveDateString += effectiveStartDate . calendar ( null , { sameElse : 'MMMM D, YYYY' } ) . split ( ' at' ) [ 0 ]
195
- return (
196
- < div key = { k } className = 'transit-alert' >
197
- < div className = 'alert-icon' > < i className = 'fa fa-exclamation-triangle' /> </ div >
198
- < div className = 'alert-body' > { alert . alertDescriptionText } </ div >
199
- < div className = 'effective-date' > { effectiveDateString } </ div >
200
- </ div >
201
- )
202
- } ) }
191
+ { this . props . alerts
192
+ . sort ( ( a , b ) => b . effectiveStartDate - a . effectiveStartDate )
193
+ . map ( ( alert , i ) => {
194
+ const effectiveStartDate = moment ( alert . effectiveStartDate )
195
+ let effectiveDateString = 'Effective as of '
196
+ const daysAway = moment ( ) . diff ( effectiveStartDate , 'days' )
197
+ // Add time if alert is effective within one day.
198
+ if ( Math . abs ( daysAway ) <= 1 ) {
199
+ effectiveDateString += `${ effectiveStartDate . format ( timeFormat ) } , `
200
+ }
201
+ effectiveDateString += effectiveStartDate . calendar ( null , { sameElse : 'MMMM D, YYYY' } ) . split ( ' at' ) [ 0 ]
202
+ return (
203
+ < div key = { i } className = 'transit-alert' >
204
+ < div className = 'alert-icon' > < i className = 'fa fa-exclamation-triangle' /> </ div >
205
+ < div className = 'alert-body' > { alert . alertDescriptionText } </ div >
206
+ < div className = 'effective-date' > { effectiveDateString } </ div >
207
+ </ div >
208
+ )
209
+ } )
210
+ }
203
211
</ div >
204
212
)
205
213
}
0 commit comments