1
0
mirror of https://github.com/funamitech/mastodon synced 2024-11-29 07:18:54 +09:00
YuruToot/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-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",
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-25 04:08:00 +09:00
propTypes: {
timestamp: React.PropTypes.string.isRequired,
now: React.PropTypes.any
2016-08-25 04:08:00 +09:00
},
mixins: [PureRenderMixin],
render () {
const timestamp = moment(this.props.timestamp);
const now = this.props.now;
2016-08-25 04:08:00 +09:00
let string = '';
2016-08-25 04:08:00 +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>
{string}
2016-08-25 04:08:00 +09:00
</span>
);
}
});
export default RelativeTimestamp;