Skip to content

Commit 3337d28

Browse files
taralxneild
authored andcommitted
ptypes: Avoid assuming time.Duration is nanoseconds (#796)
It is spec'd that way, but best practice is to avoid it.
1 parent 347cf4a commit 3337d28

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ptypes/duration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func Duration(p *durpb.Duration) (time.Duration, error) {
8282
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
8383
}
8484
if p.Nanos != 0 {
85-
d += time.Duration(p.Nanos)
85+
d += time.Duration(p.Nanos) * time.Nanosecond
8686
if (d < 0) != (p.Nanos < 0) {
8787
return 0, fmt.Errorf("duration: %v is out of range for time.Duration", p)
8888
}

0 commit comments

Comments
 (0)