<commit_before>import React from "react";
import {FormattedRelative} from "react-intl";

class TimeAgo extends React.Component {
    
    constructor(props) {
        super(props);

        this.timeout = null;
        this._update = this._update.bind(this);
    }

    shouldComponentUpdate(nextProps) {
        if (nextProps.time !== this.props.time) {
            this.forceUpdate();
        }
        return false;
    }

    _update() {
        this._clearTimeout();
        let {time} = this.props;
        if (typeof time === "string") {
            time += "+00:00";
        }
        let now = (new Date()).toString();
        let timePassed = Math.round((new Date()).getTime() - (new Date(time)).getTime()) / 1000;
        let interval;
        if (timePassed < 60) { // 60s
            interval = 1000; // 1s
        } else if (timePassed < 60 * 60){ // 1 hour
            interval = 60 * 1000; // 1 minute
        } else {
            interval = 60 * 60 * 1000 // 1 hour
        }

        // console.log("now:", now, "propTime:", propTime, "time:", time, "typeof time:", typeof time);

        this.timeout = setTimeout(this._update, interval);

        this.forceUpdate();
    }

    _clearTimeout() {
        if (this.timeout) {
            clearTimeout(this.timeout);
        }
    }

    componentDidMount() {
        this._update();
    }

    componentWillUnmount() {
        this._clearTimeout();
    }

    render() {
        let {time, component} = this.props;
        if (!time) {
            return null;
        }
        
        if (typeof time === "string" && time.indexOf("+") === -1) {
            time += "+00:00";
        }

        component = component ? component : "span";

        let timeAgo = <FormattedRelative value={time} />
        return React.createElement(component, {className: this.props.className}, timeAgo);
    }
}

export default TimeAgo;<commit_msg>Add full date tooltip on TimeAgo hover<commit_after>import React from "react";
import {FormattedRelative} from "react-intl";

class TimeAgo extends React.Component {
    
    constructor(props) {
        super(props);

        this.timeout = null;
        this._update = this._update.bind(this);
    }

    shouldComponentUpdate(nextProps) {
        if (nextProps.time !== this.props.time) {
            this.forceUpdate();
        }
        return false;
    }

    _update() {
        this._clearTimeout();
        let {time} = this.props;
        if (typeof time === "string") {
            time += "+00:00";
        }
        let timePassed = Math.round((new Date()).getTime() - (new Date(time)).getTime()) / 1000;
        let interval;
        if (timePassed < 60) { // 60s
            interval = 1000; // 1s
        } else if (timePassed < 60 * 60){ // 1 hour
            interval = 60 * 1000; // 1 minute
        } else {
            interval = 60 * 60 * 1000 // 1 hour
        }

        // console.log("now:", now, "propTime:", propTime, "time:", time, "typeof time:", typeof time);

        this.timeout = setTimeout(this._update, interval);

        this.forceUpdate();
    }

    _clearTimeout() {
        if (this.timeout) {
            clearTimeout(this.timeout);
        }
    }

    componentDidMount() {
        this._update();
    }

    componentWillUnmount() {
        this._clearTimeout();
    }

    render() {
        let {time, component} = this.props;
        if (!time) {
            return null;
        }
        
        if (typeof time === "string" && time.indexOf("+") === -1) {
            time += "+00:00";
        }

        component = component ? component : "span";

        let timeAgo = <span ref={"timeago_ttip_" + time} data-tip={new Date(time)} data-place="top" data-type="light"><FormattedRelative value={time}/></span>
        return React.createElement(component, {className: this.props.className}, timeAgo);
    }
}

export default TimeAgo;
{'fraction_non_alphanumeric': 0.14609053497942387, 'fraction_numerical': 0.022119341563786008, 'mean_word_length': 1.8658806190125277, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1871155', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1109, 'n_words': 267}