feat: TimestamppbToTime & TimeToTimestamppb.

This commit is contained in:
tx7do
2024-04-21 22:20:59 +08:00
parent ce853c6b87
commit 4e084cc4b5
2 changed files with 19 additions and 1 deletions

View File

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

View File

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