Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: gengliqi <gengliqiii@gmail.com>
  • Loading branch information
gengliqi committed Sep 26, 2024
1 parent 01797cb commit a3f949b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ func ParseTimeFromFloat64(ctx Context, f float64) (Time, error) {
}
if t.Type() == mysql.TypeDatetime {
// US part is only kept when the integral part is recognized as datetime.
fracPart := uint32((f - float64(intPart)) * 1000000.0)
fracPart := uint32(math.Round((f - float64(intPart)) * 1000000.0))
ct := t.CoreTime()
ct.setMicrosecond(fracPart)
t.SetCoreTime(ct)
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,8 @@ func TestParseTimeFromFloat64(t *testing.T) {
{0.0, mysql.TypeDate, 0, 0, 0, 0, 0, 0, 0, nil},
{20000102030405, mysql.TypeDatetime, 2000, 1, 2, 3, 4, 5, 0, nil},
{20000102030405.015625, mysql.TypeDatetime, 2000, 1, 2, 3, 4, 5, 15625, nil},
{20000102030405.0078125, mysql.TypeDatetime, 2000, 1, 2, 3, 4, 5, 7812, nil},
{20000102030405.0078125, mysql.TypeDatetime, 2000, 1, 2, 3, 4, 5, 7813, nil},
{121212131313.99998, mysql.TypeDatetime, 2012, 12, 12, 13, 13, 13, 999985, nil},
{2000, mysql.TypeDatetime, 0, 0, 0, 0, 0, 0, 0, types.ErrTruncatedWrongVal},
{20000000000000, mysql.TypeDatetime, 2000, 0, 0, 0, 0, 0, 0, nil},
}
Expand Down

0 comments on commit a3f949b

Please sign in to comment.