<commit_before>import * as React from 'react'
import * as moment from 'moment'

interface IRelativeTimeProps {
  readonly date: Date
}

interface IRelativeTimeState {
  readonly absoluteText: string
  readonly relativeText: string
}

const SECOND = 1000
const MINUTE = SECOND * 60
const HOUR = MINUTE * 60
const DAY = HOUR * 24

export class RelativeTime extends React.Component<IRelativeTimeProps, IRelativeTimeState> {

  private timer: number | null

  private clearTimer() {
    if (this.timer) {
      clearTimeout(this.timer)
      this.timer = null
    }
  }

  private updateAndSchedule(absoluteText: string, relativeText: string, timeout: number) {
    this.timer = window.setTimeout(this.update, timeout)
    this.setState({ absoluteText, relativeText })
  }

  private update = () => {
    this.clearTimer()

    const then = moment(this.props.date)
    const now = moment()
    const diff = then.diff(now)
    const duration = Math.abs(diff)
    const absoluteText = then.format('LLLL')

    if (diff > 0) {
      this.updateAndSchedule(absoluteText, 'from the future', duration)
    } else if (duration < MINUTE) {
      this.updateAndSchedule(absoluteText, 'just now', MINUTE - duration)
    } else if (duration < HOUR) {
      this.updateAndSchedule(absoluteText, then.from(now), MINUTE)
    } else if (duration < DAY) {
      this.updateAndSchedule(absoluteText, then.from(now), HOUR)
    } else if (duration < 7 * DAY) {
      this.updateAndSchedule(absoluteText, then.from(now), 6 * HOUR)
    } else {
      this.setState({ absoluteText, relativeText: then.format('LL') })
    }
  }

  public componentWillReceiveProps(nextProps: IRelativeTimeProps) {
    if (this.props.date !== nextProps.date) {
      this.update()
    }
  }

  public componentWillMount() {
    this.update()
  }

  public componentWillUnmount() {
    this.clearTimer()
  }
<commit_msg>Don't use this.props from willReceiveProps<commit_after>import * as React from 'react'
import * as moment from 'moment'

interface IRelativeTimeProps {
  readonly date: Date
}

interface IRelativeTimeState {
  readonly absoluteText: string
  readonly relativeText: string
}

const SECOND = 1000
const MINUTE = SECOND * 60
const HOUR = MINUTE * 60
const DAY = HOUR * 24

export class RelativeTime extends React.Component<IRelativeTimeProps, IRelativeTimeState> {

  private timer: number | null

  private clearTimer() {
    if (this.timer) {
      clearTimeout(this.timer)
      this.timer = null
    }
  }

  private updateAndSchedule(absoluteText: string, relativeText: string, timeout: number) {
    console.log(absoluteText, relativeText, timeout)
    this.clearTimer()
    this.timer = window.setTimeout(this.updateFromScheduler, timeout)
    this.setState({ absoluteText, relativeText })
  }

  private updateWithDate(date: Date) {
    const then = moment(date)
    const now = moment()
    const diff = then.diff(now)
    const duration = Math.abs(diff)
    const absoluteText = then.format('LLLL')

    if (diff > 0) {
      this.updateAndSchedule(absoluteText, 'from the future', duration)
    } else if (duration < MINUTE) {
      this.updateAndSchedule(absoluteText, 'just now', MINUTE - duration)
    } else if (duration < HOUR) {
      this.updateAndSchedule(absoluteText, then.from(now), MINUTE)
    } else if (duration < DAY) {
      this.updateAndSchedule(absoluteText, then.from(now), HOUR)
    } else if (duration < 7 * DAY) {
      this.updateAndSchedule(absoluteText, then.from(now), 6 * HOUR)
    } else {
      this.setState({ absoluteText, relativeText: then.format('LL') })
    }
  }

  private updateFromScheduler = () => { this.updateWithDate(this.props.date) }

  public componentWillReceiveProps(nextProps: IRelativeTimeProps) {
    if (this.props.date !== nextProps.date) {
      this.updateWithDate(nextProps.date)
    }
  }

  public componentWillMount() {
    this.updateWithDate(this.props.date)
  }

  public componentWillUnmount() {
    this.clearTimer()
  }

{'fraction_non_alphanumeric': 0.11038306451612903, 'fraction_numerical': 0.00655241935483871, 'mean_word_length': 3.5620689655172413, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '5081395', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1189, 'n_words': 299}