diff --git a/go/vt/vtgate/evalengine/compiler_asm.go b/go/vt/vtgate/evalengine/compiler_asm.go index 8b44cd69f1c..91c9915186c 100644 --- a/go/vt/vtgate/evalengine/compiler_asm.go +++ b/go/vt/vtgate/evalengine/compiler_asm.go @@ -3798,15 +3798,13 @@ func (asm *assembler) Fn_LAST_DAY() { func (asm *assembler) Fn_FROM_DAYS() { asm.emit(func(env *ExpressionEnv) int { arg := env.vm.stack[env.vm.sp-1].(*evalInt64) - y, m, d := datetime.MysqlDateFromDayNumber(int(arg.i)) - if y == 0 && m == 0 && d == 0 { - env.vm.stack[env.vm.sp-1] = env.vm.arena.newEvalDate(datetime.Date{}) - } else if y > 9999 { + d := datetime.DateFromDayNumber(int(arg.i)) + if d.Year() > 9999 { env.vm.stack[env.vm.sp-1] = nil - } else { - dt := datetime.NewDateFromStd(time.Date(int(y), time.Month(m), int(d), 0, 0, 0, 0, env.currentTimezone())) - env.vm.stack[env.vm.sp-1] = env.vm.arena.newEvalDate(dt) + return 1 } + + env.vm.stack[env.vm.sp-1] = env.vm.arena.newEvalDate(d) return 1 }, "FN FROM_DAYS INT64(SP-1)") } diff --git a/go/vt/vtgate/evalengine/fn_time.go b/go/vt/vtgate/evalengine/fn_time.go index 2c615002684..bf4bfb71934 100644 --- a/go/vt/vtgate/evalengine/fn_time.go +++ b/go/vt/vtgate/evalengine/fn_time.go @@ -1263,21 +1263,13 @@ func (b *builtinFromDays) eval(env *ExpressionEnv) (eval, error) { return nil, err } - days := evalToInt64(arg).i - y, m, d := datetime.MysqlDateFromDayNumber(int(days)) + d := datetime.DateFromDayNumber(int(evalToInt64(arg).i)) - // mysql returns 0000-00-00 for days below 366 and above 3652499 - if y == 0 && m == 0 && d == 0 { - return newEvalDate(datetime.Date{}, true), nil - } - - // mysql returns NULL if y is greater than 9999 - if y > 9999 { + // mysql returns NULL if year is greater than 9999 + if d.Year() > 9999 { return nil, nil } - - dt := datetime.NewDateFromStd(time.Date(int(y), time.Month(m), int(d), 0, 0, 0, 0, env.currentTimezone())) - return newEvalDate(dt, true), nil + return newEvalDate(d, true), nil } func (call *builtinFromDays) compile(c *compiler) (ctype, error) {