Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed Mar 28, 2019
1 parent c7f8ed4 commit 4149a28
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions expression/builtin_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,10 @@ var (
_ builtinFunc = &builtinSubDateDatetimeDecimalSig{}
)

func convertTimeToMysqlTime(t time.Time, fsp int, useTrunc bool) (types.Time, error) {
func convertTimeToMysqlTime(t time.Time, fsp int, roundMode types.RoundMode) (types.Time, error) {
var tr time.Time
var err error
if useTrunc {
if roundMode == types.ModeTruncate {
tr, err = types.TruncateFrac(t, fsp)
} else {
tr, err = types.RoundFrac(t, fsp)
Expand Down Expand Up @@ -1611,7 +1611,7 @@ func evalFromUnixTime(ctx sessionctx.Context, fsp int, row chunk.Row, arg Expres

sc := ctx.GetSessionVars().StmtCtx
tmp := time.Unix(integralPart, fractionalPart).In(sc.TimeZone)
t, err := convertTimeToMysqlTime(tmp, fsp, false)
t, err := convertTimeToMysqlTime(tmp, fsp, types.ModeHalfEven)
if err != nil {
return res, true, err
}
Expand Down Expand Up @@ -1933,7 +1933,7 @@ func (b *builtinSysDateWithFspSig) evalTime(row chunk.Row) (d types.Time, isNull

loc := b.ctx.GetSessionVars().Location()
now := time.Now().In(loc)
result, err := convertTimeToMysqlTime(now, int(fsp), false)
result, err := convertTimeToMysqlTime(now, int(fsp), types.ModeHalfEven)
if err != nil {
return types.Time{}, true, err
}
Expand All @@ -1955,7 +1955,7 @@ func (b *builtinSysDateWithoutFspSig) Clone() builtinFunc {
func (b *builtinSysDateWithoutFspSig) evalTime(row chunk.Row) (d types.Time, isNull bool, err error) {
tz := b.ctx.GetSessionVars().Location()
now := time.Now().In(tz)
result, err := convertTimeToMysqlTime(now, 0, false)
result, err := convertTimeToMysqlTime(now, 0, types.ModeHalfEven)
if err != nil {
return types.Time{}, true, err
}
Expand Down Expand Up @@ -2284,7 +2284,7 @@ func evalUTCTimestampWithFsp(ctx sessionctx.Context, fsp int) (types.Time, bool,
if nowTs.Equal(time.Time{}) {
*nowTs = time.Now()
}
result, err := convertTimeToMysqlTime(nowTs.UTC(), fsp, false)
result, err := convertTimeToMysqlTime(nowTs.UTC(), fsp, types.ModeHalfEven)
if err != nil {
return types.Time{}, true, err
}
Expand Down Expand Up @@ -2384,7 +2384,7 @@ func evalNowWithFsp(ctx sessionctx.Context, fsp int) (types.Time, bool, error) {
// +----------------------------+-------------------------+---------------------+
// | 2019-03-25 15:57:56.612966 | 2019-03-25 15:57:56.612 | 2019-03-25 15:57:56 |
// +----------------------------+-------------------------+---------------------+
result, err := convertTimeToMysqlTime(*sysTs, fsp, true)
result, err := convertTimeToMysqlTime(*sysTs, fsp, types.ModeTruncate)
if err != nil {
return types.Time{}, true, err
}
Expand Down

0 comments on commit 4149a28

Please sign in to comment.