From 41d6c9c42c505eda6b8c5cb1661af42dc999f2fe Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Tue, 5 Feb 2019 14:15:02 -0800 Subject: [PATCH] More cleanly construct a Timestamp The existing code is much more complex. --- ptypes/timestamp.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ptypes/timestamp.go b/ptypes/timestamp.go index 47f10dbc2c..8da0df01ac 100644 --- a/ptypes/timestamp.go +++ b/ptypes/timestamp.go @@ -111,11 +111,9 @@ func TimestampNow() *tspb.Timestamp { // 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