<commit_before>require 'time'

# Class that returns a Human representation of the time elapsed since
# a passed time, or between two times.
class HumanTime
  def initialize(stamp, now = 0)
    @stamp    = stamp.is_a?(Time) ? stamp : Time.parse(stamp)
    @now      = now == 0 ? Time.now : now
    midnight  = Time.new(@now.year, @now.mon, @now.day, 0, 0)
    @midday   = midnight + 86_400 / 2

    @elapsed  = @now - @stamp
    @hours    = (@elapsed / 3600.0) + 0.45

    @days     = (midnight - @stamp) / 86_400.0
  end

  def to_s
    text = longer + ' ago'

    text = 'Yesterday' if @days < 1
    text = today       if @days < 0

    text = 'An hour ago' if @elapsed.between?(58 * 60 + 30, 65 * 60 - 15)

    text = 'A couple of minutes ago' if @elapsed < 150

    text = 'Just now' if @elapsed < 90

    text
  end

  def today
    return 'Half an hour ago' if @elapsed > 28.5 * 60 && @elapsed < 31.5 * 60
    return format('%.0f minutes ago', (@elapsed / 60.0)) if @elapsed < (71 * 60)
    return 'This morning' if @stamp < @midday && @now > @midday

    format '%.0f hours ago', @hours
  end

  def longer
    return 'A week' if @days > 6 && @days < 8
    return 'A fortnight' if @days > 13 && @days < 15
    return format('%.0f days', [@days, 2].max) if @days <= 28
    return format('%.0f weeks', ((@days + 3) / 7)) if @days <= 49
    return format('%.0f months', (@days / 30.0)) if @days < (20 * 30)

    format '%.0f years', ((@days / 365) + 0.5)
  end
end<commit_msg>Turned many constants into methods<commit_after>require 'time'

# Monkey patch Float to have a between? analog.
class Float
  def in?(low, high)
    self > low && self < high
  end
end

# Class that returns a Human representation of the time elapsed since
# a passed time, or between two times.
class HumanTime
  HOUR_SECS = 3600
  DAY_SECS  = 24 * HOUR_SECS

  def initialize(stamp, now = nil)
    @stamp    = stamp.is_a?(Time) ? stamp : Time.parse(stamp)
    @now      = now || Time.now
    @midnight = Time.new(@now.year, @now.mon, @now.day, 0, 0)
  end

  def to_s
    text = longer + ' ago'

    text = 'Yesterday' if days < 1
    text = today       if days < 0

    text = 'An hour ago' if elapsed.between?(58 * 60 + 30, 65 * 60 - 15)

    text = 'A couple of minutes ago' if elapsed < 170

    text = 'Just now' if elapsed < 90

    text
  end

  def today
    return 'Half an hour ago' if elapsed.between?(28.5 * 60, 31.5 * 60)
    return format('%.0f minutes ago', (elapsed / 60.0)) if elapsed < (71 * 60)

    return 'This morning' if @stamp < midday && @now > midday

    format '%.0f hours ago', hours
  end

  def longer
    return 'A week' if days.in?(6, 8)
    return 'A fortnight' if days.in?(13, 15)
    return format('%.0f days', [days, 2].max) if days <= 28
    return format('%.0f weeks', ((days + 3) / 7)) if days <= 49
    return format('%.0f months', (days / 30.0)) if days < (20 * 30)

    format '%.0f years', ((days / 365) + 0.5)
  end

  def elapsed
    @now - @stamp
  end

  def midday
    @midnight + DAY_SECS / 2
  end

  def hours
    (elapsed / HOUR_SECS) + 0.45
  end

  def days
    (@midnight - @stamp) / DAY_SECS
  end
end
{'fraction_non_alphanumeric': 0.1408540471637986, 'fraction_numerical': 0.05417463352453792, 'mean_word_length': 2.4119565217391306, 'pattern_counts': {'":': 0, '<': 25, '<?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': '169703', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1121, 'n_words': 407}