]> Cypherpunks repositories - gostls13.git/commitdiff
time: parse 1us in Nanoseconds example
authorAlberto Donizetti <alb.donizetti@gmail.com>
Sun, 24 Feb 2019 21:48:46 +0000 (22:48 +0100)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Tue, 26 Feb 2019 17:22:58 +0000 (17:22 +0000)
The example for Nanoseconds() currently reads:

  ns, _ := time.ParseDuration("1000ns")
  fmt.Printf("one microsecond has %d nanoseconds.", ns.Nanoseconds())

which is not terribly interesting: it seems obvious that parsing
"1000ns" and then calling Nanoseconds() will print 1000. The mention
of microseconds in the text suggests that the author's intention was,
instead, to write something like this:

  u, _ := time.ParseDuration("1us")

i.e. build a time value by parsing 1 microsecond, and then print the
value in nanoseconds. Change the example to do this.

Change-Id: I4ddb123f0935a12cda3b5d6f1ca919bfcd6383d6
Reviewed-on: https://go-review.googlesource.com/c/163622
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/time/example_test.go

index 0fd325f2e4f02f77f3274ee39a1b75bee1f09e71..a3532584ef587792c56b006d721f824bddbd96f9 100644 (file)
@@ -113,8 +113,8 @@ func ExampleDuration_Minutes() {
 }
 
 func ExampleDuration_Nanoseconds() {
-       ns, _ := time.ParseDuration("1000ns")
-       fmt.Printf("one microsecond has %d nanoseconds.", ns.Nanoseconds())
+       u, _ := time.ParseDuration("1us")
+       fmt.Printf("one microsecond has %d nanoseconds.", u.Nanoseconds())
        // Output: one microsecond has 1000 nanoseconds.
 }