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

Add support for timestamp with time zone #409

Merged
merged 1 commit into from Aug 18, 2016
Merged

Add support for timestamp with time zone #409

merged 1 commit into from Aug 18, 2016

Conversation

sgrif
Copy link
Member

@sgrif sgrif commented Aug 18, 2016

This adds support for the timestamp with time zone type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided ToSql implementations for basically all flavors
of DateTime, but I've only provided a FromSql implementation for
DateTime<UTC> and NaiveDateTime. I have not provided any
implementation for std::time::SystemTime, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.

@sgrif
Copy link
Member Author

sgrif commented Aug 18, 2016

Review? @diesel-rs/contributors

@killercup
Copy link
Member

LGTM, though I'd probably add a few tests for edge cases like inserting a datetime in one time zone and trying to get it out in another. Is this a feature that is regularly used? Do you want to add some docs for that (even if you copying the ones from timestamp)?

@sgrif
Copy link
Member Author

sgrif commented Aug 18, 2016

You mean documentation for the SQL type itself? Yeah I'll update that PR adding those docs after I merge this.

This adds support for the `timestamp with time zone` type. This is part
of the SQL standard, but not supported explicitly by SQLite as far as I
can tell. As such I've made it a PG specific type for now.

timestamp with time zone does not actually mean that a time zone is
stored. It instead means that when dealing with strings, Postgres will
no longer ignore the time zone portion. It will convert the time zone to
UTC for storage. When transmitted as text, it will be converted to the
database's local time zone. When transmitted as binary, it will be sent
as UTC.

As such, I've provided `ToSql` implementations for basically all flavors
of `DateTime`, but I've only provided a `FromSql` implementation for
`DateTime<UTC>` and `NaiveDateTime`. I have not provided any
implementation for `std::time::SystemTime`, as it implies local time
zone for the machine and we do not have the tools to handle the
conversion in the standard library.

Fixes #106.
Fixes #295.
Fixes #402.
@sgrif sgrif merged commit b6b56c9 into master Aug 18, 2016
@sgrif sgrif deleted the sg-timestamptz branch August 18, 2016 17:14
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.

None yet

2 participants