Class: Time
Class Method Summary collapse
- .from_mongo(value) ⇒ Object
-
.to_local_time(value) ⇒ Object
make sure we have a time and that it is local.
- .to_mongo(value) ⇒ Object
- .to_utc_time(value) ⇒ Object
Class Method Details
.from_mongo(value) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/mongo_mapper/support.rb', line 150 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
163 164 165 166 167 168 169 |
# File 'lib/mongo_mapper/support.rb', line 163 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
142 143 144 145 146 147 148 |
# File 'lib/mongo_mapper/support.rb', line 142 def self.to_mongo(value) if value.nil? || value == '' nil else to_utc_time(value) end end |
.to_utc_time(value) ⇒ Object
158 159 160 |
# File 'lib/mongo_mapper/support.rb', line 158 def self.to_utc_time(value) to_local_time(value).try(:utc) end |