From c9fba33ac4ab3a08e37fd03d590bea52b768719a Mon Sep 17 00:00:00 2001 From: b41sh Date: Wed, 20 Mar 2019 11:38:53 +0800 Subject: [PATCH 1/2] fix `str_to_date` func compatible issues 9773 --- types/time.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/time.go b/types/time.go index 87b51266094e2..1fd685cb398e0 100644 --- a/types/time.go +++ b/types/time.go @@ -2047,6 +2047,9 @@ func mysqlTimeFix(t *MysqlTime, ctx map[string]int) error { _ = yearOfDay } if valueAMorPm, ok := ctx["%p"]; ok { + if _, ok := ctx["%H"]; ok { + return ErrInvalidTimeFormat.GenWithStackByArgs(t) + } if t.hour == 0 { return ErrInvalidTimeFormat.GenWithStackByArgs(t) } @@ -2429,6 +2432,7 @@ func hour24Numeric(t *MysqlTime, input string, ctx map[string]int) (string, bool return input, false } t.hour = v + ctx["%H"] = v return input[length:], true } From 0966b5cb3916e711660c057e8fdc140bd53ac9b7 Mon Sep 17 00:00:00 2001 From: b41sh Date: Wed, 20 Mar 2019 16:11:49 +0800 Subject: [PATCH 2/2] Add unit test for StrToDate Function --- expression/builtin_time_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index b2669ffb5a062..72f1b3b16e5f8 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -1269,6 +1269,8 @@ func (s *testEvaluatorSuite) TestStrToDate(c *C) { {"15-01-2001 1:59:58.", "%d-%m-%Y %H:%i:%s.%f", true, time.Date(2001, 1, 15, 1, 59, 58, 000000000, time.Local)}, {"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%s.%f", true, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)}, {"15-01-2001 1:9:8.999", "%d-%m-%Y %H:%i:%S.%f", true, time.Date(2001, 1, 15, 1, 9, 8, 999000000, time.Local)}, + {"2003-01-02 10:11:12 PM", "%Y-%m-%d %H:%i:%S %p", false, time.Time{}}, + {"10:20:10AM", "%H:%i:%S%p", false, time.Time{}}, } fc := funcs[ast.StrToDate]