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

Handle `DateTime` in addition to `NaiveDateTime` #295

Closed
sgrif opened this Issue Apr 22, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@sgrif
Member

sgrif commented Apr 22, 2016

People trying to use DateTime<UTC> is really common. Perhaps we should write an impl<TZ> ToSql<Timestamp, Pg> for DateTime<TZ> and impl FromSql<Timestamp, Pg> for DateTime<UTC>, where the ToSql impl converts to UTC. I'm concerned this implies more guarantees than exist though, as the database does not contain TZ information on a normal timestamp type column.

@anp

This comment has been minimized.

Contributor

anp commented May 4, 2016

What about supporting timestamp with time zone columns for PG? There would be a clear (in my mind) mapping:

  • NaiveDateTime -> timestamp / timestamp without time zone
  • DateTime<Tz> -> timestamptz / timestamp with time zone

EDIT: related to #106

@sgrif

This comment has been minimized.

Member

sgrif commented May 4, 2016

Yes that is the plan

On Wed, May 4, 2016, 1:49 PM Adam Perry notifications@github.com wrote:

What about supporting timestamp with time zone columns for PG? There
would be a clear (in my mind) mapping:

  • NaiveDateTime -> timestamp / timestamp without time zone
  • DateTime -> timestamptz / timestamp with time zone


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#295 (comment)

sgrif added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
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 added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
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 added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
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 added a commit that referenced this issue Aug 18, 2016

Add support for timestamp with time zone
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 closed this in #409 Aug 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment