Skip to content

time: parsing reference times seems to ignore three-letter timezones #9617

@jovlinger

Description

@jovlinger

According to the docs for package time, the RFC822(Z) format of the reference time is

    RFC822      = "02 Jan 06 15:04 MST"
    RFC822Z     = "02 Jan 06 15:04 -0700"

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)

if err1 != nil || err1z != nil {
    fmt.Println(err1)
    fmt.Println(err1z)
    return
}
prt("rfc822", rfc822)
prt("rfc822z", rfc822z)
fmt.Println("rfc822 == rfc822z:", rfc822.Equal(rfc822z))

rfc850, err850 := time.Parse(time.RFC850, rfc822z.Format(time.RFC850))
if err850 != nil {
    fmt.Println(err850)
    return
}
prt("rfc850", rfc850)

}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions