mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 04:25:31 +08:00
6f7017a887
Summary: Fixes T1905 - Gost line in recipients field Fixes T1877 - Collapsed dates should not show time Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Maniphest Tasks: T1877, T1905 Differential Revision: https://phab.nylas.com/D1671
48 lines
1.3 KiB
CoffeeScript
48 lines
1.3 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: =>
|
|
<div className={@props.className}
|
|
onClick={@props.onClick}>{@_formattedDate()}</div>
|
|
|
|
_formattedDate: =>
|
|
moment.tz(@props.date, Utils.timeZone).format(@_timeFormat())
|
|
|
|
_timeFormat: =>
|
|
if @props.isDetailed
|
|
return "MMMM D, YYYY [at] h:mm A"
|
|
else
|
|
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"
|
|
else if diff > 1 and diff <= 365
|
|
return "MMM D"
|
|
else
|
|
return "MMM D YYYY"
|
|
|
|
# Stubbable for testing. Returns a `moment`
|
|
_today: -> moment.tz(Utils.timeZone)
|
|
|
|
|
|
|
|
|
|
module.exports = MessageTimestamp
|