You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
475 B
24 lines
475 B
package protobuf
|
|
|
|
import (
|
|
"github.com/golang/protobuf/ptypes"
|
|
"github.com/golang/protobuf/ptypes/timestamp"
|
|
"log"
|
|
"time"
|
|
)
|
|
|
|
func MarshalTime(t time.Time) *timestamp.Timestamp {
|
|
pt, err := ptypes.TimestampProto(t)
|
|
if err != nil {
|
|
log.Printf("time to proto time error: %v", err)
|
|
}
|
|
return pt
|
|
}
|
|
|
|
func UnMarshalTime(pt *timestamp.Timestamp) *time.Time {
|
|
t, err := ptypes.Timestamp(pt)
|
|
if err != nil {
|
|
log.Printf("time to proto time error: %v", err)
|
|
}
|
|
return &t
|
|
}
|