Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: system TZ is UTC, but time.Local != time.UTC #9832

Closed
pbnjay opened this issue Feb 10, 2015 · 6 comments
Closed

time: system TZ is UTC, but time.Local != time.UTC #9832

pbnjay opened this issue Feb 10, 2015 · 6 comments

Comments

@pbnjay
Copy link
Contributor

pbnjay commented Feb 10, 2015

This was a very unexpected bug, considering all output and other logging statements matched up.

$ cat tt.go

package main

import (
    "fmt"
    "time"
)

func main() {
    t1 := time.Now()
    t2 := t1.UTC()
    fmt.Println(t1, " == ", t2, " => ", t1==t2)
}

$ go run tt.go

2015-02-10 19:51:15.366942319 +0000 UTC  ==  2015-02-10 19:51:15.366942319 +0000 UTC  =>  false

go version devel +2d02ff2 Sat Dec 13 10:18:27 2014 +0000 linux/amd64

@DisposaBlackSwan
Copy link

It wasn't clear whether or not you're aware of http://golang.org/pkg/time/#Time.Equal. I'm not sure t == t is ever what one wants.

@ianlancetaylor
Copy link
Contributor

See the note about == at http://golang.org/pkg/time/#Time .

@pbnjay
Copy link
Contributor Author

pbnjay commented Feb 10, 2015

TBH I was using time.Time as map keys when I stumbled on this, so I couldn't use Time.Equal anyways.

The code above was just a minimal test case, since even when trying to debug this the output matched exactly. I had to dig all the way into zoneinfo_unix.go to see that they weren't the same value.

@pbnjay
Copy link
Contributor Author

pbnjay commented Feb 10, 2015

@ianlancetaylor I've seen the note, but it's not clear that Local = "UTC" and UTC = "UTC" are different things. Obviously bugs/docs are up to y'all, at least now if someone else has the issue they'll be able to google this particular edge case. Cheers

@nightlyone
Copy link
Contributor

@pbnjay please note, that you actually CAN use times as map keys, if you call .UTC() before storing them, since t1.UTC() == t2.UTC() => true, iff t1.Equal(t2) => true

@pbnjay
Copy link
Contributor Author

pbnjay commented Feb 10, 2015

yeah that's what I'm doing now.... but again, docs make it unclear that I
have to force .UTC() even when it's already in UTC.

Jeremy

On Tue, Feb 10, 2015 at 4:22 PM, Ingo Oeser notifications@github.com
wrote:

@pbnjay https://github.com/pbnjay please note, that you actually CAN
use times as map keys, if you call .UTC() before storing them, since
t1.UTC() == t2.UTC() => true, iff t1.Equal(t2) => true


Reply to this email directly or view it on GitHub
#9832 (comment).

@mikioh mikioh changed the title system TZ is UTC, but time.Local != time.UTC time: system TZ is UTC, but time.Local != time.UTC Feb 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants