]> Cypherpunks repositories - gostls13.git/commitdiff
time: print zero duration as 0s, not 0
authorRob Pike <r@golang.org>
Thu, 21 Apr 2016 21:53:19 +0000 (14:53 -0700)
committerRob Pike <r@golang.org>
Thu, 21 Apr 2016 22:07:59 +0000 (22:07 +0000)
There should be a unit, and s is the SI unit name, so use that.
The other obvious possibility is ns (nanosecond), but the fact
that durations are measured in nanoseconds is an internal detail.

Fixes #14058.

Change-Id: Id1f8f3c77088224d9f7cd643778713d5cc3be5d9
Reviewed-on: https://go-review.googlesource.com/22357
Reviewed-by: Robert Griesemer <gri@golang.org>
src/time/time.go
src/time/time_test.go

index 92d635eec5099ebdadaac0f97c5fe1ee56d1850a..d9dbd3449a04de2566606ba5ddea7bb30995a074 100644 (file)
@@ -476,7 +476,7 @@ func (d Duration) String() string {
                w--
                switch {
                case u == 0:
-                       return "0"
+                       return "0s"
                case u < uint64(Microsecond):
                        // print nanoseconds
                        prec = 0
index 5a5451b5b80ea27c5c1aaa4bc9d6eae970b434bf..b7ebb372967169123d0ae5c67fc150965531f684 100644 (file)
@@ -533,7 +533,7 @@ var durationTests = []struct {
        str string
        d   Duration
 }{
-       {"0", 0},
+       {"0s", 0},
        {"1ns", 1 * Nanosecond},
        {"1.1µs", 1100 * Nanosecond},
        {"2.2ms", 2200 * Microsecond},