<commit_before>/** @jsx React.DOM */

Drop.Views.RelativeTimestamp = React.createClass({
	resetInterval: function () {
		this.setState({
			interval: setInterval(this.forceUpdate.bind(this), 1000)
		});
	},

	clearInterval: function () {
		clearInterval(this.state.interval);
	},

	componentDidMount: function () {
		this.resetInterval();
	},

	componentWillUnmount: function () {
		this.clearInterval();
	},

	componentWillReceiveProps: function (props) {
		if (this.props.milliseconds !== props.milliseconds) {
			this.resetInterval();
		}
	},
<commit_msg>Optimize re-render interval for timestamps<commit_after>/** @jsx React.DOM */

Drop.Views.RelativeTimestamp = React.createClass({
	getInitialState: function () {
		return {};
	},

	resetInterval: function () {
		this.clearInterval();

		var updateEvery = function (n) {
			this.setState({
				interval: setInterval(this.forceUpdate.bind(this), n)
			});
		}.bind(this);

    var delta = Date.now() - this.props.milliseconds;
    if (delta < 60000) { // less than 1 minute ago
			updateEvery(2000); // update in 2 seconds
		} else if (delta < 3600000) { // less than 1 hour ago
			updateEvery(30000); // update in 30 seconds
		} else if (delta < 86400000) { // less than 1 day ago
			updateEvery(1800000); // update in 30 minutes
		} else if (delta < 2678400000) { // 31 days ago
			updateEvery(43200000); // update in 12 hours
		} else {
			updateEvery(2419000000); // update in 28 days
		}
	},

	clearInterval: function () {
		clearInterval(this.state.interval);
	},

	componentDidMount: function () {
		this.resetInterval();
	},

	componentWillUnmount: function () {
		this.clearInterval();
	},

	componentWillReceiveProps: function (props) {
		if (this.props.milliseconds !== props.milliseconds) {
			this.resetInterval();
		}
	},

{'fraction_non_alphanumeric': 0.14508928571428573, 'fraction_numerical': 0.04575892857142857, 'mean_word_length': 3.718421052631579, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6983102', 'n_tokens_mistral': 679, 'n_tokens_neox': 556, 'n_words': 130}