Mailspring/internal_packages/message-list/lib/message-timestamp.cjsx
dillon 0c14146c78 fix(message-timestamp): call @_formattedDate with correct params. fixes T3388.
Summary: small fix

Test Plan: I didn't add any tests, but this should probably be tested. Not sure the best way to test though. Would love to discuss with somebody!

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T3388

Differential Revision: https://phab.nylas.com/D1919
2015-08-19 15:50:10 -07:00

48 lines
1.5 KiB
CoffeeScript

_ = require 'underscore'
moment = require 'moment-timezone'
React = require 'react'
{Utils} = require 'nylas-exports'
class MessageTimestamp extends React.Component
@displayName: 'MessageTimestamp'
@propTypes:
date: React.PropTypes.object.isRequired,
className: React.PropTypes.string,
isDetailed: React.PropTypes.bool
onClick: React.PropTypes.func
shouldComponentUpdate: (nextProps, nextState) =>
+nextProps.date isnt +@props.date or nextProps.isDetailed isnt @props.isDetailed
render: =>
msgDate = moment.tz(@props.date, Utils.timeZone)
nowDate = @_today()
formattedDate = @_formattedDate(msgDate, nowDate, @props.isDetailed)
<div className={@props.className}
onClick={@props.onClick}>{formattedDate}</div>
_formattedDate: (msgDate, now, isDetailed) =>
if isDetailed
return msgDate.format "MMMM D, YYYY [at] h:mm A"
else
diff = now.diff(msgDate, 'days', true)
isSameDay = now.isSame(msgDate, 'days')
if diff < 1 and isSameDay
return msgDate.format "h:mm a"
if diff < 1.5 and not isSameDay
timeAgo = msgDate.from now
monthAndDay = msgDate.format "h:mm a"
return monthAndDay + " (" + timeAgo + ")"
if diff >= 1.5 and diff < 365
return msgDate.format "MMM D"
if diff >= 365
return msgDate.format "MMM D, YYYY"
# Stubbable for testing. Returns a `moment`
_today: -> moment.tz(Utils.timeZone)
module.exports = MessageTimestamp