Skip to content

Commit

Permalink
ptypes: More cleanly construct a Timestamp (#797)
Browse files Browse the repository at this point in the history
The existing code is much more complex.
  • Loading branch information
taralx authored and neild committed Feb 5, 2019
1 parent 3337d28 commit c823c79
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions ptypes/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c823c79

Please sign in to comment.