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
Unfiy time parsing with timestamp parsing #253
Conversation
@@ -47,14 +47,10 @@ func decode(parameterStatus *parameterStatus, s []byte, typ oid.Oid) interface{} | |||
switch typ { | |||
case oid.T_bytea: | |||
return parseBytea(s) | |||
case oid.T_timestamptz: | |||
case oid.T_timestamptz, oid.T_timetz: | |||
return parseTs(parameterStatus.currentLocation, string(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using currentLocation for "time with time zone" is not an easily defendable behaviour. I'm inclined to think that timetz should always result in a time.FixedOffset.
@deafbybeheading: Are you going to clean this up? I think we should commit a fix for the "time without time zone" issue. |
Yeah, sorry--I thought this was a simple fix and then I realized the semantics we want are actually more nuanced. So if I understand correctly, those first four tests should instead be using |
First four? I don't understand where the number four comes from. It looks like all uses of time.UTC in the tests are slightly incorrect, and barely don't fail because we only compare the offset (which is +00 for UTC, obviously) and not the location. |
Sorry, meant first the tests added in the patch, starting here. Obviously there's more than four--I think something had scrolled off-screen and I miscounted. Should we be using |
I think that would be more correct.
I think so. Especially in the location tests -- currently they're not testing much of anything, really. :-( |
So we can't do that, because that compares the fields of the structs by value, including the pointer to the I think we could use |
Ugh. Ugly.
Given the above, I think that's the most reasonable thing to do. |
Can I inquire on the status of this? I was bit by this and traced here from jinzhu/gorm#16. Let me know if I can lend a hand in some way. |
This only fixes problems with "time", not "timestamp with time zone". I had a look, and it looks like the people in that issue are burned by the fact that negative time.Time values are not encoded correctly before they're sent into the database: https://gist.github.com/johto/d85b8a614e62b63fb31d. Personally I think that sending time.Time{} values is dubious at best, but the bug is probably still worth fixing. |
Ah, I see @johto. I spent some time digging through this; hopefully this helps. I think you are close, and that you may not have a negative
The date is, I think, more accurately represented in Postgres, so it returns that value. I will talk to the maintainer of the other library about a cleaner way to represent a nil time. |
There's is a problem with negative years, and I've opened a pull request for that in #303. |
Fixes #251.