Skip to content

Commit c823c79

Browse files
taralxneild
authored andcommitted
ptypes: More cleanly construct a Timestamp (#797)
The existing code is much more complex.
1 parent 3337d28 commit c823c79

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

ptypes/timestamp.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,9 @@ func TimestampNow() *tspb.Timestamp {
111111
// TimestampProto converts the time.Time to a google.protobuf.Timestamp proto.
112112
// It returns an error if the resulting Timestamp is invalid.
113113
func TimestampProto(t time.Time) (*tspb.Timestamp, error) {
114-
seconds := t.Unix()
115-
nanos := int32(t.Sub(time.Unix(seconds, 0)))
116114
ts := &tspb.Timestamp{
117-
Seconds: seconds,
118-
Nanos: nanos,
115+
Seconds: t.Unix(),
116+
Nanos: int32(t.Nanosecond()),
119117
}
120118
if err := validateTimestamp(ts); err != nil {
121119
return nil, err

0 commit comments

Comments
 (0)