Skip to content

Commit 9d24ce6

Browse files
authored
Merge pull request #102 from opentripplanner/fix-alert-date-string
Fix alert effective date time string
2 parents 0a5e04c + 7f7b835 commit 9d24ce6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,16 @@ class AlertsBody extends Component {
202202
{this.props.alerts
203203
.sort((a, b) => b.effectiveStartDate - a.effectiveStartDate)
204204
.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+
})
213215
const effectiveDateString = `Effective as of ${dateTimeString}`
214216
return (
215217
<div key={i} className='transit-alert'>

0 commit comments

Comments
 (0)