<commit_before># BrazilDateInput

module BrazilDateInput
  def self.included(base)
    base.send :extend, ClassMethods
  end
  
  module ClassMethods
    def brazil_date_field *args
      args.each do |field|
        field_name = "#{field}_bd"
        
        define_method field_name do
          if send(field).blank?
            nil
          else
            send(field).to_s.split('-').reverse.join('/')
          end
        end
        
        define_method "#{field_name}=" do |date|
          return unless date =~ /\d{2}\/\d{2}\/\d{4}/
          
          send("#{field}=", date.split('/').reverse.join('-'))
        end
      end
    end
    
    def age_calculation_field(date_field, target_field = :age)
      define_method target_field do
        cur = send(date_field)
        return 0 if cur.blank?

        now = DateTime.now
        old = now.year - cur.year
        old -= 1 if (now.month < cur.month or (now.month == cur.month and now.day < cur.day))

        old
      end
    end
  end
end

ActiveRecord::Base.send :include, BrazilDateInput<commit_msg>adjusts<commit_after># BrazilDateInput

module BrazilDateInput
  def self.included(base)
    base.send :extend, ClassMethods
  end
  
  module ClassMethods
    def brazil_date_field *args
      args.each do |field|
        field_name = "#{field}_br"
        
        define_method field_name do
          if send(field).blank?
            nil
          else
            send(field).strftime("%d/%m/%Y")
          end
        end
        
        define_method "#{field_name}=" do |date|
          return unless date =~ /\d{2}\/\d{2}\/\d{4}/
          
          send("#{field}=", Date.strptime(date, "%d/%m/%Y"))
        end
      end
    end
    
    def brazil_datetime_field *args
      args.each do |field|
        field_name = "#{field}_br"

        define_method field_name do
          if send(field).blank?
            nil
          else
            send(field).strftime("%d/%m/%Y %H:%M")
          end
        end

        define_method "#{field_name}=" do |date|
          return unless date =~ /^\d{2}\/\d{2}\/\d{4} \d{2}:\d{2}$/

          send("#{field}=", DateTime.strptime(date + "-0300", "%d/%m/%Y %H:%M%Z"))
        end
      end
    end
    
    def age_calculation_field(date_field, target_field = :age)
      define_method target_field do
        cur = send(date_field)
        return 0 if cur.blank?

        now = DateTime.now
        old = now.year - cur.year
        old -= 1 if (now.month < cur.month or (now.month == cur.month and now.day < cur.day))

        old
      end
    end
  end
end

ActiveRecord::Base.send :include, BrazilDateInput if defined? ActiveRecord
Mongoid::Document::ClassMethods.send :include, BrazilDateInput::ClassMethods
{'fraction_non_alphanumeric': 0.12486348744084456, 'fraction_numerical': 0.00691663633054241, 'mean_word_length': 1.8359133126934986, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1171615', 'n_tokens_mistral': 884, 'n_tokens_neox': 862, 'n_words': 202}