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

2 years ago
  1. package protobuf
  2. import (
  3. "github.com/golang/protobuf/ptypes"
  4. "github.com/golang/protobuf/ptypes/timestamp"
  5. "log"
  6. "time"
  7. )
  8. func MarshalTime(t time.Time) *timestamp.Timestamp {
  9. pt, err := ptypes.TimestampProto(t)
  10. if err != nil {
  11. log.Printf("time to proto time error: %v", err)
  12. }
  13. return pt
  14. }
  15. func UnMarshalTime(pt *timestamp.Timestamp) *time.Time {
  16. t, err := ptypes.Timestamp(pt)
  17. if err != nil {
  18. log.Printf("time to proto time error: %v", err)
  19. }
  20. return &t
  21. }