From 6f0129f4fead19137db81725f107515bfcadb938 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Sat, 23 Mar 2019 10:15:04 +0800 Subject: [PATCH] expression: fix last_day function (#9750) --- expression/builtin_time.go | 7 ++++--- expression/builtin_time_test.go | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/expression/builtin_time.go b/expression/builtin_time.go index bbd0411f54267..1b2de9f601b92 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -5583,9 +5583,10 @@ func (b *builtinLastDaySig) evalTime(row chunk.Row) (types.Time, bool, error) { return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, err)) } tm := arg.Time - year, month, day := tm.Year(), tm.Month(), 30 - if year == 0 && month == 0 && tm.Day() == 0 { - return types.Time{}, true, errors.Trace(handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String()))) + var day int + year, month := tm.Year(), tm.Month() + if month == 0 { + return types.Time{}, true, handleInvalidTimeError(b.ctx, types.ErrIncorrectDatetimeValue.GenWithStackByArgs(arg.String())) } day = types.GetLastDay(year, month) ret := types.Time{ diff --git a/expression/builtin_time_test.go b/expression/builtin_time_test.go index 06d4ad1663a09..c2721d8998637 100644 --- a/expression/builtin_time_test.go +++ b/expression/builtin_time_test.go @@ -2373,6 +2373,8 @@ func (s *testEvaluatorSuite) TestLastDay(c *C) { "0000-00-00", "1992-13-00", "2007-10-07 23:59:61", + "2005-00-00", + "2005-00-01", 123456789} for _, i := range testsNull {