Module: MongoMapper::Extensions::Date
- Included in:
- Date
- Defined in:
- lib/mongo_mapper/extensions/date.rb
Instance Method Summary collapse
Instance Method Details
#from_mongo(value) ⇒ Object
16 17 18 |
# File 'lib/mongo_mapper/extensions/date.rb', line 16 def from_mongo(value) value.to_date if value end |
#to_mongo(value) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mongo_mapper/extensions/date.rb', line 5 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 |