aboutsummaryrefslogtreecommitdiff
path: root/src/time/example_test.go
diff options
context:
space:
mode:
authorJuan Carlos <juanjcsr@gmail.com>2017-07-21 17:55:57 -0500
committerIan Lance Taylor <iant@golang.org>2017-09-09 12:18:42 +0000
commita7489ec2ccd53511ae004517ad0f640394063c35 (patch)
tree136957c8e5c275c0d5ca4383971251af10bbe3af /src/time/example_test.go
parent401609c3ff0da3d7bbf78f5034c87ef5c4640792 (diff)
downloadgo-a7489ec2ccd53511ae004517ad0f640394063c35.tar.xz
time: change wording in duration hours example
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>
Diffstat (limited to 'src/time/example_test.go')
-rw-r--r--src/time/example_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 8d019a0f21..170e4ded52 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -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