-
Notifications
You must be signed in to change notification settings - Fork 863
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
Timestamp incorrectly adds 'Z' when serializing from JSON to indicate GMT, fixes bug #2215 #2216
base: master
Are you sure you want to change the base?
Conversation
@s-montigny-desautels any chance you could review this? |
Now that I'm looking at this functionality a little closer, it seems to me that both I would expect pgtype.Timestamp's JSON behavior to match PostgreSQL.
|
It looks like RFC3339 is endorsed by ISO 8601. - https://www.rfc-editor.org/rfc/rfc3339
The issue I encountered was that the library added the "Z" even if it was there. I'd be happy if the whole change in 7803ec3 was rolled back. Probably the other issue is that Go doesn't have a |
The fix I did was to match the postgres JSON implementation, by adding the missing "Z" to the returned string. As @jackc said, I don't think reverting 7803ec3 is an good option either, since it will break UnmarshalJSON when getting JSON timestamp from postgres. @pconstantinou Where are you getting your timezone from? Maybe you are not using the proper type, since your timestamp has a timezone information in it. |
See: #2215 with a succinct example here: https://goplay.tools/snippet/fO_ceIqGn7d |
I see. Then, maybe, we should modify the |
I've made As a consequence, this change does modify the expected results in the unit tests. The old version of the unit tests expected a timezone, I've removed that. When Unmarshalling, I've changed the implementation to start parsing using with For my particular usecase, I've persisted JSON generated from the older version of the library, the appending |
@jackc can you take another look? I'd love to get this merged or decide on a different approach. |
@@ -116,12 +129,32 @@ func TestTimestampMarshalJSON(t *testing.T) { | |||
t.Errorf("%d: %v", i, err) | |||
} | |||
|
|||
if string(r) != tt.result { | |||
if !assert.Equal(t, tt.result, string(r)) { |
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 don't understand this change.
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.
The ! assert.Equal(...)
function evaluates to the same as string(r) != tt.result
but will also output a standard error message from testify
showing clearly the expected and actual value.
So if I understand correctly, this change makes marshalling and unmarshalling match PostgreSQL? If so then this should be fine. |
Yes. It will match PostgresSQL marshaling and unmarshalling, by default excluding the timezone. Additionally, if the data was marshaled using an older version of the |
Fixes #2215