Sha256: 5164b17ab3bf6d09fc13c492baa998a387815854beb3582393f59870425ab88d

Contents?: true

Size: 510 Bytes

Versions: 71

Compression:

Stored size: 510 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Extensions
    module Date
      def to_mongo(value)
        if value.nil? || value == ''
          nil
        else
          date = value.is_a?(::Date) || value.is_a?(::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.present?
      end
    end
  end
end

class Date
  extend MongoMapper::Extensions::Date
end

Version data entries

71 entries across 71 versions & 9 rubygems

Version Path
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/extensions/date.rb
mongo_mapper-0.8.3 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.08 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.06 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.05 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.04 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.03 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.02 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.08.01 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.07.31 lib/mongo_mapper/extensions/date.rb
mongo_mapper-unstable-2010.07.30 lib/mongo_mapper/extensions/date.rb