Skip to content

Commit

Permalink
expression: fix last_day function (#9750)
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored and zz-jason committed Mar 23, 2019
1 parent 8da8632 commit 6f0129f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6f0129f

Please sign in to comment.