]> Cypherpunks repositories - gostls13.git/commitdiff
time: add a comment about how to use the Duration constants
authorRob Pike <r@golang.org>
Sun, 26 Feb 2012 11:24:51 +0000 (22:24 +1100)
committerRob Pike <r@golang.org>
Sun, 26 Feb 2012 11:24:51 +0000 (22:24 +1100)
R=golang-dev, bradfitz, r, dsymonds
CC=golang-dev
https://golang.org/cl/5696078

src/pkg/time/time.go

index 709a42267246fad5fb4216f92ba2856263ea5090..1b8c76fcc4c129677afdc8380c101b8f283ba067 100644 (file)
@@ -384,6 +384,15 @@ type Duration int64
 
 // Common durations.  There is no definition for units of Day or larger
 // to avoid confusion across daylight savings time zone transitions.
+//
+// To count the number of units in a Duration, divide:
+//     second := time.Second
+//     fmt.Print(int64(second/time.Millisecond)) // prints 1000
+//
+// To convert an integer number of units to a Duration, multiply:
+//     seconds := 10
+//     fmt.Print(time.Duration(seconds)*time.Second) // prints 10s
+//
 const (
        Nanosecond  Duration = 1
        Microsecond          = 1000 * Nanosecond