Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

msakrejda
Copy link
Contributor

Fixes #251.

@@ -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))
Copy link
Contributor

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.

@johto
Copy link
Contributor

johto commented May 19, 2014

@deafbybeheading: Are you going to clean this up? I think we should commit a fix for the "time without time zone" issue.

@msakrejda
Copy link
Contributor Author

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 time.FixedZone("", 0)?

@johto
Copy link
Contributor

johto commented May 21, 2014

So if I understand correctly, those first four tests should instead be using time.FixedZone("", 0)?

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.

@msakrejda
Copy link
Contributor Author

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 time.FixedZone("", 0) everywhere in the tests then? And should we be using == instead of time.Equal?

@johto
Copy link
Contributor

johto commented May 21, 2014

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 time.FixedZone("", 0) everywhere in the tests then?

I think that would be more correct.

And should we be using == instead of time.Equal?

I think so. Especially in the location tests -- currently they're not testing much of anything, really. :-(

@msakrejda
Copy link
Contributor Author

And should we be using == instead of time.Equal?

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 time.Location, which means if we instantiate two different zones with an identical name and offset, they'll still be treated as different. We can't really compare the time.Locationss manually, either, since the struct exposes no members, and the only function is String(), which is the same for time.Locations with different offsets but the same name.

I think we could use == of the respective time.String() values, however. Does that sound reasonable?

@johto
Copy link
Contributor

johto commented May 22, 2014

So we can't do that, because that compares the fields of the structs by value, including the pointer to the time.Location, which means if we instantiate two different zones with an identical name and offset, they'll still be treated as different. We can't really compare the time.Locationss manually, either, since the struct exposes no members, and the only function is String(), which is the same for time.Locations with different offsets but the same name.

Ugh. Ugly.

I think we could use == of the respective time.String() values, however. Does that sound reasonable?

Given the above, I think that's the most reasonable thing to do.

@msakrejda msakrejda mentioned this pull request Jun 2, 2014
@bendemaree
Copy link

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.

@johto
Copy link
Contributor

johto commented Oct 6, 2014

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.

@bendemaree
Copy link

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 time.Time bug at all. I am pretty sure the issue lies with sending a zeroed-out time.Time{}, as you suspected. In fact, when you run this through time.Format you get back 0001-01-01T00:00:00Z, which is reasonable. Then, asking Postgres to parse that is where it gets interesting.

testdb=# SELECT '0001-01-01T00:00:00Z'::timestamptz;
           timestamptz
---------------------------------
 0001-12-31 18:09:24-05:50:36 BC
(1 row)

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.

@johto
Copy link
Contributor

johto commented Oct 7, 2014

There's is a problem with negative years, and I've opened a pull request for that in #303.

@msakrejda msakrejda closed this Jun 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistent behavior of Row.Scan scanning time.Time struct
3 participants