From: Alberto Donizetti Date: Sun, 24 Feb 2019 21:48:46 +0000 (+0100) Subject: time: parse 1us in Nanoseconds example X-Git-Tag: go1.13beta1~1414 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c0101b1961299ce6d13fac3c1dd13d3aea22b276;p=gostls13.git time: parse 1us in Nanoseconds example 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/time/example_test.go b/src/time/example_test.go index 0fd325f2e4..a3532584ef 100644 --- a/src/time/example_test.go +++ b/src/time/example_test.go @@ -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. }