<commit_before>import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import utc from 'dayjs/plugin/utc'
import PropTypes from 'prop-types'
import React from 'react'

dayjs.extend(utc)
dayjs.extend(relativeTime)

class RelativeDate extends React.Component {
  static propTypes = {
    date: PropTypes.string,
    label: PropTypes.string,
  }

  constructor(props) {
    super(props)

    /*
      Make day.js say 'just now' if the time difference is less
      than five seconds either way to get round non-sync'd server and
      client time.
      This may make 'a few seconds ago' somewhat redundant, but it's
      worth it.
    */
    dayjs.prototype.fromNowOrNow = function (a) {
      console.log(this)
      if (Math.abs(dayjs().diff(this)) < 5000) {
        return `just now`
      }
      return this.fromNow(a)
    }
  }

  render() {
    const { date, label } = this.props
    return (
      <div title={dayjs.utc(date).local().format(`dddd, D MMMM YYYY, h:mm:ss a`)}>
        {label} {dayjs.utc(date).local().fromNowOrNow()}
      </div>
    )
  }
}

export default RelativeDate
<commit_msg>fix relative date<commit_after>import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import utc from 'dayjs/plugin/utc'
import PropTypes from 'prop-types'
import React from 'react'

dayjs.extend(utc)
dayjs.extend(relativeTime)

class RelativeDate extends React.Component {
  static propTypes = {
    date: PropTypes.string,
    label: PropTypes.string,
  }

  constructor(props) {
    super(props)

    /*
      Make day.js say 'just now' if the time difference is less
      than five seconds either way to get round non-sync'd server and
      client time.
      This may make 'a few seconds ago' somewhat redundant, but it's
      worth it.
    */
    dayjs.prototype.fromNowOrNow = function (a) {
      console.log(this)
      if (Math.abs(dayjs().diff(this)) < 5000) {
        return `just now`
      }
      return this.fromNow(a)
    }
  }

  render() {
    const { date, label } = this.props
    return (
      <div title={
        dayjs().utc(date).local().format(`dddd, D MMMM YYYY, h:mm:ss a`)
      }
      >
        {label} {dayjs().utc(date).local().fromNowOrNow()}
      </div>
    )
  }
}

export default RelativeDate

{'fraction_non_alphanumeric': 0.11718408395277656, 'fraction_numerical': 0.0034980323567993005, 'mean_word_length': 2.726384364820847, 'pattern_counts': {'":': 0, '<': 9, '<?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': '409226', 'n_tokens_mistral': 763, 'n_tokens_neox': 744, 'n_words': 207}