From 9d6af0a401b9fd955fbefeeab243a66b40233d42 Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Tue, 22 Aug 2023 18:08:54 +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 | 44 +++++++++++++++++------------------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/pkg/schema/field/timestamp.go b/pkg/schema/field/timestamp.go
index a9689954..cc13bbea 100644
--- a/pkg/schema/field/timestamp.go
+++ b/pkg/schema/field/timestamp.go
@@ -30,28 +30,10 @@ func (TimestampType) IsEmpty(v interface{}) bool {
 	return v == 0 || v == nil
 }
 
-func (TimestampType) Decode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
-	switch i := v.(type) {
-	case nil:
-		return nil, nil
-	case string:
-		duration, err := time.ParseDuration(i)
-		if err == nil {
-			return duration.Nanoseconds(), nil
-		}
-		t, err := time.Parse(time.TimeOnly, i)
-
-		if err == nil {
-			return t.AddDate(1, 0, 0).Sub(zeroTime).Nanoseconds(), nil
-		}
-		return nil, err
-	default:
-		return toTimestamp(i)
-	}
-}
-
 func toTimestamp(i interface{}) (interface{}, error) {
 	switch v := i.(type) {
+	case nil:
+		return nil, nil
 	case int64:
 		return v, nil
 	case int:
@@ -69,14 +51,30 @@ func toTimestamp(i interface{}) (interface{}, error) {
 	case uint32:
 		return int64(v), nil
 	default:
-		return 0, fmt.Errorf("unsupported value type: \"%T\"", v)
+		return 0, fmt.Errorf("unsupported value type: \"%T\"", i)
+	}
+}
+
+func (TimestampType) Decode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
+	switch i := v.(type) {
+	case string:
+		duration, err := time.ParseDuration(i)
+		if err == nil {
+			return duration.Nanoseconds(), nil
+		}
+		t, err := time.Parse(time.TimeOnly, i)
+
+		if err == nil {
+			return t.AddDate(1, 0, 0).Sub(zeroTime).Nanoseconds(), nil
+		}
+		return nil, err
+	default:
+		return toTimestamp(i)
 	}
 }
 
 func (TimestampType) Encode(_ context.Context, _ *Field, v interface{}) (interface{}, error) {
 	switch i := v.(type) {
-	case nil:
-		return nil, nil
 	default:
 		return toTimestamp(i)
 	}
-- 
GitLab