Skip to content

Commit 8afd562

Browse files
committed
fix(service-alert): fix date string display in service alert
fix ibi-group/trimet-mod-otp#136
1 parent 1306196 commit 8afd562

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lib/components/narrative/line-itin/transit-leg-body.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,14 @@ class AlertsBody extends Component {
203203
.sort((a, b) => b.effectiveStartDate - a.effectiveStartDate)
204204
.map((alert, i) => {
205205
const effectiveStartDate = moment(alert.effectiveStartDate)
206-
let effectiveDateString = 'Effective as of '
207206
const daysAway = moment().diff(effectiveStartDate, 'days')
208-
// Add time if alert is effective within one day.
209-
if (Math.abs(daysAway) <= 1) {
210-
effectiveDateString += `${effectiveStartDate.format(timeFormat)}, `
211-
}
212-
effectiveDateString += effectiveStartDate
213-
.calendar(
214-
null,
215-
{ sameElse: longDateFormat }
216-
)
217-
.split(' at')[0]
207+
// Add time if alert is effective within one day. Otherwise, use
208+
// calendar long date format (e.g., July 31, 2019).
209+
const dateTimeFormatter = Math.abs(daysAway) <= 1
210+
? `${timeFormat}, ${longDateFormat}`
211+
: longDateFormat
212+
const dateTimeString = effectiveStartDate.format(dateTimeFormatter)
213+
const effectiveDateString = `Effective as of ${dateTimeString}`
218214
return (
219215
<div key={i} className='transit-alert'>
220216
<div className='alert-icon'><i className='fa fa-exclamation-triangle' /></div>

0 commit comments

Comments
 (0)