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: TZ=UTC does not cause Location field to be nil #19202
Comments
|
Isn't it already supported? Anyway it should fallback to UTC. And UTC must contain nil loc like in second string. |
Your program clearly shows that the time package does respect the I think the question is: should the time package require that |
I'm not sure about that. bash-3.2$ go version
go version go1.7.5 darwin/amd64
bash-3.2$ cat tt.go
package main
import (
"fmt"
"os"
"time"
)
func main() {
fmt.Println("TZ:", os.Getenv("TZ"))
fmt.Printf("%#v\n", time.Now().Location())
}
bash-3.2$ TZ="MSK" go run tt.go
TZ: MSK
&time.Location{name:"", zone:[]time.zone(nil), tx:[]time.zoneTrans(nil), cacheStart:0, cacheEnd:0, cacheZone:(*time.zone)(nil)}
bash-3.2$ TZ="UTC" go run tt.go
TZ: UTC
&time.Location{name:"", zone:[]time.zone(nil), tx:[]time.zoneTrans(nil), cacheStart:0, cacheEnd:0, cacheZone:(*time.zone)(nil)} |
@pzinovkin That is not the right test. Try actually fetching some field from the location first. For example, try adding
(which will call the |
You're right. Thanks. bash-3.2$ cat tt.go
package main
import (
"fmt"
"os"
"time"
)
func main() {
fmt.Println("TZ:", os.Getenv("TZ"))
fmt.Println(time.Now())
fmt.Println(time.Now().Location())
}
bash-3.2$ TZ="ROK" go run tt.go
TZ: ROK
2017-02-21 04:16:47.677760884 +0900 KST
ROK
bash-3.2$ TZ="" go run tt.go
TZ:
2017-02-20 19:16:51.373521089 +0000 UTC
UTC
bash-3.2$ TZ="Asia/Irkutsk" go run tt.go
TZ: Asia/Irkutsk
2017-02-21 03:17:54.094113655 +0800 +08
Asia/Irkutsk |
@bradfitz is this issue already resolved? |
Sorry, I quickly interpreted the "You're right" as the issue no longer existing. On second read, it looks like we're still trying to determine whether Location should always be nil, like @ianlancetaylor says in #19202 (comment):
|
This looks like #19486? |
Yes, I think Russ addresses this issue in #19486 when he said "Go always maintains a distinction between local and UTC times, even when TZ=UTC in the environment." I'm going to close this again. If you think this is wrong, please follow up with some code that shows a problem that is not related to internal details of the time package. |
Well, I guess we need to start setting time to UTC() explicitly then. Because setting TZ=UTC won't work once we need to compare time.Now() and time.Now().UTC(). |
What do you mean by "compare?" Comparing using (Edited to add a missing "not".) |
@ianlancetaylor did you mean "you should normally not use |
What about reflect.DeepEqual when time in some struct? |
Argh, yes, I mean you should not use |
@pzinovkin Yes, |
Addressed or stated the issue? Please see https://go-review.googlesource.com/c/31144 |
Also consider this example:
|
No. |
What did you do?
What did you expect to see?
Both strings to contain nil Location.
System details
The text was updated successfully, but these errors were encountered: