Skip to content

Instantly share code, notes, and snippets.

@GirlBossRush
Created May 18, 2014 04:11
Show Gist options
  • Save GirlBossRush/1975a22fc47e7fdc9ab1 to your computer and use it in GitHub Desktop.
Save GirlBossRush/1975a22fc47e7fdc9ab1 to your computer and use it in GitHub Desktop.
REFRESH_DELAY = 6000
@HumanTime = React.createClass
displayName: "humantime"
getInitialState: ->
{relativeTime: @humanize(@props.datetime)}
componentDidMount: ->
@interval = setInterval(@refresh, REFRESH_DELAY)
componentWillUnmount: ->
clearInterval @interval
humanize: (datetime) ->
moment(datetime).fromNow()
refresh: ->
@setState relativeTime: @humanize(@props.datetime)
render: ->
R.time {className: "human-time", dateTime: @props.datetime},
@state.relativeTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment