<commit_before># encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Time #:nodoc:
      module Conversions #:nodoc:
        def set(value)
          return nil if value.blank?
          time = ::Time.parse(value.is_a?(::Time) ? value.strftime("%Y-%m-%d %H:%M:%S %Z") : value.to_s)
          time.utc? ? time : time.utc
        end
        def get(value)
          return nil if value.blank?
          ::Time.zone ? value.getlocal : value
        end
      end
    end
  end
end
<commit_msg>add more optimized conversions for Time<commit_after># encoding: utf-8
module Mongoid #:nodoc:
  module Extensions #:nodoc:
    module Time #:nodoc:
      module Conversions #:nodoc:
        def set(value)
          return nil if value.blank?
          time = convertable?(value) ? value.to_time : ::Time.parse(value.to_s)
          # Convert time to milliseconds since BSON stores dates with that accurracy, but Ruby uses microseconds
          ::Time.at((time.to_f * 1000).round / 1000.0).utc if time
        rescue ArgumentError
          value
        end
        def get(value)
          return nil if value.blank?
          ::Time.zone ? value.getlocal : value
        end

        protected
        def convertable?(value)
          value.is_a?(::Time) || value.is_a?(::Date) || value.is_a?(::DateTime)
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.11176040905770636, 'fraction_numerical': 0.008035062089116142, 'mean_word_length': 2.0925507900677203, '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': '1678769', 'n_tokens_mistral': 436, 'n_tokens_neox': 429, 'n_words': 120}