2017-05-03 01:04:16 +01:00
|
|
|
import React from 'react';
|
2017-01-04 14:43:28 +00:00
|
|
|
import { injectIntl, FormattedRelative } from 'react-intl';
|
2017-04-21 19:05:35 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2017-01-04 14:43:28 +00:00
|
|
|
|
2017-05-26 02:25:41 +01:00
|
|
|
const dateFormatOptions = {
|
|
|
|
hour12: false,
|
|
|
|
year: 'numeric',
|
|
|
|
month: 'short',
|
|
|
|
day: '2-digit',
|
|
|
|
hour: '2-digit',
|
|
|
|
minute: '2-digit',
|
2016-11-16 16:20:52 +00:00
|
|
|
};
|
2016-08-24 20:08:00 +01:00
|
|
|
|
2017-06-23 18:36:54 +01:00
|
|
|
@injectIntl
|
|
|
|
export default class RelativeTimestamp extends React.Component {
|
2017-05-26 02:25:41 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
timestamp: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
shouldComponentUpdate (nextProps) {
|
|
|
|
// As of right now the locale doesn't change without a new page load,
|
|
|
|
// but we might as well check in case that ever changes.
|
|
|
|
return this.props.timestamp !== nextProps.timestamp ||
|
|
|
|
this.props.intl.locale !== nextProps.intl.locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const { timestamp, intl } = this.props;
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<time dateTime={timestamp} title={intl.formatDate(date, dateFormatOptions)}>
|
|
|
|
<FormattedRelative value={date} />
|
|
|
|
</time>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|