@@ -202,14 +202,16 @@ class AlertsBody extends Component {
202
202
{ this . props . alerts
203
203
. sort ( ( a , b ) => b . effectiveStartDate - a . effectiveStartDate )
204
204
. map ( ( alert , i ) => {
205
- const effectiveStartDate = moment ( alert . effectiveStartDate )
206
- const daysAway = moment ( ) . diff ( effectiveStartDate , 'days' )
207
- // Add time if alert is effective within one day. Otherwise, use
208
- // calendar long date format (e.g., July 31, 2019).
209
- const dateTimeFormat = Math . abs ( daysAway ) <= 1
210
- ? `${ timeFormat } , ${ longDateFormat } `
211
- : longDateFormat
212
- const dateTimeString = effectiveStartDate . format ( dateTimeFormat )
205
+ // If alert is effective as of +/- one day, use today, tomorrow, or
206
+ // yesterday with time. Otherwise, use long date format.
207
+ const dateTimeString = moment ( alert . effectiveStartDate )
208
+ . calendar ( null , {
209
+ sameDay : `${ timeFormat } , [Today]` ,
210
+ nextDay : `${ timeFormat } , [Tomorrow]` ,
211
+ lastDay : `${ timeFormat } , [Yesterday]` ,
212
+ lastWeek : `${ longDateFormat } ` ,
213
+ sameElse : `${ longDateFormat } `
214
+ } )
213
215
const effectiveDateString = `Effective as of ${ dateTimeString } `
214
216
return (
215
217
< div key = { i } className = 'transit-alert' >
0 commit comments