aboutsummaryrefslogtreecommitdiff
path: root/src/time/example_test.go
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2019-02-27 14:01:55 +1100
committerRob Pike <r@golang.org>2019-02-28 00:24:56 +0000
commit61170f85e62f1326d42c4dbd8aa17ab4a1305a87 (patch)
treee2cec756fa0c7ab4f94655b9431e7583d4520a53 /src/time/example_test.go
parentbd23e84b73b90947a676ec9a5325de52d7186815 (diff)
downloadgo-61170f85e62f1326d42c4dbd8aa17ab4a1305a87.tar.gz
go-61170f85e62f1326d42c4dbd8aa17ab4a1305a87.zip
time: move the explanation of u/micro to the ParseDuration example
Fix a few missing capitalizations in drive-by. Change-Id: I7353c12f3ccddefc0f26a98590caf9e446129558 Reviewed-on: https://go-review.googlesource.com/c/163918 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/time/example_test.go')
-rw-r--r--src/time/example_test.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 3b3c88e6af..25c34ebc1c 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -90,14 +90,21 @@ func ExampleDuration_Truncate() {
func ExampleParseDuration() {
hours, _ := time.ParseDuration("10h")
complex, _ := time.ParseDuration("1h10m10s")
+ micro, _ := time.ParseDuration("1µs")
+ // The package also accepts the incorrect but common prefix u for micro.
+ micro2, _ := time.ParseDuration("1us")
fmt.Println(hours)
fmt.Println(complex)
- fmt.Printf("there are %.0f seconds in %v\n", complex.Seconds(), complex)
+ fmt.Printf("There are %.0f seconds in %v.\n", complex.Seconds(), complex)
+ fmt.Printf("There are %d nanoseconds in %v.\n", micro.Nanoseconds(), micro)
+ fmt.Printf("There are %6.2e seconds in %v.\n", micro2.Seconds(), micro)
// Output:
// 10h0m0s
// 1h10m10s
- // there are 4210 seconds in 1h10m10s
+ // There are 4210 seconds in 1h10m10s.
+ // There are 1000 nanoseconds in 1µs.
+ // There are 1.00e-06 seconds in 1µs.
}
func ExampleDuration_Hours() {
@@ -115,18 +122,14 @@ func ExampleDuration_Minutes() {
func ExampleDuration_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() {
m, _ := time.ParseDuration("1m30s")
- fmt.Printf("take off in t-%.0f seconds.", m.Seconds())
- // Output: take off in t-90 seconds.
+ fmt.Printf("Take off in t-%.0f seconds.", m.Seconds())
+ // Output: Take off in t-90 seconds.
}
var c chan int