mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
59 lines
992 B
JavaScript
59 lines
992 B
JavaScript
import moment from 'moment';
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin';
|
|
|
|
moment.updateLocale('en', {
|
|
relativeTime : {
|
|
future: "in %s",
|
|
past: "%s",
|
|
s: "%ds",
|
|
m: "1m",
|
|
mm: "%dm",
|
|
h: "1h",
|
|
hh: "%dh",
|
|
d: "1d",
|
|
dd: "%dd",
|
|
M: "1mo",
|
|
MM: "%dmo",
|
|
y: "1y",
|
|
yy: "%dy"
|
|
}
|
|
});
|
|
|
|
const RelativeTimestamp = React.createClass({
|
|
|
|
getInitialState () {
|
|
return {
|
|
text: ''
|
|
};
|
|
},
|
|
|
|
propTypes: {
|
|
timestamp: React.PropTypes.string.isRequired
|
|
},
|
|
|
|
mixins: [PureRenderMixin],
|
|
|
|
componentWillMount () {
|
|
this._updateMomentText();
|
|
this.interval = setInterval(this._updateMomentText, 6000);
|
|
},
|
|
|
|
componentWillUnmount () {
|
|
clearInterval(this.interval);
|
|
},
|
|
|
|
_updateMomentText () {
|
|
this.setState({ text: moment(this.props.timestamp).fromNow() });
|
|
},
|
|
|
|
render () {
|
|
return (
|
|
<span>
|
|
{this.state.text}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
});
|
|
|
|
export default RelativeTimestamp;
|