mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
convert times to local when quoting for db
This commit is contained in:
@@ -100,14 +100,6 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def quoted_date(value)
|
||||
if value.acts_like?(:time)
|
||||
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
|
||||
|
||||
if value.respond_to?(zone_conversion_method)
|
||||
value = value.send(zone_conversion_method)
|
||||
end
|
||||
end
|
||||
|
||||
value.to_s(:db)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,20 @@ require 'active_support/values/time_zone'
|
||||
|
||||
class Time
|
||||
DATE_FORMATS = {
|
||||
:db => "%Y-%m-%d %H:%M:%S",
|
||||
:db => lambda { |time|
|
||||
time = time.utc.to_time
|
||||
|
||||
if !defined?(ActiveRecord::Base.default_timezone) || ActiveRecord::Base.default_timezone == :local
|
||||
# our DB is in local time (ugh), so make sure the time object is
|
||||
# converted to local time before converting it to a db string
|
||||
#
|
||||
# also we have to do this ridiculous dance to ensure that we can
|
||||
# turn any given DateTime object into something in localtime.
|
||||
time = time.getlocal
|
||||
end
|
||||
|
||||
time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
},
|
||||
:number => "%Y%m%d%H%M%S",
|
||||
:time => "%H:%M",
|
||||
:short => "%d %b %H:%M",
|
||||
|
||||
Reference in New Issue
Block a user