feat: TimestamppbToTime & TimeToTimestamppb.
This commit is contained in:
2
tag.bat
2
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user