1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-24 22:53:52 +02:00

сделал Date_from_TimestampReference()

This commit is contained in:
Nikitin Aleksandr
2024-11-28 11:25:19 +03:00
parent eabb926139
commit be0645dd17
2 changed files with 22 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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)
}
}