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

expression: adjust DST for convert_tz() (#37206) #37951

Closed
Closed
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
6 changes: 6 additions & 0 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -5773,7 +5773,13 @@ func (b *builtinConvertTzSig) convertTz(dt types.Time, fromTzStr, toTzStr string
return types.ZeroTime, true, nil
}

<<<<<<< HEAD
return types.NewTime(types.FromGoTime(t.In(toTz)), mysql.TypeDatetime, int8(b.tp.Decimal)), false, nil
=======
t, err := dt.AdjustedGoTime(fromTz)
if err != nil {
return types.ZeroTime, true, nil
>>>>>>> 8d5328ec4... expression: adjust DST for convert_tz() (#37206)
}
if fromTzMatched && toTzMatched {
t, err := dt.GoTime(time.Local)
Expand Down
22 changes: 22 additions & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2662,6 +2662,28 @@ func (s *testEvaluatorSuite) TestConvertTz(c *C) {
{nil, "GMT", "+00:00", true, ""},
{"2004-01-01 12:00:00", nil, "+00:00", true, ""},
{"2004-01-01 12:00:00", "GMT", nil, true, ""},
<<<<<<< HEAD
=======
{"2004-01-01 12:00:00", "GMT", "+10:00", true, "2004-01-01 22:00:00"},
{"2004-01-01 12:00:00", "+00:00", "MET", true, "2004-01-01 13:00:00"},
{"2004-01-01 12:00:00", "+00:00", "+14:00", true, "2004-01-02 02:00:00"},
{"2021-10-31 02:59:59", "+02:00", "Europe/Amsterdam", true, "2021-10-31 02:59:59"},
{"2021-10-31 03:00:00", "+01:00", "Europe/Amsterdam", true, "2021-10-31 03:00:00"},
{"2021-10-31 02:00:00", "+02:00", "Europe/Amsterdam", true, "2021-10-31 02:00:00"},
{"2021-10-31 02:59:59", "+02:00", "Europe/Amsterdam", true, "2021-10-31 02:59:59"},
{"2021-10-31 03:00:00", "+02:00", "Europe/Amsterdam", true, "2021-10-31 02:00:00"},
{"2021-10-31 02:30:00", "+01:00", "Europe/Amsterdam", true, "2021-10-31 02:30:00"},
{"2021-10-31 03:00:00", "+01:00", "Europe/Amsterdam", true, "2021-10-31 03:00:00"},
// Europe/Amsterdam during DST transition +02:00 -> +01:00, Summer to normal time,
// will be interpreted as +01:00, normal time.
{"2021-10-31 02:00:00", "Europe/Amsterdam", "+02:00", true, "2021-10-31 03:00:00"},
{"2021-10-31 02:59:59", "Europe/Amsterdam", "+02:00", true, "2021-10-31 03:59:59"},
{"2021-10-31 02:00:00", "Europe/Amsterdam", "+01:00", true, "2021-10-31 02:00:00"},
{"2021-10-31 03:00:00", "Europe/Amsterdam", "+01:00", true, "2021-10-31 03:00:00"},
{"2021-03-28 02:30:00", "Europe/Amsterdam", "UTC", true, "2021-03-28 01:00:00"},
{"2021-10-22 10:00:00", "Europe/Tallinn", "SYSTEM", true, t1.In(loc2).Format("2006-01-02 15:04:00")},
{"2021-10-22 10:00:00", "SYSTEM", "Europe/Tallinn", true, t2.In(loc1).Format("2006-01-02 15:04:00")},
>>>>>>> 8d5328ec4... expression: adjust DST for convert_tz() (#37206)
}
fc := funcs[ast.ConvertTz]
for _, test := range tests {
Expand Down
17 changes: 17 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10294,8 +10294,25 @@ func (s *testIntegrationSuite) TestIssue27831(c *C) {
tk.MustQuery("select /*+ inl_hash_join(t1) */ * from t t1 right join t t2 on t1.a=t2.b and t1.a= t2.c and t1.d=t2.d;").Check(testkit.Rows("a a 1 1 a a 1 1"))
}

<<<<<<< HEAD
func (s *testIntegrationSuite) TestIssue30326(c *C) {
tk := testkit.NewTestKit(c, s.store)
=======
func TestIssue30081(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`USE test`)
tk.MustQuery(`SELECT CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central');`).
Check(testkit.Rows(`2007-03-11 01:00:00`))
tk.MustQuery(`SELECT CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central');`).
Check(testkit.Rows(`2007-03-11 01:00:00`))
}

func TestIssue30326(t *testing.T) {
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
>>>>>>> 8d5328ec4... expression: adjust DST for convert_tz() (#37206)
tk.MustExec("use test")
tk.MustExec("drop table if exists t;")
tk.MustExec("create table t(a int);")
Expand Down