Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 28 lines (26 sloc) 0.63 kb
# encoding: UTF-8
module MongoMapper
module Extensions
module Time
def to_mongo(value)
if !value.present?
nil
else
time_class = ::Time.try(:zone) || ::Time
time = value.is_a?(::Time) ? value : time_class.parse(value.to_s)
at(time.to_f).utc if time # ensure milliseconds are preserved with to_f (issue #308)
end
end
def from_mongo(value)
if value and zone = ::Time.try(:zone)
value.in_time_zone(zone)
else
value
end
end
end
end
end
class Time
extend MongoMapper::Extensions::Time
end
Jump to Line
Something went wrong with that request. Please try again.