Class: Time
Class Method Summary collapse
Class Method Details
.from_mongo(value) ⇒ Object
171 172 173 174 175 176 177 |
# File 'lib/mongo_mapper/support.rb', line 171 def self.from_mongo(value) if Time.try(:zone).present? && value.present? value.in_time_zone(Time.zone) else value end end |
.to_mongo(value) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/mongo_mapper/support.rb', line 160 def self.to_mongo(value) if value.nil? || value == '' nil else time_class = Time.try(:zone).present? ? Time.zone : Time time = value.is_a?(Time) ? value : time_class.parse(value.to_s) # strip milliseconds as Ruby does micro and bson does milli and rounding rounded wrong at(time.to_i).utc if time end end |