|
|
|
Created:
13 years, 9 months ago by r Modified:
13 years, 9 months ago CC:
golang-dev, bradfitz, r2 Visibility:
Public. |
Descriptiontime: add a comment about how to use the Duration constants
Patch Set 1 #Patch Set 2 : diff -r 81084c0ed4e8 https://code.google.com/p/go/ #Patch Set 3 : diff -r 81084c0ed4e8 https://code.google.com/p/go/ #Patch Set 4 : diff -r 81084c0ed4e8 https://code.google.com/p/go/ #Patch Set 5 : diff -r 81084c0ed4e8 https://code.google.com/p/go/ #
Total comments: 3
Patch Set 6 : diff -r 81084c0ed4e8 https://code.google.com/p/go/ #Patch Set 7 : diff -r 767b6229d4dc https://code.google.com/p/go/ #
Total comments: 3
MessagesTotal messages: 17
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go/
Sign in to reply to this message.
Feels weird to write docs assuming the author is already in package "time". I'd qualify all these symbols with "time.". We do that for ExampleFoo generally, don't we? On Sun, Feb 26, 2012 at 12:59 AM, <r@golang.org> wrote: > Reviewers: golang-dev_googlegroups.com, > > Message: > Hello golang-dev@googlegroups.com, > > I'd like you to review this change to > https://code.google.com/p/go/ > > > Description: > time: add a comment about how to use the Duration constants > > Please review this at http://codereview.appspot.com/**5696078/<http://codereview.appspot.com/5696078/> > > Affected files: > M src/pkg/time/time.go > > > Index: src/pkg/time/time.go > ==============================**==============================**======= > --- a/src/pkg/time/time.go > +++ b/src/pkg/time/time.go > @@ -384,6 +384,15 @@ > > // 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 := Duration(Second) > +// fmt.Print(int64(second/**Millisecond)) // prints 1000 > +// > +// To convert an integer number of units to a duration, multiply: > +// seconds := 10 > +// fmt.Print(Duration(seconds)***Second) // prints 10s > +// > const ( > Nanosecond Duration = 1 > Microsecond = 1000 * Nanosecond > > >
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, bradfitz@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
On 26/02/2012, at 8:10 PM, Brad Fitzpatrick wrote: > Feels weird to write docs assuming the author is already in package "time". > > I'd qualify all these symbols with "time.". We do that for ExampleFoo generally, don't we? I went back and forth on that issue. Most docs are in the package, but perhaps this one is special. -rob
Sign in to reply to this message.
You'd never write time.Duration(time.Second); time.Second is already that type.
Sign in to reply to this message.
sigh.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, bradfitz@golang.org, r@google.com, dsymonds@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
http://codereview.appspot.com/5696078/diff/6/src/pkg/time/time.go File src/pkg/time/time.go (right): http://codereview.appspot.com/5696078/diff/6/src/pkg/time/time.go#newcode389 src/pkg/time/time.go:389: // second := time.Second "time." here http://codereview.appspot.com/5696078/diff/6/src/pkg/time/time.go#newcode390 src/pkg/time/time.go:390: // fmt.Print(int64(second/time.Millisecond)) // prints 1000 ... and here http://codereview.appspot.com/5696078/diff/6/src/pkg/time/time.go#newcode394 src/pkg/time/time.go:394: // fmt.Print(Duration(seconds)*Second) // prints 10s but not here.
Sign in to reply to this message.
Hello golang-dev@googlegroups.com, bradfitz@golang.org, r@google.com, dsymonds@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
Sign in to reply to this message.
LGTM
Sign in to reply to this message.
i wrote them, compiled them, ran them, took out the times, mailed them. you said put the times back. then things started to go wrong. no excuses. i've run them again. they work now. promise. i suppose this is an argument for an executable example, and there should perhaps be one, but there's also something to be said for simple code snippets in the doc comment. what a fiasco. -rob
Sign in to reply to this message.
*** Submitted as http://code.google.com/p/go/source/detail?r=84582b0431a1 *** time: add a comment about how to use the Duration constants R=golang-dev, bradfitz, r, dsymonds CC=golang-dev http://codereview.appspot.com/5696078
Sign in to reply to this message.
LGTM
Sign in to reply to this message.
http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go File src/pkg/time/time.go (right): http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go#newcode394 src/pkg/time/time.go:394: // fmt.Print(time.Duration(seconds)*time.Second) // prints 10s equivalent: s/time.Duration(seconds)/seconds/
Sign in to reply to this message.
http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go File src/pkg/time/time.go (right): http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go#newcode394 src/pkg/time/time.go:394: // fmt.Print(time.Duration(seconds)*time.Second) // prints 10s On 2012/02/26 14:21:27, crawshaw1 wrote: > equivalent: s/time.Duration(seconds)/seconds/ That's not the idiom, though.
Sign in to reply to this message.
http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go File src/pkg/time/time.go (right): http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go#newcode394 src/pkg/time/time.go:394: // fmt.Print(time.Duration(seconds)*time.Second) // prints 10s On 2012/02/26 14:22:53, bradfitzgoog wrote: > On 2012/02/26 14:21:27, crawshaw1 wrote: > > equivalent: s/time.Duration(seconds)/seconds/ > > That's not the idiom, though. Not to mention your "equivalent" way wouldn't even compile (an int * an time.Duration). But even if "secs" were a constant (not an int, as above), it still wouldn't be the idiom. We always write: time.Duration(identifier) * time.Unit And we tend to even include 1 when doing something like: 1 * time.Minute
Sign in to reply to this message.
On Sun, Feb 26, 2012 at 9:25 AM, <bradfitz@google.com> wrote: > > http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go > File src/pkg/time/time.go (right): > > http://codereview.appspot.com/5696078/diff/7002/src/pkg/time/time.go#newcode394 > src/pkg/time/time.go:394: > // fmt.Print(time.Duration(seconds)*time.Second) // prints 10s > On 2012/02/26 14:22:53, bradfitzgoog wrote: >> >> On 2012/02/26 14:21:27, crawshaw1 wrote: >> > equivalent: s/time.Duration(seconds)/seconds/ > > >> That's not the idiom, though. > > > Not to mention your "equivalent" way wouldn't even compile (an int * an > time.Duration). But even if "secs" were a constant (not an int, as > above), it still wouldn't be the idiom. We always write: > > time.Duration(identifier) * time.Unit > > And we tend to even include 1 when doing something like: > > 1 * time.Minute > > http://codereview.appspot.com/5696078/ Ah you're right, I took the easy but very different shortcut when testing, 10*time.Second. I'll be quiet now.
Sign in to reply to this message.
|
