Class: Time
Class Method Summary collapse
Class Method Details
.from_mongo(value) ⇒ Object
199 200 201 202 203 204 205 |
# File 'lib/novelys_mongo_mapper/support.rb', line 199 def self.from_mongo(value) if MongoMapper.use_time_zone? && value.present? value.in_time_zone(Time.zone) else value end end |
.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 |