From f69d50f9a0f1ac57a33e04e8cb03ef45a8aa4725 Mon Sep 17 00:00:00 2001 From: ko_oler <kooler89@gmail.com> Date: Thu, 31 Aug 2023 14:06:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BA=D0=BE=D0=B4=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D0=B4=D0=B5=D0=BA=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=82=D0=B8=D0=BF=D0=B0=20float=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8F=20Timestamp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/schema/field/timestamp.go | 4 ++++ pkg/schema/field/timestamp_test.go | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/schema/field/timestamp.go b/pkg/schema/field/timestamp.go index 7f89aefc..694d477e 100644 --- a/pkg/schema/field/timestamp.go +++ b/pkg/schema/field/timestamp.go @@ -50,6 +50,10 @@ func toTimestamp(i interface{}) (interface{}, error) { return int64(v), nil case uint32: return int64(v), nil + case float32: + return int64(v), nil + case float64: + return int64(v), nil default: return nil, fmt.Errorf("unsupported value type: \"%T\"", i) } diff --git a/pkg/schema/field/timestamp_test.go b/pkg/schema/field/timestamp_test.go index 0875a699..87c756f1 100644 --- a/pkg/schema/field/timestamp_test.go +++ b/pkg/schema/field/timestamp_test.go @@ -23,19 +23,19 @@ func TestTimestamp_Decode(t *testing.T) { {"Correct", Timestamp(), "13h10m44s", int64(47444000000000), false, ""}, // #3 {"Correct", Timestamp(), "24h", int64(86400000000000), false, ""}, // #4 {"Correct", Timestamp(), "2.5h", int64(9000000000000), false, ""}, // #5 - {"Correct", Timestamp(), "-5h", int64(-18000000000000), false, ""}, // #5 - {"Correct", Timestamp(), "13:10:44", int64(47444000000000), false, ""}, // #6 - {"Correct", Timestamp(), "23:59:59", int64(86399000000000), false, ""}, // #7 - {"Correct", Timestamp(), "00:00:00", int64(0), false, ""}, // #8 - {"Correct", Timestamp(), "00:00:01", int64(1000000000), false, ""}, // #8 - {"Correct", Timestamp(), uint64(2), int64(2), false, ""}, - {"Correct", Timestamp(), nil, nil, false, ""}, + {"Correct", Timestamp(), "-5h", int64(-18000000000000), false, ""}, // #6 + {"Correct", Timestamp(), "13:10:44", int64(47444000000000), false, ""}, // #7 + {"Correct", Timestamp(), "23:59:59", int64(86399000000000), false, ""}, // #8 + {"Correct", Timestamp(), "00:00:00", int64(0), false, ""}, // #9 + {"Correct", Timestamp(), "00:00:01", int64(1000000000), false, ""}, // #10 + {"Correct", Timestamp(), uint64(2), int64(2), false, ""}, // #11 + {"Correct", Timestamp(), nil, nil, false, ""}, // #12 + {"Correct", Timestamp(), 2.0, int64(2), false, ""}, // #13 {"Wrong data", Timestamp(), "", nil, true, "decode error: parsing time \"\" as \"15:04:05\": cannot parse \"\" as \"15\""}, // #0 {"Wrong data", Timestamp(), []byte(""), nil, true, "decode error: unsupported value type: \"[]uint8\""}, // #1 - {"Wrong data", Timestamp(), 2.2, nil, true, "decode error: unsupported value type: \"float64\""}, // #2 - {"Wrong data", Timestamp(), "13:10", nil, true, "decode error: parsing time \"13:10\" as \"15:04:05\": cannot parse \"\" as \":\""}, // #3 - {"Wrong data", Timestamp(), "24:00:00", nil, true, "decode error: parsing time \"24:00:00\": hour out of range"}, // #4 + {"Wrong data", Timestamp(), "13:10", nil, true, "decode error: parsing time \"13:10\" as \"15:04:05\": cannot parse \"\" as \":\""}, // #2 + {"Wrong data", Timestamp(), "24:00:00", nil, true, "decode error: parsing time \"24:00:00\": hour out of range"}, // #3 } for _, tt := range tests { @@ -64,10 +64,10 @@ func TestTimestamp_Encode(t *testing.T) { {"Correct", Timestamp(), int64(2), int64(2), false, ""}, // #0 {"Correct", Timestamp(), 2, int64(2), false, ""}, // #1 {"Correct", Timestamp(), uint64(2), int64(2), false, ""}, // #2 + {"Correct", Timestamp(), 2.0, int64(2), false, ""}, // #3 {"Wrong data", Timestamp(), "", nil, true, "encode error: unsupported value type: \"string\""}, // #0 {"Wrong data", Timestamp(), []byte(""), nil, true, "encode error: unsupported value type: \"[]uint8\""}, // #1 - {"Wrong data", Timestamp(), 2.2, nil, true, "encode error: unsupported value type: \"float64\""}, // #2 } for _, tt := range tests { -- GitLab