提交 8e4ab75a 编写于 作者: R Ryuta Kamizono

Normalize time value not to be affected by summer time

Follow up of #33358 for SQLite3.
上级 b8674dc3
......@@ -17,6 +17,7 @@ def quote_column_name(name)
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
......
......@@ -62,4 +62,30 @@ def test_quoted_time_normalizes_date_qualified_time
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
......@@ -90,24 +90,28 @@ def test_quoted_time_local
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册