import formatDistance from 'date-fns/formatDistance';
import * as React from 'react';
/**
 * Displays a date's relative time ("... ago") and shows the full date on hover. Re-renders
 * periodically to ensure the relative time string is up-to-date.
 */
export class Timestamp extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.intervalHandle = null;
    }
    componentDidMount() {
        this.intervalHandle = window.setInterval(() => this.forceUpdate(), Timestamp.RERENDER_INTERVAL_MSEC);
    }
    componentWillUnmount() {
        if (this.intervalHandle !== null) {
            window.clearInterval(this.intervalHandle);
        }
    }
    render() {
        let label = formatDistance(this.props.date, new Date(), { addSuffix: true, includeSeconds: true });
        if (this.props.noAbout) {
            label = label.replace('about ', '');
        }
        return (React.createElement("span", { className: "timestamp", "data-tooltip": this.props.date }, label));
    }
}
Timestamp.RERENDER_INTERVAL_MSEC = 7000;
//# sourceMappingURL=Timestamp.js.map