Skip to content

Instantly share code, notes, and snippets.

@kennyj
Last active December 23, 2015 14:49
Show Gist options
  • Save kennyj/6651773 to your computer and use it in GitHub Desktop.
Save kennyj/6651773 to your computer and use it in GitHub Desktop.
fixes 12278 for rails 3.2
$ vim config/initializers/fix_12278.rb
require 'active_record/connection_adapters/column'
module ActiveRecord
module ConnectionAdapters
class Column
class << self
def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil)
# Treat 0000-00-00 00:00:00 as nil.
return nil if year.nil? || (year == 0 && mon == 0 && mday == 0)
unless offset
Time.time_with_datetime_fallback(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
else
time = Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil
return nil unless time
time -= offset
time.send("get#{Base.default_timezone}")
end
end
def fallback_string_to_time(string)
time_hash = Date._parse(string)
time_hash[:sec_fraction] = microseconds(time_hash)
new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset))
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment