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

Timestamp with time zone decodes to different locations with different encodings #107

Open
bvisness opened this issue May 27, 2021 · 1 comment

Comments

@bvisness
Copy link

I'm not sure this is a bug you can or should do anything about, but I figured you should be made aware of it.

The timestamp with time zone (timestamptz) type decodes with different time.Location values depending on the encoding:

  • DecodeText yields a time.Time with location time.UTC
  • DecodeBinary yields a time.Time with location time.Local

You can see this for yourself by running the modified tests found in this commit: bvisness@a859409

The reason for this, I think, is that DecodeText uses time.Parse with a format string like "2006-01-02 15:04:05.999999999Z07:00:00". The problem is Z; time.Parse does not recognize Z as a valid timezone specifier and so falls back to parsing as UTC. DecodeBinary simply uses time.Unix, which always produces a local Go time.

As I said, I'm not even really sure if this is a bug since I'm not sure we should depend on a particular time.Location from Postgres, given that the timestamptz from Postgres does not contain any location information. Arguably it could always produce a UTC time, since it's always stored in Postgres as UTC, but as a fully qualified time I'm not sure it even matters.

If anything, the worst part is that there is a discrepancy between the two encodings.

Feel free to close if you don't think it's worth doing anything about!

@jackc
Copy link
Owner

jackc commented May 29, 2021

The problem is Z; time.Parse does not recognize Z as a valid timezone specifier and so falls back to parsing as UTC.

It ends up in UTC, but it does handle the +7 offset.

I agree the situation is not ideal, but I'm not sure what would be an improvement. And then there's the problem of not breaking backwards compatibility.

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

No branches or pull requests

2 participants