From ff71c0c746d0ad39ee46dd7bac2b150ee52ff6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E5=A4=A9=E7=BF=BC?= Date: Sat, 10 Aug 2019 19:12:38 +0800 Subject: [PATCH] expression: fix last_day incompatible with mysql (#11704) --- expression/builtin_time.go | 9 ++++----- expression/builtin_time_test.go | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index 39c45fdd7b13..d93eccbffc5f 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -6416,14 +6416,13 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { return types.Time{}, true, handleInvalidTimeError(b.ctx, err) } tm := arg.Time - var day int - year, month := tm.Year(), tm.Month() - if month == 0 { + year, month, day := tm.Year(), tm.Month(), tm.Day() + if month == 0 || day == 0 { return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) } - day = types.GetLastDay(year, month) + lastDay := types.GetLastDay(year, month) ret := types.Time{ - Time: types.FromDate(year, month, day, 0, 0, 0, 0), + Time: types.FromDate(year, month, lastDay, 0, 0, 0, 0), Type: mysql.TypeDate, Fsp: types.DefaultFsp, } diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index ed7e784cc231..f37af43e1861 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -2676,6 +2676,7 @@ func (s *testEvaluatorSuite) TestLastDay(c *C) { "2007-10-07 23:59:61", "2005-00-00", "2005-00-01", + "2243-01 00:00:00", 123456789} for _, i := range testsNull {