Skip to content

Commit

Permalink
time: rewrite ExampleDuration_Nanoseconds to be more idiomatic.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
robpike committed Feb 27, 2019
1 parent 6fa7669 commit 9426d8c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/time/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 9426d8c

Please sign in to comment.