Sha256: e0adf59ad7c26761f3875857273c9ae8b80f0d1c68049fe29748c1f30f8122ef

Contents?: true

Size: 480 Bytes

Versions: 3

Compression:

Stored size: 480 Bytes

Contents

require 'active_support/core_ext/time/conversions'
require 'active_support/core_ext/string/conversions'

module MongoModel
  module Types
    class Time < Object
      def cast(value)
        case value
        when ::Array
          base = ::Time.zone ? ::Time.zone : ::Time
          base.local(*value)
        else
          time = value.to_time
          time.change(:usec => (time.usec / 1000.0).floor * 1000)
        end
      rescue
        nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mongomodel-0.2.13 lib/mongomodel/support/types/time.rb
mongomodel-0.2.12 lib/mongomodel/support/types/time.rb
mongomodel-0.2.11 lib/mongomodel/support/types/time.rb