Class: Time

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

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/mongo_mapper/support.rb', line 141

def self.from_mongo(value)
  if Time.respond_to?(:zone) && Time.zone && value.present?
    value.in_time_zone(Time.zone)
  else
    value
  end
end

.to_local_time(value) ⇒ Object

make sure we have a time and that it is local



154
155
156
157
158
159
160
# File 'lib/mongo_mapper/support.rb', line 154

def self.to_local_time(value)
  if Time.respond_to?(:zone) && Time.zone
    Time.zone.parse(value.to_s)
  else
    Time.parse(value.to_s)
  end
end

.to_mongo(value) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/mongo_mapper/support.rb', line 133

def self.to_mongo(value)
  if value.nil? || value == ''
    nil
  else
    to_utc_time(value)
  end
end

.to_utc_time(value) ⇒ Object



149
150
151
# File 'lib/mongo_mapper/support.rb', line 149

def self.to_utc_time(value)
  to_local_time(value).try(:utc)
end