aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPantelis Sampaziotis <psampaz@gmail.com>2019-09-17 19:01:36 +0000
committerIan Lance Taylor <iant@golang.org>2019-09-17 20:11:12 +0000
commit575386d6324308d83f6f0782e61620ffe9f5dba3 (patch)
treef7e4224509b71dd7e85cfd7b92f7ce66df46f0d3
parent06e5529eceae35bb26b51f2430c2c9425149ede2 (diff)
downloadgo-575386d6324308d83f6f0782e61620ffe9f5dba3.tar.gz
go-575386d6324308d83f6f0782e61620ffe9f5dba3.zip
time: add examples for microseconds and milliseconds methods
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>
-rw-r--r--src/time/example_test.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 25c34ebc1c..4d70471a7d 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -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())