mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 16:26:08 +08:00
32 lines
750 B
Plaintext
32 lines
750 B
Plaintext
|
moment = require 'moment'
|
||
|
React = require 'react'
|
||
|
|
||
|
module.exports =
|
||
|
MessageTimestamp = React.createClass
|
||
|
displayName: 'MessageTimestamp'
|
||
|
propTypes:
|
||
|
date: React.PropTypes.object.isRequired,
|
||
|
|
||
|
render: ->
|
||
|
<div>{moment(@props.date).format(@_timeFormat())}</div>
|
||
|
|
||
|
_timeFormat: ->
|
||
|
today = moment(@_today())
|
||
|
dayOfEra = today.dayOfYear() + today.year() * 365
|
||
|
msgDate = moment(@props.date)
|
||
|
msgDayOfEra = msgDate.dayOfYear() + msgDate.year() * 365
|
||
|
diff = dayOfEra - msgDayOfEra
|
||
|
if diff < 1
|
||
|
return "h:mm a"
|
||
|
if diff < 4
|
||
|
return "MMM D, h:mm a"
|
||
|
else if diff > 1 and diff <= 365
|
||
|
return "MMM D"
|
||
|
else
|
||
|
return "MMM D YYYY"
|
||
|
|
||
|
# Stubbable for testing. Returns a `moment`
|
||
|
_today: -> moment()
|
||
|
|
||
|
|