1

Why Golang time format (RFC-822 in this case) is different from the one described in the RFC?

In time package RFC822 const value is defined as:

RFC822 = "02 Jan 06 15:04 MST"

11 Nov 09 00:00 CET

But regarding to RFC-822 or w3.org Validator date format should be rather as RFC1123:

RFC1123     = "Mon, 02 Jan 2006 15:04:05 MST"

Wed, 11 Nov 2009 00:00:00 CET

or even better:

RFC1123Z    = "Mon, 02 Jan 2006 15:04:05 -0700"

Wed, 11 Nov 2009 00:00:00 +0100

Because the Central European Time Zone (CET) is not correct in this RFC.

Why such a difference? I'm writing an RSS server and it took me a while to figure out why I'm getting badly formatted results.

parasit
  • 486
  • 1
  • 4
  • 10
  • 2
    The format used for RFC822 perfectly matches what is defined in RFC 822 section 5.1. Day and seconds are clearly marked as optional there. – Steffen Ullrich Jan 31 '23 at 21:53
  • I'm not sure what you're after here - if you are asking, "why did the developers of go do it this way," that's probably a question better asked at https://github.com/golang/go. Having said that...a couple of things: (1) Why are you getting worked up over RFC822? Use a format you like better, since it's clear you prefer 1123. (2)RFC 822 makes the seconds optional - there is nothing wrong with omitting it. `hh:mm` is perfectly valid under 822. Ditto for the day (this is why it's listed as `[ day "," ]` - the brackets mean "optional") – Sandy Cash Jan 31 '23 at 21:59
  • 1
    It's not that I don't like it (I ended up using the longer version in my code), but I approached the matter with a completely opposite path, i.e. RSS -> Validator -> RFC. Absolutely everywhere where there are requirements for RSS, the format described as required is "RFC-822", but my code using "time.RFC822" returned different results than expected. "Problem" solved, but I managed to get annoyed why standard != standard. And while I can agree that the day of the week and the seconds are optional, the timezone "MST" (CET in my case) is not correct. – parasit Jan 31 '23 at 22:57
  • 1
    Yes, I read (later) that RFC822 should be applied to local time, but I still don't really see the logic why it was done that way... Maybe at least there will be a trace if someone in the future has similar problems. – parasit Jan 31 '23 at 23:15
  • Hear, hear. Insanity looms for those tinkering with Go's `time` package. I'm doing something similar (generating RSS feeds) and baffled at the way these so-called 'standards' have been implemented (or should I say... interpreted?). Thanks for pointing it out! – Gwyneth Llewelyn Apr 05 '23 at 10:54

0 Answers0