time.UnixNano() error -- Possible bug

260 peržiūrų
Praleisti ir pereiti prie pirmo neskaityto pranešimo

senior7515

neskaityta,
2012-03-08 01:32:202012-03-08
kam: golang-nuts
http://play.golang.org/p/MmC-ltROsq

Increate the time on your host to say 1 second.

It prints the same result.

Brad Fitzpatrick

neskaityta,
2012-03-08 01:36:592012-03-08
kam: senior7515, golang-nuts
The playground has a fixed clock for security-ish reasons.

It works on a real machine.

David Symonds

neskaityta,
2012-03-08 01:37:212012-03-08
kam: senior7515, golang-nuts
The playground is a limited environment, and its time does not
advance. Try running that code locally.


Dave.

David Symonds

neskaityta,
2012-03-08 01:38:312012-03-08
kam: senior7515, golang-nuts
Wait, that's not it. You're never changing the 't' variable after init.

chris dollin

neskaityta,
2012-03-08 01:41:262012-03-08
kam: senior7515, golang-nuts

Not here.

(i and j will of course be ==; they're a conversion of the
same time to a unix-nanoseconds-count.)

Chris

--
Chris "allusive" Dollin

Brad Fitzpatrick

neskaityta,
2012-03-08 01:43:372012-03-08
kam: David Symonds, senior7515, golang-nuts
On Wed, Mar 7, 2012 at 10:38 PM, David Symonds <dsym...@golang.org> wrote:
Wait, that's not it. You're never changing the 't' variable after init.

Hah, I missed that too.  I guess the playground does do time now:


(modulo source -> result caching)

senior7515

neskaityta,
2012-03-08 01:49:302012-03-08
kam: golang-nuts
I know that. I am saying that on my fbsd box it does in fact print the
same number.

I also mentioned it to increase it to 1 second before testing. I think
there is another limit to 1 sec on appengine or smth like that.

On Mar 8, 1:43 am, Brad Fitzpatrick <bradf...@golang.org> wrote:

senior7515

neskaityta,
2012-03-08 01:50:252012-03-08
kam: golang-nuts
Oh wait i didn't say I used it on an FreeBSD box. sorry.

On Mar 8, 1:43 am, Brad Fitzpatrick <bradf...@golang.org> wrote:

senior7515

neskaityta,
2012-03-08 01:53:022012-03-08
kam: golang-nuts
Chris: even after sleeping ?

time now in nano + sleep + time now in nano

Did I miss something ? maybe i don't get it.

On Mar 8, 1:41 am, chris dollin <ehog.he...@googlemail.com> wrote:

senior7515

neskaityta,
2012-03-08 01:58:482012-03-08
kam: golang-nuts
Edit:

I ran this code with 2 seconds of sleeping on a real machine. FBSD 9.0
amd 64. Latest weekly i just rebuilt my $GOROOT/src

According to http://weekly.golang.org/pkg/time/#Time.UnixNano

It returns the number of nano since epoch. This should change after
sleeping for 2 seconds for sure.

It doesn't on my system.

I also understand that there are appengine limitations. That's why i
mentioned to test it on your *host*.

Thank you. Let me know if I can provide any further clarification.
Sorry for being ambiguous the first time. It's late.

Brad Fitzpatrick

neskaityta,
2012-03-08 02:02:002012-03-08
kam: senior7515, golang-nuts
UnixTime returns the UnixTime of the receiver, t, not the the unix time of "Now", which you only called once, in your init.

You need to call Now() twice (before & after sleeping), if you want to see movement in time.

David Symonds

neskaityta,
2012-03-08 02:02:272012-03-08
kam: senior7515, golang-nuts
On Thu, Mar 8, 2012 at 5:58 PM, senior7515 <galleg...@gmail.com> wrote:

> I ran this code with 2 seconds of sleeping on a real machine. FBSD 9.0
> amd 64. Latest weekly i just rebuilt my $GOROOT/src
>
> According to http://weekly.golang.org/pkg/time/#Time.UnixNano
>
> It returns the number of nano since epoch. This should change after
> sleeping for 2 seconds for sure.

UnixNano is a method on an object. If you don't change the object, it
will report the same value each call.

Read the docs more carefully: t.UnixNano() is the number of
nanoseconds since epoch of *that* time, not of the current time. You
need to call time.Now().UnixNano() to get the current value.

>
> It doesn't on my system.

For clarity, please paste the *exact* code you are using.

senior7515

neskaityta,
2012-03-08 02:06:232012-03-08
kam: golang-nuts
David: Thank you. Also, that is the exact* code except i sleep it 1e9
as mentioned in the post.

Brad: Thanks. False alarm.

On Mar 8, 2:02 am, David Symonds <dsymo...@golang.org> wrote:
> On Thu, Mar 8, 2012 at 5:58 PM, senior7515 <gallego.al...@gmail.com> wrote:
> > I ran this code with 2 seconds of sleeping on a real machine. FBSD 9.0
> > amd 64. Latest weekly i just rebuilt my $GOROOT/src
>
> > According tohttp://weekly.golang.org/pkg/time/#Time.UnixNano

senior7515

neskaityta,
2012-03-08 02:11:012012-03-08
kam: golang-nuts
Just re read them. To quote : UnixNano returns the Unix time, the
number of nanoseconds elapsed since January 1, 1970 UTC.

How does that tell me is for the receiver t without looking at the
source ?

I suppose one can argue that since the receiver is t, it would make
sense.

I'll try not to post silly questions without looking at the source,
but I wanted to clarify that the docs didn't read clear to me.

David Symonds

neskaityta,
2012-03-08 02:13:232012-03-08
kam: senior7515, golang-nuts
On Thu, Mar 8, 2012 at 6:11 PM, senior7515 <galleg...@gmail.com> wrote:

> Just re read them. To quote : UnixNano returns the Unix time, the
> number of nanoseconds elapsed since January 1, 1970 UTC.
>
> How does that tell me is for the receiver t  without looking at the
> source ?
>
> I suppose one can argue that since the receiver is t, it would make
> sense.
>
> I'll try not to post silly questions without looking at the source,
> but I wanted to clarify that the docs didn't read clear to me.

You're right, it could be clearer. The other methods refer to the
receiver t, but Unix/UnixNano don't. Can you please file a bug?
http://code.google.com/p/go/issues/list


Dave.

Atsakyti visiems
Atsakyti autoriui
Persiųsti
0 naujų pranešimų