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: On Windows, zone name returned by Zone() method sometimes cannot be used in time.LoadLocation #5909

Closed
gopherbot opened this issue Jul 18, 2013 · 12 comments

Comments

Projects
None yet
4 participants
@gopherbot
Copy link

commented Jul 18, 2013

by diogomfranco:

Found when running http://play.golang.org/p/La5gHqlGU- on a Windows system
set to the (UTC -03:00) Brasilia timezone (with or without DST).
Output:

> ESAST -10800
> unknown time zone ESAST

This also affects time.Parse: time.Parse("MST",
time.Now().Format("MST")),
or time.UnixDate or any template including a timezone results in a parsing
error. With the "MST" template, the error is `cannot parse "ESAST"
as "MST"`,
but with time.UnixDate the error is the odd `cannot parse "ESAST 2013" as
"MST"`.

Apparently Windows exports the timezone name as "E. South America Standard
Time", while the name given in the zoneinfo database included with Go, it's
named BRT. Go uses the OS to get the timezone name (and abbreviation?), but
it doesn't use the OS to do the reverse mapping, and we get that.

On other OSes, Go (IIRC) uses the zoneinfo database, so this bug probably
doesn't exist there.
@gopherbot

This comment has been minimized.

Copy link
Author

commented Jul 18, 2013

Comment 1 by torlangballe:

We think this might be the same cause:
I'm in Vietnam, and when I call
zonename, offset := time.Now().In(time.Local()).Zone()
I get a zone-name "ICT"  (Indo-China Time)
When I then call 
time.LoadLocation("ICT")
It returns UTC and the error: "unknown time zone ICT"
I'm on a Mac (go 1.1), so not just a windows problem if it's the same bug,
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Jul 19, 2013

Comment 2:

I think time.LoadLocation ( http://golang.org/pkg/time/#LoadLocation ) takes zone names
like "Asia/Bangkok" not zone abbreviations like "ICT".
Alex
@gopherbot

This comment has been minimized.

Copy link
Author

commented Jul 19, 2013

Comment 3 by diogomfranco:

It does, but that's because, instead of using the system for looking up zones, it
uses a packaged zoneinfo database. The *real* problem is that, given its current
behavior, the time package is unable to parse its own times, such as in
`time.Parse("MST", time.Now().Format("MST"))`.
@remyoudompheng

This comment has been minimized.

Copy link
Contributor

commented Jul 20, 2013

Comment 4:

Labels changed: added os-windows.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Jul 23, 2013

Comment 5:

Remy,
As you described, it fails on linux too:
# cat > main.go
package main
import "fmt"
import "time"
func main() {
        zone, offset := time.Now().In(time.Local).Zone()
        fmt.Println(zone, offset)
        if loc, err := time.LoadLocation(zone); err == nil {
                fmt.Println(loc)
        } else {
                fmt.Println(err)
        }
}
# export TZ='Asia/Kolkata'
# go run main.go
IST 19800
unknown time zone IST
#
Alex
@rsc

This comment has been minimized.

Copy link
Contributor

commented Jul 30, 2013

Comment 6:

The zone name returned by Zone can never be used by LoadLocation.
See comment #2.

Status changed to Invalid.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Aug 1, 2013

Comment 7 by diogomfranco:

This still leaves the problem that time.Parse can't parse time strings generated by
the time package itself, such as in `time.Parse("MST", time.Now().Format("MST"))`.
Should I open a separate bug for that? Or is this another instance of
https://golang.org/issue/3790 ?
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Aug 2, 2013

Comment 8:

diogomfranco,
Please, provide example to demonstrate.
Alex
@gopherbot

This comment has been minimized.

Copy link
Author

commented Aug 2, 2013

Comment 9 by diogomfranco:

Code: http://play.golang.org/p/CmKvKRSzxi
Output:
Zone: "" -10800
Format:  2006-01-02T15:04:05Z07:00
2013-08-02T13:43:47-03:00
2013-08-02 13:43:47 -0300 -0300
Format:  02 Jan 06 15:04 MST
02 Aug 13 13:43 -0300
parsing time "02 Aug 13 13:43 -0300" as "02 Jan 06 15:04 MST": cannot parse "-0300" as
"MST"
Format:  Monday, 02-Jan-06 15:04:05 MST
Friday, 02-Aug-13 13:43:47 -0300
parsing time "Friday, 02-Aug-13 13:43:47 -0300" as "Monday, 02-Jan-06 15:04:05 MST":
cannot parse "-0300" as "MST"
Format:  Mon, 02 Jan 2006 15:04:05 MST
Fri, 02 Aug 2013 13:43:47 -0300
parsing time "Fri, 02 Aug 2013 13:43:47 -0300" as "Mon, 02 Jan 2006 15:04:05 MST":
cannot parse "-0300" as "MST"
Format:  Mon Jan _2 15:04:05 MST 2006
Fri Aug  2 13:43:47 -0300 2013
parsing time "Fri Aug  2 13:43:47 -0300 2013" as "Mon Jan _2 15:04:05 MST 2006": cannot
parse "-0300 2013" as "MST"
I changed my system language to Japanese and I don't get "ESAST" as the timezone
abbreviation anymore (I presume the abbreviation code just sees a bunch of non-[A-Z]
characters and ignores them all); however "ESAST" was it when windows was in English,
presumably from "E. South America Standard Time"
(http://msdn.microsoft.com/en-us/library/ms912391%28v=winembedded.11%29.aspx
index 065).
Output (system language English):
Zone: "ESAST" -10800
Format:  2006-01-02T15:04:05Z07:00
2013-08-02T13:54:17-03:00
2013-08-02 13:54:17 -0300 ESAST
Format:  02 Jan 06 15:04 MST
02 Aug 13 13:54 ESAST
parsing time "02 Aug 13 13:54 ESAST" as "02 Jan 06 15:04 MST": cannot parse "ESAST" as
"MST"
Format:  Monday, 02-Jan-06 15:04:05 MST
Friday, 02-Aug-13 13:54:17 ESAST
parsing time "Friday, 02-Aug-13 13:54:17 ESAST" as "Monday, 02-Jan-06 15:04:05 MST":
cannot parse "ESAST" as "MST"
Format:  Mon, 02 Jan 2006 15:04:05 MST
Fri, 02 Aug 2013 13:54:17 ESAST
parsing time "Fri, 02 Aug 2013 13:54:17 ESAST" as "Mon, 02 Jan 2006 15:04:05 MST":
cannot parse "ESAST" as "MST"
Format:  Mon Jan _2 15:04:05 MST 2006
Fri Aug  2 13:54:17 ESAST 2013
parsing time "Fri Aug  2 13:54:17 ESAST 2013" as "Mon Jan _2 15:04:05 MST 2006": cannot
parse "ESAST 2013" as "MST"
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Aug 3, 2013

Comment 10:

diogomfranco,
Like this https://golang.org/issue/5783 ?
Alex
@gopherbot

This comment has been minimized.

Copy link
Author

commented Aug 3, 2013

Comment 11 by diogomfranco:

That'd be the case for the Japanese locale one, but I also get the problem in English
(the "ESAST" case).
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Aug 3, 2013

Comment 12:

Do you? Are you using recent version of Go? If not, try it, please.
Alex

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.