<commit_before>import React from 'react';
import moment from 'moment';
import {translate} from 'react-i18next';

const formatTime = (time: Date, t: Function) => {
  const now = moment();
  let lookup = 'TIME.';
  let options = {};

  if(now.diff(time, 'days') === 0) {
    lookup += 'TODAY';
  } else if (now.diff(time, 'days') === 1) {
    lookup += 'YESTERDAY';
  } else if (now.diff(time, 'weeks') === 0) {
    lookup += 'DAYS_AGO';
    options.days = now.diff(time, 'days');
  } else if (now.diff(time, 'months') === 0) {
    lookup += 'WEEKS_AGO';
    options.weeks = now.diff(time, 'weeks');
  } else if (now.diff(time, 'years' > 1)) {
    lookup += 'NOT_AVAILABLE';
  } else {
    lookup += 'MONTHS_AGO';
    options.months = now.diff(time, 'months');
  }

  return t(lookup, options);
};

const Time = translate()(({time, t}) =>
  <time dateTime={time.toISOString()}>
    {
      formatTime(time, t)
    }
  </time>
);

export default Time;<commit_msg>Add more accurate time to unit observations<commit_after>import React from 'react';
import moment from 'moment';
import {translate} from 'react-i18next';

const formatTime = (time: Date, t: Function) => {
  const now = moment();
  let lookup = 'TIME.';
  let options = {};

  if(now.diff(time, 'days') === 0) {
    lookup += 'TODAY';
  } else if (now.diff(time, 'days') === 1) {
    lookup += 'YESTERDAY';
  } else if (now.diff(time, 'weeks') === 0) {
    lookup += 'DAYS_AGO';
    options.days = now.diff(time, 'days');
  } else if (now.diff(time, 'months') === 0) {
    lookup += 'WEEKS_AGO';
    options.weeks = now.diff(time, 'weeks');
  } else if (now.diff(time, 'years' > 1)) {
    lookup += 'NOT_AVAILABLE';
  } else {
    lookup += 'MONTHS_AGO';
    options.months = now.diff(time, 'months');
  }

  return t(lookup, options);
};

const Time = translate()(({time, t}) =>
  <time dateTime={time.toISOString()}>
    {
      formatTime(time, t)
    }
    {moment().diff(time, 'days') < 2 && ' '+time.getHours()+':'+time.getMinutes()}
  </time>
);

export default Time;
{'fraction_non_alphanumeric': 0.20511559272011806, 'fraction_numerical': 0.0073782587309394985, 'mean_word_length': 3.4121475054229933, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 13, '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': '4023305', 'n_tokens_mistral': 773, 'n_tokens_neox': 738, 'n_words': 181}