]> Cypherpunks repositories - gostls13.git/commitdiff
time: change wording in duration hours example
authorJuan Carlos <juanjcsr@gmail.com>
Fri, 21 Jul 2017 22:55:57 +0000 (17:55 -0500)
committerIan Lance Taylor <iant@golang.org>
Sat, 9 Sep 2017 12:18:42 +0000 (12:18 +0000)
Change-Id: I86728a1c6c20471beaa3546ca7a43a8edeb9f0b7
Reviewed-on: https://go-review.googlesource.com/50691
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Adrian Hesketh <adrianhesketh@hushmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/time/example_test.go

index 8d019a0f21f537bdf558ce54fd83521034057e60..170e4ded522d25b7b47cd6b1c4ba5e6b929fc102 100644 (file)
@@ -85,7 +85,43 @@ func ExampleDuration_Truncate() {
        // t.Truncate(  1m0s) = 1h15m0s
        // t.Truncate( 10m0s) = 1h10m0s
        // t.Truncate(1h0m0s) = 1h0m0s
+}
+
+func ExampleParseDuration() {
+       hours, _ := time.ParseDuration("10h")
+       complex, _ := time.ParseDuration("1h10m10s")
+
+       fmt.Println(hours)
+       fmt.Println(complex)
+       fmt.Printf("there are %.0f seconds in %v\n", complex.Seconds(), complex)
+       // Output:
+       // 10h0m0s
+       // 1h10m10s
+       // there are 4210 seconds in 1h10m10s
+}
+
+func ExampleDuration_Hours() {
+       h, _ := time.ParseDuration("4h30m")
+       fmt.Printf("I've got %.1f hours of work left.", h.Hours())
+       // Output: I've got 4.5 hours of work left.
+}
+
+func ExampleDuration_Minutes() {
+       m, _ := time.ParseDuration("1h30m")
+       fmt.Printf("The movie is %.0f minutes long.", m.Minutes())
+       // Output: The movie is 90 minutes long.
+}
+
+func ExampleDuration_Nanoseconds() {
+       ns, _ := time.ParseDuration("1000ns")
+       fmt.Printf("one microsecond has %d nanoseconds.", ns.Nanoseconds())
+       // Output: one microsecond has 1000 nanoseconds.
+}
 
+func ExampleDuration_Seconds() {
+       m, _ := time.ParseDuration("1m30s")
+       fmt.Printf("take off in t-%.0f seconds.", m.Seconds())
+       // Output: take off in t-90 seconds.
 }
 
 var c chan int