-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: parsing reference times seems to ignore three-letter timezones #9617
Comments
go tip, ubuntu 12.02:
|
A given time zone abbreviation can mean different things to different people. Each interpretation is just as valid as any other. For example, MST can mean any one of:
If an abbreviation has meaning in a particular location, that's enough to resolve ambiguity. Hence http://golang.org/pkg/time/#Parse:
In Europe (for example), MST doesn't have any particular meaning. Thus http://golang.org/pkg/time/#Parse:
|
it's working as intended. |
It's broken and misleading. If Go can't parse the timezone as provided in its own example format, it should throw an error. This points out the inherent limitations of the example-driven format. I think this problem wouldn't exist if Go supported token-based time parsing. This example shows that even though
The output is
So |
Saying the time package can't parse those formats is overstating the There is no way for the time package to resolve the ambiguity itself, but If you don't need to keep the time zone offset around, you could just |
Which MST is that?
Working as intended. |
If I knew the location, I wouldn’t be worried about parsing it out of the string… |
So is my suggested solution not adequate for doing that? |
This is all very clearly documented. time.Parse makes an exception for the time zone abbreviations in the location time.Local. It does not attempt to resolve other abbreviation, since there are ambiguities. (Which MST? The one that is closest to your own local time?) In this case if your time.Local is MST/MDT then time.Parse will understand those. But otherwise not. If you have a list of what you think the abbreviations should mean, you can give them those meanings with a program like Rog posted. |
According to the docs for package time, the RFC822(Z) format of the reference time is
But when I try to parse these times, the RFC822 one gets parsed as GMT rather than MST:
rfc822 in RFC850 and unix seconds is Monday, 02-Jan-06 15:04:00 MST 1136214240
rfc822z in RFC850 and unix seconds is Monday, 02-Jan-06 15:04:00 -0700 1136239440
rfc822 == rfc822z: false
furthermore, once parsed, the result of Format into RFC850 doesn't conform to its own definition and can't be parsed into RFC850.
http://play.golang.org/p/8q0OkLkNQ-
(in case that link expires:)
package main
import (
"fmt"
"time"
)
func prt(name string, t time.Time) {
fmt.Println(name, "in RFC850 and unix seconds is", t.Format(time.RFC850), t.Unix())
}
func main() {
rfc822, err1 := time.Parse(time.RFC822, time.RFC822)
rfc822z, err1z := time.Parse(time.RFC822Z, time.RFC822Z)
}
The text was updated successfully, but these errors were encountered: