mastodon/app/assets/javascripts/components/components/relative_timestamp.jsx

53 lines
886 B
React
Raw Normal View History

import moment from 'moment';
import PureRenderMixin from 'react-addons-pure-render-mixin';
2016-08-24 21:08:00 +02:00
moment.updateLocale('en', {
relativeTime : {
future: "in %s",
2016-08-31 16:48:21 +02:00
past: "%s",
s: "%ds",
m: "1m",
2016-08-24 21:08:00 +02:00
mm: "%dm",
2016-08-31 16:48:21 +02:00
h: "1h",
2016-08-24 21:08:00 +02:00
hh: "%dh",
2016-08-31 16:48:21 +02:00
d: "1d",
2016-08-24 21:08:00 +02:00
dd: "%dd",
2016-08-31 16:48:21 +02:00
M: "1mo",
MM: "%dmo",
2016-08-31 16:48:21 +02:00
y: "1y",
2016-08-24 21:08:00 +02:00
yy: "%dy"
}
});
const RelativeTimestamp = React.createClass({
2016-08-24 21:08:00 +02:00
propTypes: {
timestamp: React.PropTypes.string.isRequired,
now: React.PropTypes.any
2016-08-24 21:08:00 +02:00
},
mixins: [PureRenderMixin],
render () {
const timestamp = moment(this.props.timestamp);
const now = this.props.now;
2016-08-24 21:08:00 +02:00
let string = '';
2016-08-24 21:08:00 +02:00
if (timestamp.isAfter(now)) {
string = 'Just now';
} else {
string = timestamp.from(now);
}
2016-08-24 21:08:00 +02:00
return (
2016-08-31 22:58:10 +02:00
<span>
{string}
2016-08-24 21:08:00 +02:00
</span>
);
}
});
export default RelativeTimestamp;