Sha256: e5738c78d6ff6129927758aff7a48e5ecf5114b49fe3b27dab93bfe3a5d54c4b

Contents?: true

Size: 665 Bytes

Versions: 15

Compression:

Stored size: 665 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
      
      def to_mongo(value)
        value.utc if value
      end
      
      def from_mongo(value)
        value.respond_to?(:in_time_zone) ? value.in_time_zone : value
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mongomodel-0.4.0 lib/mongomodel/support/types/time.rb
mongomodel-0.3.6 lib/mongomodel/support/types/time.rb
mongomodel-0.3.5 lib/mongomodel/support/types/time.rb
mongomodel-0.3.4 lib/mongomodel/support/types/time.rb
mongomodel-0.3.3 lib/mongomodel/support/types/time.rb
mongomodel-0.3.2 lib/mongomodel/support/types/time.rb
mongomodel-0.3.1 lib/mongomodel/support/types/time.rb
mongomodel-0.3.0 lib/mongomodel/support/types/time.rb
mongomodel-0.2.20 lib/mongomodel/support/types/time.rb
mongomodel-0.2.19 lib/mongomodel/support/types/time.rb
mongomodel-0.2.18 lib/mongomodel/support/types/time.rb
mongomodel-0.2.17 lib/mongomodel/support/types/time.rb
mongomodel-0.2.16 lib/mongomodel/support/types/time.rb
mongomodel-0.2.15 lib/mongomodel/support/types/time.rb
mongomodel-0.2.14 lib/mongomodel/support/types/time.rb