Commit c0101b19 authored by Alberto Donizetti's avatar Alberto Donizetti

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/163622Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b5a68a9e
......@@ -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.
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment