ptypes: More cleanly construct a Timestamp (#797)
The existing code is much more complex.
diff --git a/ptypes/timestamp.go b/ptypes/timestamp.go
index 47f10db..8da0df0 100644
--- a/ptypes/timestamp.go
+++ b/ptypes/timestamp.go
@@ -111,11 +111,9 @@
// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
// It returns an error if the resulting Timestamp is invalid.
func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
- seconds := t.Unix()
- nanos := int32(t.Sub(time.Unix(seconds, 0)))
ts := &tspb.Timestamp{
- Seconds: seconds,
- Nanos: nanos,
+ Seconds: t.Unix(),
+ Nanos: int32(t.Nanosecond()),
}
if err := validateTimestamp(ts); err != nil {
return nil, err