Method: Time.to_mongo
- Defined in:
- lib/novelys_mongo_mapper/support.rb
.to_mongo(value) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/novelys_mongo_mapper/support.rb', line 189 def self.to_mongo(value) if value.nil? || value == '' nil else time = value.is_a?(Time) ? value : MongoMapper.time_class.parse(value.to_s) # Convert time to milliseconds since BSON stores dates with that accurracy, but Ruby uses microseconds Time.at((time.to_f * 1000).round / 1000.0).utc if time end end |