class ActiveSupport::TimeZone
def parts_to_time(parts, now)
def parts_to_time(parts, now) raise ArgumentError, "invalid date" if parts.nil? return if parts.empty? if parts[:seconds] time = Time.at(parts[:seconds]) else time = Time.new( parts.fetch(:year, now.year), parts.fetch(:mon, now.month), parts.fetch(:mday, parts[:year] || parts[:mon] ? 1 : now.day), parts.fetch(:hour, 0), parts.fetch(:min, 0), parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0), parts.fetch(:offset, 0) ) end if parts[:offset] || parts[:seconds] TimeWithZone.new(time.utc, self) else TimeWithZone.new(nil, self, time) end end