diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-07-25 09:42:36 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-07-25 09:46:39 +0900 |
commit | c02f3578c1e4896de9e6ca56b23a491f2ed677d8 (patch) | |
tree | 534c1f4d1a8b087310701da58d642256a0c735ae | |
parent | ec387c6dd975fecea69db2ed9ff0c090ac59cf83 (diff) | |
download | rails-c02f3578c1e4896de9e6ca56b23a491f2ed677d8.tar.gz rails-c02f3578c1e4896de9e6ca56b23a491f2ed677d8.tar.bz2 rails-c02f3578c1e4896de9e6ca56b23a491f2ed677d8.zip |
Normalize time value not to be affected by summer time
Follow up of #33358 for SQLite3.
3 files changed, 41 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb b/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb index 70de96326c..abedf01f10 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3/quoting.rb @@ -17,6 +17,7 @@ module ActiveRecord end def quoted_time(value) + value = value.change(year: 2000, month: 1, day: 1) quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "2000-01-01 ") end diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index 1c85ff5674..40b58e86bf 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -62,4 +62,30 @@ class SQLite3QuotingTest < ActiveRecord::SQLite3TestCase assert_equal "'2000-01-01 12:30:00.999999'", @conn.quote(type.serialize(value)) end + + def test_quoted_time_dst_utc + with_env_tz "America/New_York" do + with_timezone_config default: :utc do + t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") + + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getutc.to_s(:db).sub(/\A\d\d\d\d-\d\d-\d\d /, "2000-01-01 ") + + assert_equal expected, @conn.quoted_time(t) + end + end + end + + def test_quoted_time_dst_local + with_env_tz "America/New_York" do + with_timezone_config default: :local do + t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") + + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getlocal.to_s(:db).sub(/\A\d\d\d\d-\d\d-\d\d /, "2000-01-01 ") + + assert_equal expected, @conn.quoted_time(t) + end + end + end end diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index f875dc96f7..723fccc8d9 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -90,24 +90,28 @@ module ActiveRecord end def test_quoted_time_dst_utc - with_timezone_config default: :utc do - t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") + with_env_tz "America/New_York" do + with_timezone_config default: :utc do + t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") - expected = t.change(year: 2000, month: 1, day: 1) - expected = expected.getutc.to_s(:db).slice(11..-1) + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getutc.to_s(:db).slice(11..-1) - assert_equal expected, @quoter.quoted_time(t) + assert_equal expected, @quoter.quoted_time(t) + end end end def test_quoted_time_dst_local - with_timezone_config default: :local do - t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") + with_env_tz "America/New_York" do + with_timezone_config default: :local do + t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30") - expected = t.change(year: 2000, month: 1, day: 1) - expected = expected.getlocal.to_s(:db).slice(11..-1) + expected = t.change(year: 2000, month: 1, day: 1) + expected = expected.getlocal.to_s(:db).slice(11..-1) - assert_equal expected, @quoter.quoted_time(t) + assert_equal expected, @quoter.quoted_time(t) + end end end |