You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A way to detect between a zero offset and an unknown offset. I want to detect/block unknown timezone names before they enter the database with the wrong offset.
The current design of Parse, as I understand it, purposely leaves this situation up to the user to decide, as there are tradeoffs based on what you expect from your data for this time format.
If the zone abbreviation is unknown, Parse records the time as being in a fabricated location with the given zone abbreviation and a zero offset. This choice means that such a time can be parsed and reformatted with the same layout losslessly, but the exact instant used in the representation will differ by the actual zone offset. To avoid such problems, prefer time layouts that use a numeric zone offset, or use ParseInLocation.
Strictly speaking, for your example of Wed, 25 Dec 2019 20:09:20 EST, a name was provided and an offset wasn't, so this is working as intended.
This is complicated by the RFC1123 format, as documented in time:
Note that the RFC822, RFC850, and RFC1123 formats should be applied only to local times. Applying them to UTC times will use "UTC" as the time zone abbreviation, while strictly speaking those RFCs require the use of "GMT" in that case. In general RFC1123Z should be used instead of RFC1123 for servers that insist on that format, and RFC3339 should be preferred for new protocols. RFC3339, RFC822, RFC822Z, RFC1123, and RFC1123Z are useful for formatting; when used with time.Parse they do not accept all the time formats permitted by the RFCs.
If you're stuck with RFC1123, you'll have to use ParseInLocation to handle the specific edge case of your data, like https://play.golang.org/p/qfqGisQqhrc
Let me know if there's a good suggestion to work around this, but I don't see a better way of the standard library catering to every format.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/k6d-epEgF-1
What did you expect to see?
A way to detect between a zero offset and an unknown offset. I want to detect/block unknown timezone names before they enter the database with the wrong offset.
What did you see instead?
go/src/time/format.go
Lines 1174 to 1179 in a4c579e
The text was updated successfully, but these errors were encountered: