From a3f949bdc699378d1f4d2299ffa4b2b2e49561b3 Mon Sep 17 00:00:00 2001 From: gengliqi Date: Thu, 26 Sep 2024 17:20:49 +0800 Subject: [PATCH] fix Signed-off-by: gengliqi --- pkg/types/time.go | 2 +- pkg/types/time_test.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/types/time.go b/pkg/types/time.go index e2d915df86489..778ed31ee66a7 100644 --- a/pkg/types/time.go +++ b/pkg/types/time.go @@ -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) diff --git a/pkg/types/time_test.go b/pkg/types/time_test.go index d015f5fb209b3..00484a84a0225 100644 --- a/pkg/types/time_test.go +++ b/pkg/types/time_test.go @@ -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}, }