rate: fix rounding error in tokensFromDuration

tokensFromDuration performs a unit conversion by multiplying the limit
by the duration in seconds.

Make tokensFromDuration perform conversion by unit-wise multiplication
of limit by seconds and nanoseconds, instead of the conversion to
time.(Duration).Seconds that truncated the nanoseconds.

Fixes golang/go#34861

Change-Id: I94d290d3e32a87541d1702f2b58180270e1a9e96
Reviewed-on: https://go-review.googlesource.com/c/time/+/200900
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2 files changed
tree: 2cae15672f76393f6e561376682774ce0fcc8c6b
  1. rate/
  2. AUTHORS
  3. CONTRIBUTING.md
  4. CONTRIBUTORS
  5. go.mod
  6. LICENSE
  7. PATENTS
  8. README.md
README.md

Go Time

This repository provides supplementary Go time packages.

Download/Install

The easiest way to install is to run go get -u golang.org/x/time. You can also manually git clone the repository to $GOPATH/src/golang.org/x/time.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the time repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/time:” in the subject line, so it is easy to find.