From b48c9bb5780921d2e558760219f2dec7e91c7668 Mon Sep 17 00:00:00 2001 From: Charlie Somerville Date: Thu, 12 Jun 2014 19:14:17 +1000 Subject: [PATCH] respect ActiveRecord::Base.default_timezone --- .../core_ext/time/conversions.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index 73f65ae6ef..3fb3a85e64 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -5,12 +5,18 @@ module Time #:nodoc: module Conversions DATE_FORMATS = { :db => lambda { |time| - # 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.utc.to_time.getlocal.strftime("%Y-%m-%d %H:%M:%S") + 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", -- GitLab