Sha256: 4efc7f06351c46887bdda304101a550ab375b96ef88a2946ea952b9201e129d2

Contents?: true

Size: 548 Bytes

Versions: 10

Compression:

Stored size: 548 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Extensions
    module Date
      def to_mongo(value)
        if value.nil? || (value.instance_of?(String) && '' === value)
          nil
        else
          date = value.instance_of?(::Date) || value.instance_of?(::Time) ? value : ::Date.parse(value.to_s)
          ::Time.utc(date.year, date.month, date.day)
        end
      rescue
        nil
      end

      def from_mongo(value)
        value.to_date if value
      end
    end
  end
end

class Date
  extend MongoMapper::Extensions::Date
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongo_mapper-0.15.3 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.15.2 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.15.1 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.15.0 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.14.0 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.14.0.rc1 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.13.1 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.13.0 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.13.0.beta2 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.13.0.beta1 lib/mongo_mapper/extensions/date.rb