]> Cypherpunks repositories - gostls13.git/commitdiff
time: add examples for microseconds and milliseconds methods
authorPantelis Sampaziotis <psampaz@gmail.com>
Tue, 17 Sep 2019 19:01:36 +0000 (19:01 +0000)
committerIan Lance Taylor <iant@golang.org>
Tue, 17 Sep 2019 20:11:12 +0000 (20:11 +0000)
This change adds testable examples for the new Microseconds and Milliseconds methods that were introduced in Go 1.13.

Fixes #34354

Change-Id: Ibdbfd770ca2192f9086f756918325f7327ce0482
GitHub-Last-Rev: 4575f48f5feb8e49742304d17776e28302647931
GitHub-Pull-Request: golang/go#34355
Reviewed-on: https://go-review.googlesource.com/c/go/+/195979
Reviewed-by: Alexander Rakoczy <alex@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Alexander Rakoczy <alex@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/time/example_test.go

index 25c34ebc1cbd1fdbe7a328e040241e1d4f8b3065..4d70471a7d743e1ed11f0fc96a1ce58780c2acea 100644 (file)
@@ -113,6 +113,20 @@ func ExampleDuration_Hours() {
        // Output: I've got 4.5 hours of work left.
 }
 
+func ExampleDuration_Microseconds() {
+       u, _ := time.ParseDuration("1s")
+       fmt.Printf("One second is %d microseconds.\n", u.Microseconds())
+       // Output:
+       // One second is 1000000 microseconds.
+}
+
+func ExampleDuration_Milliseconds() {
+       u, _ := time.ParseDuration("1s")
+       fmt.Printf("One second is %d milliseconds.\n", u.Milliseconds())
+       // Output:
+       // One second is 1000 milliseconds.
+}
+
 func ExampleDuration_Minutes() {
        m, _ := time.ParseDuration("1h30m")
        fmt.Printf("The movie is %.0f minutes long.", m.Minutes())