Skip to content

Commit

Permalink
expression: fix last_day incompatible with mysql (#11704)
Browse files Browse the repository at this point in the history
  • Loading branch information
TennyZhuang authored and ngaut committed Aug 10, 2019
1 parent 4995fe7 commit ff71c0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
9 changes: 4 additions & 5 deletions expression/builtin_time.go
Expand Up @@ -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,
}
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_time_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit ff71c0c

Please sign in to comment.