From 4e084cc4b55f949ea8ba988bdf3114e51f399818 Mon Sep 17 00:00:00 2001 From: tx7do Date: Sun, 21 Apr 2024 22:20:59 +0800 Subject: [PATCH] feat: TimestamppbToTime & TimeToTimestamppb. --- tag.bat | 2 +- timeutil/trans.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tag.bat b/tag.bat index e563ce9..84bb5c0 100644 --- a/tag.bat +++ b/tag.bat @@ -1,4 +1,4 @@ -git tag v1.1.9 +git tag v1.1.10 git tag bank_card/v1.1.1 git tag entgo/v1.1.13 git tag geoip/v1.1.1 diff --git a/timeutil/trans.go b/timeutil/trans.go index 9f1a872..7ae346c 100644 --- a/timeutil/trans.go +++ b/timeutil/trans.go @@ -3,6 +3,8 @@ package util import ( "time" + "google.golang.org/protobuf/types/known/timestamppb" + "github.com/tx7do/go-utils/trans" ) @@ -114,3 +116,19 @@ func TimeToDateString(tm *time.Time) *string { } return trans.String(tm.Format(DateLayout)) } + +// TimestamppbToTime timestamppb.Timestamp -> time.Time +func TimestamppbToTime(tm *timestamppb.Timestamp) *time.Time { + if tm != nil { + return trans.Ptr(tm.AsTime()) + } + return nil +} + +// TimeToTimestamppb time.Time -> timestamppb.Timestamp +func TimeToTimestamppb(tm *time.Time) *timestamppb.Timestamp { + if tm != nil { + return timestamppb.New(*tm) + } + return nil +}