<commit_before>import React, { PropTypes } from 'react';
import { Slider } from 'light-ui';
import styles from './date_slider.css';
import dateHelper from 'UTILS/date';

const getDateBySeconds = dateHelper.date.bySeconds;
const getDateBeforeYears = dateHelper.date.beforeYears;
const getValidatorDate = dateHelper.validator.date;
const getValidatorFullDate = dateHelper.validator.fullDate;
const getSecondsByDate = dateHelper.seconds.getByDate;
const afterDays = dateHelper.date.afterDays;

const SECONDS_PER_DAY = 24 * 60 * 60 * 30;
const MAX_DATE = afterDays(1);

class DateSlider extends React.Component {
  constructor(props) {
    super(props);
    const { initialStart, initialEnd, maxDate } = this.props;
    this.state = {
      startDate: initialStart,
      endDate: initialEnd || maxDate
    }
    this.onChange = this.onChange.bind(this);
  }

  onChange(seconds) {
    const { onStartChange, onEndChange } = this.props;
    const [startSeconds, endSeconds] = seconds;
    const startDate = getDateBySeconds(startSeconds);
    const endDate = getDateBySeconds(endSeconds);

    onStartChange && onStartChange(startDate);
    onEndChange && onEndChange(endDate, endDate === MAX_DATE);
    this.setState({
      startDate,
      endDate
    });
  }

  componentWillReceiveProps(nextProps) {
    const { initialStart, initialEnd } = nextProps;
    this.setState({
      startDate: initialStart,
      endDate: initialEnd
    });
  }

  get pushInterval() {
    const { pushInterval } = this.props;
    switch (pushInterval) {
      case 'day':
        return SECONDS_PER_DAY;
      case 'month':
        return SECONDS_PER_DAY * 30;
      case 'halfYear':
        return SECONDS_PER_DAY * 30 * 6;
      case 'year':
        return SECONDS_PER_DAY * 30 * 12;
      case '2year':
        return SECONDS_PER_DAY * 30 * 24;
      default:
        return SECONDS_PER_DAY * 30;
    }
  }

  render() {
    const {
      minDate,
      maxDate,
      startText,
      endText
    } = this.props;

    const {
      startDate,
      endDate
    } = this.state;
    const validateEndDate = getValidatorFullDate(endDate);

    return (
      <div className={styles.slider_container}>
        <Slider
          min={getSecondsByDate(minDate)}
          max={getSecondsByDate(maxDate)}
          value={[
            getSecondsByDate(startDate),
            getSecondsByDate(endDate)
          ]}
          tipFormatter={(seconds) => {
            const date = getDateBySeconds(seconds);
            const fullDate = getValidatorFullDate(date);
            return (
              <div className={styles.slider_tipso}>
                {MAX_DATE === fullDate ? '至今' : getValidatorDate(date)}
              </div>
            );
          }}
          onChange={this.onChange}
          minRange={SECONDS_PER_DAY}
        />
        <div className={styles.slider_tips_container}>
          <div className={styles.slider_tips}>
            {startText}
            <span>
              {getValidatorDate(startDate)}
            </span>
          </div>
          <div className={styles.slider_tips}>
            <span>
              {MAX_DATE === validateEndDate
                  ? '至今'
                  : getValidatorDate(endDate)
              }
            </span>
            {endText}
          </div>
        </div>
      </div>
    )
  }
}

DateSlider.propTypes = {
  pushInterval: PropTypes.string,
  minDate: PropTypes.string,
  maxDate: PropTypes.string,
  startText: PropTypes.string,
  endText: PropTypes.string,
  initialStart: PropTypes.string,
  initialEnd: PropTypes.string,
  onStartChange: PropTypes.func,
  onEndChange: PropTypes.func
};

DateSlider.defaultProps = {
  pushInterval: 'day',
  minDate: getDateBeforeYears(10),
  maxDate: MAX_DATE,
  initialStart: getDateBeforeYears(2),
  initialEnd: getDateBeforeYears(1),
  startText: '开始时间',
  endText: '结束时间',
  onStartChange: () => {},
  onEndChange: () => {}
};

export default DateSlider;
<commit_msg>WHAT: Bugfixed for resume rerender<commit_after>import React, { PropTypes } from 'react';
import { Slider } from 'light-ui';
import styles from './date_slider.css';
import dateHelper from 'UTILS/date';

