<commit_before>// @flow

import React, {Component, PropTypes} from 'react';
import moment from 'moment';

import type Moment from 'moment';

type Props = {
    date: ?string,
    liveUpdate: ?boolean
};

type State = {
    date: ?Moment
};

/**
 * Displays a date in moment's "fromNow" format, e.g. "2 hours ago", "5 days ago" etc
 * Also displays the original date on hover.
 * Expects "date" to be passed in as ISO-8601 string with time zone info.
 * If time zone is omitted, then UTC is assumed.
 */
export class ReadableDate extends Component {

    state:State;
    timer:number;
    timerPeriodMillis:number;

    constructor(props:Props) {
        super(props);
        // When updating, average 1s period, with jitter to spread out the work
        this.timerPeriodMillis = 750 + Math.ceil(Math.random() * 500);
        this.timer = 0;
        this.state = {date: null};
    }

    componentDidMount() {
        this.handleProps(this.props);
    }

    componentWillReceiveProps(nextProps:Props) {
        this.handleProps(nextProps);
    }

    handleProps(props:Props) {

        if (this.timer) {
            clearInterval(this.timer);
            this.timer = 0;
        }

        let date = null; // TODO: type this to ?moment, whatever the fuck that produces<commit_msg>JENKINS-35688-ReadableDate-Live * Fix a small problem listening to the wrong lifecycle event causing an unnecessary render() cycle on mount<commit_after>// @flow

import React, {Component, PropTypes} from 'react';
import moment from 'moment';

import type Moment from 'moment';

type Props = {
    date: ?string,
    liveUpdate: ?boolean
};

type State = {
    date: ?Moment
};

/**
 * Displays a date in moment's "fromNow" format, e.g. "2 hours ago", "5 days ago" etc
 * Also displays the original date on hover.
 * Expects "date" to be passed in as ISO-8601 string with time zone info.
 * If time zone is omitted, then UTC is assumed.
 */
export class ReadableDate extends Component {

    state:State;
    timer:number;
    timerPeriodMillis:number;

    constructor(props:Props) {
        super(props);
        // When updating, average 1s period, with jitter to spread out the work
        this.timerPeriodMillis = 750 + Math.ceil(Math.random() * 500);
        this.timer = 0;
        this.state = {date: null};
    }

    componentWillMount() {
        this.handleProps(this.props);
    }

    componentWillReceiveProps(nextProps:Props) {
        this.handleProps(nextProps);
    }

    handleProps(props:Props) {

        if (this.timer) {
            clearInterval(this.timer);
            this.timer = 0;
        }

        let date = null; // TODO: type this to ?moment, whatever the fuck that produces
{'fraction_non_alphanumeric': 0.1067853170189099, 'fraction_numerical': 0.012977382276603633, 'mean_word_length': 2.706043956043956, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7201929', 'n_tokens_mistral': 826, 'n_tokens_neox': 782, 'n_words': 266}