Skip to content

Commit

Permalink
Date time overhaul (#1139)
Browse files Browse the repository at this point in the history
Working on overhauling pgrx's `Date`, `Time`, `TimeWithTimeZone`, `Timestamp`, `TimestampWithTimeZone`, and `Interval` types.

We now delegate most everything back into Postgres so we're no longer responsible for re-implementing date/time math which is impossible to get correct.

The various types can now actually be constructed, and the ones `with time zone` support construction at a specific timezone and also being shifted to a specific timezone.

I've also ripped out support for the `time`  crate -- the code around that is too much highly-specific knowledge between both Postgres and `time` in order to confidently maintain going forward.  Users that use that will need to make their own wrappers to and implement `time` support themselves.

Some key changes and features are:

- [x] Better error handling -- need to invent a custom error type instead of the generic `PgSqlErrorCodes`
- [x] More `impl From` conversions between the types
- [x] `impl Add/Sub`
- ~~`impl Index` if possible so that `let hour = timestamp[DateTimeParts::Hour];` ~~ not possible
- [x] Drastically simplify the `Serialize` implementations and also properly implement the corresponding `Deserialize` trait
- [x] doc comments
- [x] additional unit tests
- [x] top-level constructor functions like `now()`, `current_timestamp()`, etc. 
- [x] misc. functions from https://www.postgresql.org/docs/15/functions-datetime.html like `age` and `date_trunc`
- [x] an example that shows off some of the simple usage
  • Loading branch information
eeeebbbbrrrr authored May 23, 2023
1 parent 3fe365f commit 49463a8
Show file tree
Hide file tree
Showing 28 changed files with 3,000 additions and 719 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ jobs:
- name: Run custom_sql example tests
run: cargo test --package custom_sql --features "pg$PG_VER" --no-default-features

- name: Run datetime example tests
run: cargo test --package datetime --features "pg$PG_VER" --no-default-features

- name: Run errors example tests
run: cargo test --package errors --features "pg$PG_VER" --no-default-features

Expand Down
Loading

0 comments on commit 49463a8

Please sign in to comment.