Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make default_timezone a module instance variable #2190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def new_connection(config)
end

# Set session time zone to current time zone
if ActiveRecord::Base.default_timezone == :local
if ActiveRecord.default_timezone == :local
@raw_connection.setSessionTimeZone(time_zone)
elsif ActiveRecord::Base.default_timezone == :utc
elsif ActiveRecord.default_timezone == :utc
@raw_connection.setSessionTimeZone("UTC")
end

Expand Down Expand Up @@ -498,13 +498,13 @@ def get_ruby_value_from_result_set(rset, i, type_name, get_lob_value = true)
if dt = rset.getDATE(i)
d = dt.dateValue
t = dt.timeValue
Time.send(Base.default_timezone, d.year + 1900, d.month + 1, d.date, t.hours, t.minutes, t.seconds)
Time.send(ActiveRecord.default_timezone, d.year + 1900, d.month + 1, d.date, t.hours, t.minutes, t.seconds)
else
nil
end
when :TIMESTAMP, :TIMESTAMPTZ, :TIMESTAMPLTZ, :"TIMESTAMP WITH TIME ZONE", :"TIMESTAMP WITH LOCAL TIME ZONE"
ts = rset.getTimestamp(i)
ts && Time.send(Base.default_timezone, ts.year + 1900, ts.month + 1, ts.date, ts.hours, ts.minutes, ts.seconds,
ts && Time.send(ActiveRecord.default_timezone, ts.year + 1900, ts.month + 1, ts.date, ts.hours, ts.minutes, ts.seconds,
ts.nanos / 1000)
when :CLOB
get_lob_value ? lob_to_ruby_value(rset.getClob(i)) : rset.getClob(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ def create_time_with_default_timezone(value)
end
# code from Time.time_with_datetime_fallback
begin
Time.send(Base.default_timezone, year, month, day, hour, min, sec, usec)
Time.send(ActiveRecord.default_timezone, year, month, day, hour, min, sec, usec)
rescue
offset = Base.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
offset = ActiveRecord.default_timezone.to_sym == :local ? ::DateTime.local_offset : 0
::DateTime.civil(year, month, day, hour, min, sec, offset)
end
end
Expand Down Expand Up @@ -343,9 +343,9 @@ def self.new_connection(config)
conn.non_blocking = true if async
conn.prefetch_rows = prefetch_rows
conn.exec "alter session set cursor_sharing = #{cursor_sharing}" rescue nil if cursor_sharing
if ActiveRecord::Base.default_timezone == :local
if ActiveRecord.default_timezone == :local
conn.exec "alter session set time_zone = '#{time_zone}'" unless time_zone.blank?
elsif ActiveRecord::Base.default_timezone == :utc
elsif ActiveRecord.default_timezone == :utc
conn.exec "alter session set time_zone = '+00:00'"
end
conn.exec "alter session set current_schema = #{schema}" unless schema.blank?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _type_cast(value)
case value
when Type::OracleEnhanced::TimestampTz::Data, Type::OracleEnhanced::TimestampLtz::Data
if value.acts_like?(:time)
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
zone_conversion_method = ActiveRecord.default_timezone == :utc ? :getutc : :getlocal
value.respond_to?(zone_conversion_method) ? value.send(zone_conversion_method) : value
else
value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class ::Post < ActiveRecord::Base
end

it "should respect default_timezone = :utc than time_zone setting" do
# it expects that ActiveRecord::Base.default_timezone = :utc
# it expects that ActiveRecord.default_timezone = :utc
ActiveRecord::ConnectionAdapters::OracleEnhanced::Connection.create(CONNECTION_WITH_TIMEZONE_PARAMS)
post = Post.create!
created_at = post.created_at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ::TestEmployee < ActiveRecord::Base
end

after(:each) do
ActiveRecord::Base.default_timezone = :utc
ActiveRecord.default_timezone = :utc
end

it "should assign ISO string to date column" do
Expand Down Expand Up @@ -170,7 +170,7 @@ class ::TestEmployee < ActiveRecord::Base
end

it "should assign ISO time string to datetime column" do
ActiveRecord::Base.default_timezone = :local
ActiveRecord.default_timezone = :local
@employee = TestEmployee.create(
first_name: "First",
last_name: "Last",
Expand All @@ -182,7 +182,7 @@ class ::TestEmployee < ActiveRecord::Base
end

it "should assign NLS time string to datetime column" do
ActiveRecord::Base.default_timezone = :local
ActiveRecord.default_timezone = :local
@employee = TestEmployee.create(
first_name: "First",
last_name: "Last",
Expand All @@ -205,7 +205,7 @@ class ::TestEmployee < ActiveRecord::Base
end

it "should assign ISO date string to datetime column" do
ActiveRecord::Base.default_timezone = :local
ActiveRecord.default_timezone = :local
@employee = TestEmployee.create(
first_name: "First",
last_name: "Last",
Expand All @@ -217,7 +217,7 @@ class ::TestEmployee < ActiveRecord::Base
end

it "should assign NLS date string to datetime column" do
ActiveRecord::Base.default_timezone = :local
ActiveRecord.default_timezone = :local
@employee = TestEmployee.create(
first_name: "First",
last_name: "Last",
Expand Down
4 changes: 2 additions & 2 deletions spec/active_record/oracle_enhanced/type/timestamp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
include SchemaSpecHelper

before(:all) do
ActiveRecord::Base.default_timezone = :local
ActiveRecord.default_timezone = :local
ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
@conn = ActiveRecord::Base.connection
schema_define do
Expand All @@ -28,7 +28,7 @@

after(:all) do
@conn.drop_table :test_employees, if_exists: true
ActiveRecord::Base.default_timezone = :utc
ActiveRecord.default_timezone = :utc
end

describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
Expand Down