Skip to content

Commit 61170f8

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent bd23e84 commit 61170f8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/time/example_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,21 @@ func ExampleDuration_Truncate() {
9090
func ExampleParseDuration() {
9191
hours, _ := time.ParseDuration("10h")
9292
complex, _ := time.ParseDuration("1h10m10s")
93+
micro, _ := time.ParseDuration("1µs")
94+
// The package also accepts the incorrect but common prefix u for micro.
95+
micro2, _ := time.ParseDuration("1us")
9396

9497
fmt.Println(hours)
9598
fmt.Println(complex)
96-
fmt.Printf("there are %.0f seconds in %v\n", complex.Seconds(), complex)
99+
fmt.Printf("There are %.0f seconds in %v.\n", complex.Seconds(), complex)
100+
fmt.Printf("There are %d nanoseconds in %v.\n", micro.Nanoseconds(), micro)
101+
fmt.Printf("There are %6.2e seconds in %v.\n", micro2.Seconds(), micro)
97102
// Output:
98103
// 10h0m0s
99104
// 1h10m10s
100-
// there are 4210 seconds in 1h10m10s
105+
// There are 4210 seconds in 1h10m10s.
106+
// There are 1000 nanoseconds in 1µs.
107+
// There are 1.00e-06 seconds in 1µs.
101108
}
102109

103110
func ExampleDuration_Hours() {
@@ -115,18 +122,14 @@ func ExampleDuration_Minutes() {
115122
func ExampleDuration_Nanoseconds() {
116123
u, _ := time.ParseDuration("1µs")
117124
fmt.Printf("One microsecond is %d nanoseconds.\n", u.Nanoseconds())
118-
// The package also accepts the incorrect but common prefix u for micro.
119-
v, _ := time.ParseDuration("1us")
120-
fmt.Printf("One microsecond is %6.2e seconds.\n", v.Seconds())
121125
// Output:
122126
// One microsecond is 1000 nanoseconds.
123-
// One microsecond is 1.00e-06 seconds.
124127
}
125128

126129
func ExampleDuration_Seconds() {
127130
m, _ := time.ParseDuration("1m30s")
128-
fmt.Printf("take off in t-%.0f seconds.", m.Seconds())
129-
// Output: take off in t-90 seconds.
131+
fmt.Printf("Take off in t-%.0f seconds.", m.Seconds())
132+
// Output: Take off in t-90 seconds.
130133
}
131134

132135
var c chan int

0 commit comments

Comments
 (0)