aboutsummaryrefslogtreecommitdiff
path: root/src/time/example_test.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2019-02-27 11:41:48 +1100
committerRob Pike <r@golang.org>2019-02-27 02:20:28 +0000
commit9426d8c63311c17483d93a20efc26e6dbb759772 (patch)
tree66d5c6ebd4c3990ad8f2e986c7e75b4037e9fbab /src/time/example_test.go
parent6fa7669fd7d9994ef20e40f41a9771d664d00c5e (diff)
downloadgo-9426d8c63311c17483d93a20efc26e6dbb759772.tar.gz
go-9426d8c63311c17483d93a20efc26e6dbb759772.zip
time: rewrite ExampleDuration_Nanoseconds to be more idiomatic.
Fix the punctuation and use the proper units for microseconds, while explaining the incorrect but common variant 'us'. Change-Id: I9e96694ef27ab4761efccd8616ac7b6700f60d39 Reviewed-on: https://go-review.googlesource.com/c/163917 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/time/example_test.go')
-rw-r--r--src/time/example_test.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index a3532584ef..3b3c88e6af 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -113,9 +113,14 @@ func ExampleDuration_Minutes() {
}
func ExampleDuration_Nanoseconds() {
- u, _ := time.ParseDuration("1us")
- fmt.Printf("one microsecond has %d nanoseconds.", u.Nanoseconds())
- // Output: one microsecond has 1000 nanoseconds.
+ u, _ := time.ParseDuration("1µs")
+ fmt.Printf("One microsecond is %d nanoseconds.\n", u.Nanoseconds())
+ // The package also accepts the incorrect but common prefix u for micro.
+ v, _ := time.ParseDuration("1us")
+ fmt.Printf("One microsecond is %6.2e seconds.\n", v.Seconds())
+ // Output:
+ // One microsecond is 1000 nanoseconds.
+ // One microsecond is 1.00e-06 seconds.
}
func ExampleDuration_Seconds() {