From 5ea3241ac966d126509aeef462fcd97488b9ef9d Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Tue, 22 Aug 2023 18:04:30 +0300
Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?=
 =?UTF-8?q?=D0=BE=20=D0=9F=D0=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/schema/field/timestamp.go      |  9 ++++-----
 pkg/schema/field/timestamp_test.go | 10 +++++-----
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/pkg/schema/field/timestamp.go b/pkg/schema/field/timestamp.go
index 29b29912..70d28b61 100644
--- a/pkg/schema/field/timestamp.go
+++ b/pkg/schema/field/timestamp.go
@@ -3,10 +3,10 @@ package field
 import (
 	"context"
 	"fmt"
-	"reflect"
 	"time"
 )
 
+var zeroTime = time.Time{}
 var timestampType = &TimestampType{}
 
 type TimestampParameters struct{}
@@ -31,13 +31,12 @@ func (TimestampType) IsEmpty(v interface{}) bool {
 func (TimestampType) Decode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
 	switch i := v.(type) {
 	case nil:
-		return 0, nil
+		return nil, nil
 	case string:
 		duration, err := time.ParseDuration(i)
 		if err == nil {
 			return duration.Nanoseconds(), nil
 		}
-		zeroTime := time.Time{}
 		t, err := time.Parse(time.TimeOnly, i)
 
 		if err == nil {
@@ -68,14 +67,14 @@ func toTimestamp(i interface{}) (interface{}, error) {
 	case uint32:
 		return int64(v), nil
 	default:
-		return 0, fmt.Errorf("unsupported value type: \"%s\"", reflect.ValueOf(v).Kind())
+		return 0, fmt.Errorf("unsupported value type: \"%T\"", v)
 	}
 }
 
 func (TimestampType) Encode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
 	switch i := v.(type) {
 	case nil:
-		return 0, nil
+		return nil, nil
 	default:
 		return toTimestamp(i)
 	}
diff --git a/pkg/schema/field/timestamp_test.go b/pkg/schema/field/timestamp_test.go
index 67be1abb..0875a699 100644
--- a/pkg/schema/field/timestamp_test.go
+++ b/pkg/schema/field/timestamp_test.go
@@ -29,10 +29,10 @@ func TestTimestamp_Decode(t *testing.T) {
 		{"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, 0, false, ""},
+		{"Correct", Timestamp(), nil, nil, false, ""},
 
 		{"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: \"slice\""},                               // #1
+		{"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
@@ -65,9 +65,9 @@ func TestTimestamp_Encode(t *testing.T) {
 		{"Correct", Timestamp(), 2, int64(2), false, ""},         // #1
 		{"Correct", Timestamp(), uint64(2), int64(2), false, ""}, // #2
 
-		{"Wrong data", Timestamp(), "", nil, true, "encode error: unsupported value type: \"string\""},        // #0
-		{"Wrong data", Timestamp(), []byte(""), nil, true, "encode error: unsupported value type: \"slice\""}, // #1
-		{"Wrong data", Timestamp(), 2.2, nil, true, "encode error: unsupported value type: \"float64\""},      // #2
+		{"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