<commit_before>module DateHelper
  def format_date_of_birth(date)
    I18n.l(date_from_string_or_date(date), format: :date_of_birth)
  end

  def format_date(date)
    I18n.l(date_from_string_or_date(date), format: :date_of_visit)
  end

  alias_method :format_date_of_visit, :format_date
  alias_method :format_date_of_reply, :format_date

  def format_time_12hr(time)
    I18n.l(time_from_string(time), format: :twelve_hour)
  end

  def format_time_24hr(time)
    I18n.l(time_from_string(time), format: :twenty_four_hour)
  end

  def date_and_duration_of_slot(slot)
    [
      format_date(slot.date),
      format_slot_and_duration(slot.times)
    ].join(' ')
  end

  def date_and_times_of_slot(slot)
    [
      format_date(slot.date),
      start_and_end_time(slot.times)
    ].join(' ')
  end

  private

  def date_from_string_or_date(obj)
    if obj.is_a?(String)
      Date.parse(obj)
    else
      obj
    end
  end

  def time_from_string(obj)
    Time.strptime(obj, '%H%M')
  end

  def format_start_time(times)
    format_time_12hr(times.split('-').first)
  end

  def format_slot_and_duration(times, glue = ' for ')
    from, to = times.split('-')
    [
      format_start_time(times),
      (time_from_string(to) - time_from_string(from)).duration
    ].join(glue)
  end

  def start_and_end_time(times)
    [
      format_time_24hr(times.split('-').first),
      format_time_24hr(times.split('-').last)
    ].join(' - ')
  end
end
<commit_msg>We refactor it so it will be easier to understand<commit_after>module DateHelper
  def format_date_of_birth(date)
    I18n.l(date_from_string_or_date(date), format: :date_of_birth)
  end

  def format_date(date)
    I18n.l(date_from_string_or_date(date), format: :date_of_visit)
  end

  alias_method :format_date_of_visit, :format_date
  alias_method :format_date_of_reply, :format_date

  def format_time_12hr(time)
    I18n.l(time_from_string(time), format: :twelve_hour)
  end

  def format_time_24hr(time)
    I18n.l(time_from_string(time), format: :twenty_four_hour)
  end

  def date_and_duration_of_slot(slot)
    "#{format_date(slot.date)} #{slot_and_duration(slot.times)}"
  end

  def date_and_times_of_slot(slot)
    "#{format_date(slot.date)} #{start_and_end_time(slot.times)}"
  end

  private

  def date_from_string_or_date(obj)
    if obj.is_a?(String)
      Date.parse(obj)
    else
      obj
    end
  end

  def time_from_string(obj)
    Time.strptime(obj, '%H%M')
  end

  def slot_and_duration(times)
    from, to = split_times(times)
    duration = (time_from_string(to) - time_from_string(from)).duration

    "#{format_time_12hr(from)} for #{duration}"
  end

  def start_and_end_time(times)
    split_times(times).map(&method(:format_time_24hr)).join(' - ')
  end

  def split_times(times)
    times.split('-')
  end
end

{'fraction_non_alphanumeric': 0.11387900355871886, 'fraction_numerical': 0.012099644128113879, 'mean_word_length': 3.984042553191489, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2069478', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1082, 'n_words': 169}