Skip to content

Commit daee94d

Browse files
authored
Merge pull request rails#33358 from azbshiri/summer-time
Normalize the date component to 2000-01-01 automatically
2 parents 241bbf2 + 35ca222 commit daee94d

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

activerecord/lib/active_record/connection_adapters/abstract/quoting.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def quoted_date(value)
130130
end
131131

132132
def quoted_time(value) # :nodoc:
133+
value = value.change(year: 2000, month: 1, day: 1)
133134
quoted_date(value).sub(/\A\d\d\d\d-\d\d-\d\d /, "")
134135
end
135136

activerecord/test/cases/quoting_test.rb

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def test_quoted_time_utc
7171
with_timezone_config default: :utc do
7272
t = Time.now.change(usec: 0)
7373

74-
expected = t.getutc.change(year: 2000, month: 1, day: 1)
75-
expected = expected.to_s(:db).sub("2000-01-01 ", "")
74+
expected = t.change(year: 2000, month: 1, day: 1)
75+
expected = expected.getutc.to_s(:db).slice(11..-1)
7676

7777
assert_equal expected, @quoter.quoted_time(t)
7878
end
@@ -89,6 +89,28 @@ def test_quoted_time_local
8989
end
9090
end
9191

92+
def test_quoted_time_dst_utc
93+
with_timezone_config default: :utc do
94+
t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30")
95+
96+
expected = t.change(year: 2000, month: 1, day: 1)
97+
expected = expected.getutc.to_s(:db).slice(11..-1)
98+
99+
assert_equal expected, @quoter.quoted_time(t)
100+
end
101+
end
102+
103+
def test_quoted_time_dst_local
104+
with_timezone_config default: :local do
105+
t = Time.new(2000, 7, 1, 0, 0, 0, "+04:30")
106+
107+
expected = t.change(year: 2000, month: 1, day: 1)
108+
expected = expected.getlocal.to_s(:db).slice(11..-1)
109+
110+
assert_equal expected, @quoter.quoted_time(t)
111+
end
112+
end
113+
92114
def test_quoted_time_crazy
93115
with_timezone_config default: :asdfasdf do
94116
t = Time.now.change(usec: 0)

0 commit comments

Comments
 (0)