From b4cc3e48934afaefbf6d5f65b5414b8b65117234 Mon Sep 17 00:00:00 2001 From: b41sh Date: Thu, 21 Mar 2019 15:00:29 +0800 Subject: [PATCH] fix `str_to_date` func compatible issues 9773 (#9819) --- expression/builtin_time_test.go | 2 ++ types/time.go | 4 ++++ 2 files changed, 6 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] 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 }