Class: Time

Inherits:
Object show all
Defined in:
lib/mongo_mapper/support.rb

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/mongo_mapper/support.rb', line 178

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



169
170
171
172
173
174
175
176
# File 'lib/mongo_mapper/support.rb', line 169

def self.to_mongo(value)
  if value.nil? || value == ''
    nil
  else
    time = MongoMapper.time_class.parse(value.to_s)
    time && time.utc
  end
end