diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2018-07-18 15:31:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-18 15:31:50 -0400 |
commit | daee94da99605d89854660b63d98e4c1dc9a979d (patch) | |
tree | 8d2876eac7ba2ddfbd66207a8c06a4e2a178a0ac /activerecord | |
parent | 241bbf268cca61c42b61076deead699010068968 (diff) | |
parent | 35ca222cd31f066da344ae4205b1e37137f7a4b5 (diff) | |
download | rails-daee94da99605d89854660b63d98e4c1dc9a979d.tar.gz rails-daee94da99605d89854660b63d98e4c1dc9a979d.tar.bz2 rails-daee94da99605d89854660b63d98e4c1dc9a979d.zip |
Merge pull request #33358 from azbshiri/summer-time
Normalize the date component to 2000-01-01 automatically
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/quoting_test.rb | 26 |
2 files changed, 25 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index aec5fa6ba1..98b1348135 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -130,6 +130,7 @@ module ActiveRecord end def quoted_time(value) # :nodoc: + value = value.change(year: 2000, month: 1, day: 1) quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "") end diff --git a/activerecord/test/cases/quoting_test.rb b/activerecord/test/cases/quoting_test.rb index 92eb0c814f..f875dc96f7 100644 --- a/activerecord/test/cases/quoting_test.rb +++ b/activerecord/test/cases/quoting_test.rb @@ -71,8 +71,8 @@ module ActiveRecord with_timezone_config default: :utc do t = Time.now.change(usec: 0) - expected = t.getutc.change(year: 2000, month: 1, day: 1) - expected = expected.to_s(:db).sub("2000-01-01 ", "") + 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) end @@ -89,6 +89,28 @@ module ActiveRecord end end + def test_quoted_time_dst_utc + 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) + + assert_equal expected, @quoter.quoted_time(t) + 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") + + 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) + end + end + def test_quoted_time_crazy with_timezone_config default: :asdfasdf do t = Time.now.change(usec: 0) |