const getDateBySeconds = dateHelper.date.bySeconds;
const getDateBeforeYears = dateHelper.date.beforeYears;
const getValidatorDate = dateHelper.validator.date;
const getValidatorFullDate = dateHelper.validator.fullDate;
const getSecondsByDate = dateHelper.seconds.getByDate;
const afterDays = dateHelper.date.afterDays;

const SECONDS_PER_DAY = 24 * 60 * 60 * 30;
const MAX_DATE = afterDays(1);

class DateSlider extends React.Component {
  constructor(props) {
    super(props);
    const { initialStart, initialEnd, maxDate } = this.props;
    this.state = {
      startDate: initialStart,
      endDate: initialEnd || maxDate
    }
    this.onChange = this.onChange.bind(this);
  }

  onChange(seconds) {
    const { onStartChange, onEndChange } = this.props;
    const [startSeconds, endSeconds] = seconds;
    const startDate = getDateBySeconds(startSeconds);
    const endDate = getDateBySeconds(endSeconds);

    onStartChange && onStartChange(startDate);
    onEndChange && onEndChange(endDate, endDate === MAX_DATE);
    this.setState({
      startDate,
      endDate
    });
  }

  componentWillReceiveProps(nextProps) {
    const { initialStart, initialEnd, maxDate } = nextProps;
    this.setState({
      startDate: initialStart,
      endDate: initialEnd || maxDate
    });
  }

  get pushInterval() {
    const { pushInterval } = this.props;
    switch (pushInterval) {
      case 'day':
        return SECONDS_PER_DAY;
      case 'month':
        return SECONDS_PER_DAY * 30;
      case 'halfYear':
        return SECONDS_PER_DAY * 30 * 6;
      case 'year':
        return SECONDS_PER_DAY * 30 * 12;
      case '2year':
        return SECONDS_PER_DAY * 30 * 24;
      default:
        return SECONDS_PER_DAY * 30;
    }
  }

  render() {
    const {
      minDate,
      maxDate,
      startText,
      endText
    } = this.props;

    const {
      startDate,
      endDate
    } = this.state;
    const validateEndDate = getValidatorFullDate(endDate);

    return (
      <div className={styles.slider_container}>
        <Slider
          min={getSecondsByDate(minDate)}
          max={getSecondsByDate(maxDate)}
          value={[
            getSecondsByDate(startDate),
            getSecondsByDate(endDate)
          ]}
          tipFormatter={(seconds) => {
            const date = getDateBySeconds(seconds);
            const fullDate = getValidatorFullDate(date);
            return (
              <div className={styles.slider_tipso}>
                {MAX_DATE === fullDate ? '至今' : getValidatorDate(date)}
              </div>
            );
          }}
          onChange={this.onChange}
          minRange={SECONDS_PER_DAY}
        />
        <div className={styles.slider_tips_container}>
          <div className={styles.slider_tips}>
            {startText}
            <span>
              {getValidatorDate(startDate)}
            </span>
          </div>
          <div className={styles.slider_tips}>
            <span>
              {MAX_DATE === validateEndDate
                  ? '至今'
                  : getValidatorDate(endDate)
              }
            </span>
            {endText}
          </div>
        </div>
      </div>
    )
  }
}

DateSlider.propTypes = {
  pushInterval: PropTypes.string,
  minDate: PropTypes.string,
  maxDate: PropTypes.string,
  startText: PropTypes.string,
  endText: PropTypes.string,
  initialStart: PropTypes.string,
  initialEnd: PropTypes.string,
  onStartChange: PropTypes.func,
  onEndChange: PropTypes.func
};

DateSlider.defaultProps = {
  pushInterval: 'day',
  minDate: getDateBeforeYears(10),
  maxDate: MAX_DATE,
  initialStart: getDateBeforeYears(2),
  initialEnd: getDateBeforeYears(1),
  startText: '开始时间',
  endText: '结束时间',
  onStartChange: () => {},
  onEndChange: () => {}
};

export default DateSlider;

{'fraction_non_alphanumeric': 0.10903622007770397, 'fraction_numerical': 0.007269081338513598, 'mean_word_length': 2.4665508253692443, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '3506586', 'n_tokens_mistral': 2464, 'n_tokens_neox': 2431, 'n_words': 476}