From be0645dd176af5a77f42c07db122d33c58ed686f Mon Sep 17 00:00:00 2001 From: Nikitin Aleksandr Date: Thu, 28 Nov 2024 11:25:19 +0300 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20Date=5Ff?= =?UTF-8?q?rom=5FTimestampReference()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- micro/microfunctions.go | 12 ++++++++++++ micro/microfunctions_test.go | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/micro/microfunctions.go b/micro/microfunctions.go index e7ae955a..1ee3656c 100644 --- a/micro/microfunctions.go +++ b/micro/microfunctions.go @@ -10,6 +10,7 @@ import ( "fmt" "github.com/google/uuid" "golang.org/x/exp/constraints" + "google.golang.org/protobuf/types/known/timestamppb" "hash/fnv" "os/exec" "reflect" @@ -1274,3 +1275,14 @@ func InsertTextFrom(Text string, TextAdd string, IndexFrom int) string { Otvet := buffer.String() return Otvet } + +// Date_from_TimestampReference - возвращает дату из *Timestamp +func Date_from_TimestampReference(Timestamp *timestamppb.Timestamp) time.Time { + Otvet := time.Time{} + + if Timestamp != nil { + Otvet = Timestamp.AsTime() + } + + return Otvet +} diff --git a/micro/microfunctions_test.go b/micro/microfunctions_test.go index a604aee1..98151047 100644 --- a/micro/microfunctions_test.go +++ b/micro/microfunctions_test.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/ManyakRus/starter/contextmain" "github.com/google/uuid" + "google.golang.org/protobuf/types/known/timestamppb" "os" "reflect" "strings" @@ -1272,3 +1273,12 @@ func TestInsertTextFrom_MiddleOfString(t *testing.T) { t.Errorf("Expected %s, but got %s", expected, result) } } + +func TestDate_from_TimestampReference(t *testing.T) { + var Timestamp1 *timestamppb.Timestamp + + result := Date_from_TimestampReference(Timestamp1) + if result.IsZero() == false { + t.Errorf("Expected time.Time{}, but got %s", result) + } +}