Class: Time
Class Method Summary collapse
Class Method Details
.from_mongo(value) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/mongo_mapper/support.rb', line 194 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
184 185 186 187 188 189 190 191 192 |
# File 'lib/mongo_mapper/support.rb', line 184 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 |