<commit_before>def __split_nil_time
  Time.parse "#{Time.now.hour}:0:0"
end
def __split_nil_date
  Date.today
end

def __split_to_time datetime
  datetime = __split_nil_time if datetime.blank?
  datetime.to_formatted_s :time
end
def __split_to_date datetime
  datetime = __split_nil_date if datetime.blank?
  datetime.strftime '%d/%m/%Y'
end
def __split_set_time datetime, value
  value = if value.blank?
    __split_nil_time
  elsif value.kind_of? String
    Time.parse value
  else
    value.to_time
  end
  datetime = __split_nil_date if datetime.blank?

  Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime
end
def __split_set_date datetime, value
  value = if value.blank?
    __split_nil_date
  elsif value.kind_of? String
    DateTime.strptime value, '%d/%m/%Y'
  else
    value.to_time
  end
  datetime = __split_nil_time if datetime.blank?

  Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime
end

module SplitDatetime

  module SplitMethods

    def split_datetime attr
      define_method "#{attr}_time" do
        datetime = send attr
        __split_to_time datetime
      end
      define_method "#{attr}_date" do
        datetime = send attr
        __split_to_date datetime
      end
      define_method "#{attr}_time=" do |value|
        datetime = send attr
        send "#{attr}=", __split_set_time(datetime, value)
      end
      define_method "#{attr}_date=" do |value|
        datetime = send attr
        send "#{attr}=", __split_set_date(datetime, value)
      end
    end

  end

end

Class.extend SplitDatetime::SplitMethods
ActiveRecord::Base.extend SplitDatetime::SplitMethods<commit_msg>Refactor to remove global methods<commit_after>
module SplitDatetime

  class << self
    def nil_time
      Time.parse "#{Time.now.hour}:0:0"
    end
    def nil_date
      Date.today
    end

    def to_time datetime
      datetime = self.nil_time if datetime.blank?
      datetime.to_formatted_s :time
    end
    def to_date datetime
      datetime = self.nil_date if datetime.blank?
      datetime.strftime '%d/%m/%Y'
    end
    def set_time datetime, value
      value = if value.blank?
                self.nil_time
              elsif value.kind_of? String
                Time.parse value
              else
                value.to_time
              end
      datetime = self.nil_date if datetime.blank?

      Time.mktime(datetime.year, datetime.month, datetime.day, value.hour, value.min, value.sec).to_datetime
    end
    def set_date datetime, value
      value = if value.blank?
                self.nil_date
              elsif value.kind_of? String
                DateTime.strptime value, '%d/%m/%Y'
              else
                value.to_time
              end
      datetime = nil_time if datetime.blank?

      Time.mktime(value.year, value.month, value.day, datetime.hour, datetime.min, datetime.sec).to_datetime
    end
  end

  module SplitMethods

    def split_datetime attr
      define_method "#{attr}_time" do
        datetime = send attr
        SplitDatetime.to_time datetime
      end
      define_method "#{attr}_date" do
        datetime = send attr
        SplitDatetime.to_date datetime
      end
      define_method "#{attr}_time=" do |value|
        datetime = send attr
        send "#{attr}=", SplitDatetime.set_time(datetime, value)
      end
      define_method "#{attr}_date=" do |value|
        datetime = send attr
        send "#{attr}=", SplitDatetime.set_date(datetime, value)
      end
    end

  end

end

Class.extend SplitDatetime::SplitMethods
ActiveRecord::Base.extend SplitDatetime::SplitMethods
{'fraction_non_alphanumeric': 0.08342391304347826, 'fraction_numerical': 0.0010869565217391304, 'mean_word_length': 2.584225900681597, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6527467', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1110, 'n_words': 287}