Class: Time

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

Class Method Summary collapse

Class Method Details

.from_mongo(value) ⇒ Object



137
138
139
140
141
142
143
# File 'lib/mongomapper/support.rb', line 137

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



150
151
152
153
154
155
156
# File 'lib/mongomapper/support.rb', line 150

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
# File 'lib/mongomapper/support.rb', line 133

def self.to_mongo(value)
  to_utc_time(value)
end

.to_utc_time(value) ⇒ Object



145
146
147
# File 'lib/mongomapper/support.rb', line 145

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