Sha256: e2003d8e959ba3bffa390764851127a5323397fc09bc7353572207a598643e99

Contents?: true

Size: 383 Bytes

Versions: 4

Compression:

Stored size: 383 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)
        time = value.to_time.utc
        # BSON only stores time accurate to the millisecond
        ::Time.at((time.to_f * 1000).floor / 1000.0)
      rescue
        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mongomodel-0.2.6 lib/mongomodel/support/types/time.rb
mongomodel-0.2.5 lib/mongomodel/support/types/time.rb
mongomodel-0.2.4 lib/mongomodel/support/types/time.rb
mongomodel-0.2.3 lib/mongomodel/support/types/time.rb