From 65f61b63f899376304b6259b21c9f0bfaf87203a Mon Sep 17 00:00:00 2001 From: tangenta Date: Mon, 19 Sep 2022 17:05:01 +0800 Subject: [PATCH] cherry pick #37206 to release-4.0 Signed-off-by: ti-srebot --- expression/builtin_time.go | 6 +++++ expression/builtin_time_test.go | 22 +++++++++++++++ expression/integration_test.go | 47 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 9f4cf3e5e6793..0551f3a5e7975 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -5710,7 +5710,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) diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 16fcaa8fbfaa9..8e209f934d79d 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -2637,6 +2637,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 { diff --git a/expression/integration_test.go b/expression/integration_test.go index 2a6b74b291fb5..88cbb2981c8a4 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -8507,7 +8507,54 @@ func (s *testIntegrationSuite) TestControlFunctionWithEnumOrSet(c *C) { tk.MustQuery("select * from e where if(e>2,e,e) and (if(e<3,0,e) or if(e>=2,0,e));").Sort().Check( testkit.Rows("a", "a")) +<<<<<<< HEAD // issue 24494 +======= + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1;") + tk.MustExec("create table t1(c1 bigint unsigned, c2 bigint unsigned);") + tk.MustExec("insert into t1 values(9223372036854775808, 9223372036854775809);") + tk.MustQuery("select greatest(c1, c2) from t1;").Sort().Check(testkit.Rows("9223372036854775809")) +} + +func TestIssue28739(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec(`USE test`) + tk.MustExec("SET time_zone = 'Europe/Vilnius'") + tk.MustQuery("SELECT UNIX_TIMESTAMP('2020-03-29 03:45:00')").Check(testkit.Rows("1585443600")) + tk.MustQuery("SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('2020-03-29 03:45:00'))").Check(testkit.Rows("2020-03-29 04:00:00")) + tk.MustExec(`DROP TABLE IF EXISTS t`) + tk.MustExec(`CREATE TABLE t (dt DATETIME NULL)`) + defer tk.MustExec(`DROP TABLE t`) + // Test the vector implememtation + tk.MustExec(`INSERT INTO t VALUES ('2021-10-31 02:30:00'), ('2021-03-28 02:30:00'), ('2020-10-04 02:15:00'), ('2020-03-29 03:45:00'), (NULL)`) + tk.MustQuery(`SELECT dt, UNIX_TIMESTAMP(dt) FROM t`).Sort().Check(testkit.Rows( + "2020-03-29 03:45:00 1585443600", + "2020-10-04 02:15:00 1601766900", + "2021-03-28 02:30:00 1616891400", + "2021-10-31 02:30:00 1635636600", + " ")) +} + +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) + tk.MustExec("use test") +>>>>>>> 8d5328ec4... expression: adjust DST for convert_tz() (#37206) tk.MustExec("drop table if exists t;") tk.MustExec("create table t(a int,b enum(\"b\",\"y\",\"1\"));") tk.MustExec("insert into t values(0,\"y\"),(1,\"b\"),(null,null),(2,\"1\");")