Skip to content

Commit

Permalink
fix(service-alert): fix alert effective date time string
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Aug 16, 2019
1 parent af96520 commit 9726654
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/components/narrative/line-itin/transit-leg-body.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ class AlertsBody extends Component {
{this.props.alerts
.sort((a, b) => b.effectiveStartDate - a.effectiveStartDate)
.map((alert, i) => {
const effectiveStartDate = moment(alert.effectiveStartDate)
const daysAway = moment().diff(effectiveStartDate, 'days')
// Add time if alert is effective within one day. Otherwise, use
// calendar long date format (e.g., July 31, 2019).
const dateTimeFormat = Math.abs(daysAway) <= 1
? `${timeFormat}, ${longDateFormat}`
: longDateFormat
const dateTimeString = effectiveStartDate.format(dateTimeFormat)
// If alert is effective as of +/- one day, use today, tomorrow, or
// yesterday with time. Otherwise, use long date format.
const dateTimeString = moment(alert.effectiveStartDate).calendar({
sameDay: `${timeFormat}, [Today]`,
nextDay: `${timeFormat}, [Tomorrow]`,
lastDay: `${timeFormat}, [Yesterday]`,
lastWeek: `${longDateFormat}`,
sameElse: `${longDateFormat}`
})
const effectiveDateString = `Effective as of ${dateTimeString}`
return (
<div key={i} className='transit-alert'>
Expand Down

0 comments on commit 9726654

Please sign in to comment.