Преглед изворни кода

ptypes: More cleanly construct a Timestamp (#797)

The existing code is much more complex.
JP Sugarbroad пре 7 година
родитељ
комит
c823c79ea1
1 измењених фајлова са 2 додато и 4 уклоњено
  1. 2 4
      ptypes/timestamp.go

+ 2 - 4
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