Class: Time

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

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



195
196
197
198
199
200
201
# File 'lib/mongo_mapper/support.rb', line 195

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



186
187
188
189
190
191
192
193
# File 'lib/mongo_mapper/support.rb', line 186

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