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