<commit_before>#require 'active_support/all'
require 'active_support/core_ext'
#require 'active_support/core_ext/date'
#require 'active_support/core_ext/date_time'

module DateTimeHelper

  # Processes common time periods and turns them into from to dates.
  # if a to date is not given then it will be auto populated with the from_date 
  #
  # @param [String] from_date (Required) 
  #   in the last hour  - Now - 1 hour
  #   this hour         - The beginning of the hour
  #   last hour         - The beginning of the previous hour
  #   today             - The beginning of the day
  #   yesterday         - The beginning of yesterday
  #   in the last week  - Now - 1 week
  #   this week         - The beginning of the week
  #   last week         - The beginning of last week
  #   in the last month - Now - 1 month
  #   this month        - The beginning of the month
  #   last month        - The beginning of last month
  #   this quarter      - The beginning of the quarter
  #   last quarter      - The beginning of last quarter
  #   this half         - The beginning of this half
  #   last half         - The beginning of hte last half
  #   in the last year  - Now - 1 year
  #   this year         - The beginning of the year
  #   last year         - The beginning of last year
  #   epoch             - Any epoch time made up of 10 digits
  #   YYYYMMDDHHMM      - date string to the minute
  #   Any valid date value parseable by DateTime.parse
  #
  # @param [String] to_date (from_date)
  #   in the last hour  - Now
  #   this hour         - The end of the hour
  #   last hour         - The end of the previous hour
  #   today             - The end of the day
  #   yesterday         - The end of yesterday
  #   in the last week  - Now
  #   this week         - The end of the week
  #   last week         - The end of last week
  #   in the last month - Now
  #   this month        - The end of the month
  #   last month        - The end of last month
  #   this quarter      - The end of the quarter
  #   last quarter      - The end of last quarter
  #   this half         - The end of this half
  #   last half         - The end of hte last half
  #   in the last year  - Now
  #   this year         - The end of the year
  #   last year         - The end of last year
  #   epoch             - Any epoch time made up of 10 digits
  #   YYYYMMDDHHMM      - date string to the minute
  #   Any valid date value parseable by DateTime.parse
  #
  # @return [Array<DateTime>] [ from_date, to_date ]
  def self.process_range(from_date, to_date = nil)
    from_date_str = from_date.to_s.downcase.gsub('_', ' ')
    to_date_str = to_date ? to_date.to_s.downcase.gsub('_', ' ') : nil

    case from_date_str
      when 'in the last hour' # This case diverges the main pattern
        _from_date = DateTime.current - 1.hour
        to_date_str = 'now'
      when 'this hour'
        _from_date = DateTime.current.beginning_of_hour
        to_date_str = from_date_str unless to_date_str
      when 'last hour', 'prev hour'
        _from_date = (DateTime.current - 1.hour).beginning_of_hour
        to_date_str = from_date_str unless to_date_str
      when 'today'
        _from_date = DateTime.current.beginning_of_day
        to_date_str = from_date_str unless to_date_str
      when 'yesterday'
        _from_date = DateTime.yesterday.beginning_of_day
        to_date_str = from_date_str unless to_date_str
      when 'in the last week'
        _from_date = DateTime.current - 1.week
        to_date_str = 'now'
      when 'this week'
        _from_date = DateTime.current.beginning_of_week<commit_msg>Added 'in the last day' as an option<commit_after>#require 'active_support/all'
require 'active_support/core_ext'
#require 'active_support/core_ext/date'
#require 'active_support/core_ext/date_time'

module DateTimeHelper

  # Processes common time periods and turns them into from to dates.
  # if a to date is not given then it will be auto populated with the from_date 
  #
  # @param [String] from_date (Required) 
  #   in the last hour  - Now - 1 hour
  #   this hour         - The beginning of the hour
  #   last hour         - The beginning of the previous hour
  #   in the last day   - Now - 24 hours
  #   today             - The beginning of the day
  #   yesterday         - The beginning of yesterday
  #   in the last week  - Now - 1 week
  #   this week         - The beginning of the week
  #   last week         - The beginning of last week
  #   in the last month - Now - 1 month
  #   this month        - The beginning of the month
  #   last month        - The beginning of last month
  #   this quarter      - The beginning of the quarter
  #   last quarter      - The beginning of last quarter
  #   this half         - The beginning of this half
  #   last half         - The beginning of the last half
  #   in the last year  - Now - 1 year
  #   this year         - The beginning of the year
  #   last year         - The beginning of last year
  #   epoch             - Any epoch time made up of 10 digits
  #   YYYYMMDDHHMM      - date string to the minute
  #   Any valid date value parseable by DateTime.parse
  #
  # @param [String] to_date (from_date)
  #   in the last hour  - Now
  #   this hour         - The end of the hour
  #   last hour         - The end of the previous hour
  #   in the last day   - Now
  #   today             - The end of the day
  #   yesterday         - The end of yesterday
  #   in the last week  - Now
  #   this week         - The end of the week
  #   last week         - The end of last week
  #   in the last month - Now
  #   this month        - The end of the month
  #   last month        - The end of last month
  #   this quarter      - The end of the quarter
  #   last quarter      - The end of last quarter
  #   this half         - The end of this half
  #   last half         - The end of the last half
  #   in the last year  - Now
  #   this year         - The end of the year
  #   last year         - The end of last year
  #   epoch             - Any epoch time made up of 10 digits
  #   YYYYMMDDHHMM      - date string to the minute
  #   Any valid date value parseable by DateTime.parse
  #
  # @return [Array<DateTime>] [ from_date, to_date ]
  def self.process_range(from_date, to_date = nil)
    from_date_str = from_date.to_s.downcase.gsub('_', ' ')
    to_date_str = to_date ? to_date.to_s.downcase.gsub('_', ' ') : nil

    case from_date_str
      when 'in the last hour' # This case diverges the main pattern
        _from_date = DateTime.current - 1.hour
        to_date_str = 'now'
      when 'this hour'
        _from_date = DateTime.current.beginning_of_hour
        to_date_str = from_date_str unless to_date_str
      when 'last hour', 'prev hour'
        _from_date = (DateTime.current - 1.hour).beginning_of_hour
        to_date_str = from_date_str unless to_date_str
      when 'in the last day'
        _from_date = (DateTime.current - 24.hour)
        to_date_str = 'now'
      when 'today'
        _from_date = DateTime.current.beginning_of_day
        to_date_str = from_date_str unless to_date_str
      when 'yesterday'
        _from_date = DateTime.yesterday.beginning_of_day
        to_date_str = from_date_str unless to_date_str
      when 'in the last week'
        _from_date = DateTime.current - 1.week
        to_date_str = 'now'
      when 'this week'
        _from_date = DateTime.current.beginning_of_week
{'fraction_non_alphanumeric': 0.06119983894779224, 'fraction_numerical': 0.003489464501409207, 'mean_word_length': 1.9618441971383147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2873691', 'n_tokens_mistral': 2281, 'n_tokens_neox': 2244, 'n_words': 858}