From c0101b1961299ce6d13fac3c1dd13d3aea22b276 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Sun, 24 Feb 2019 22:48:46 +0100 Subject: [PATCH] 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 --- src/time/example_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. } -- 2.48.1