sfackler / rust-postgres

Native PostgreSQL driver for the Rust programming language
Apache License 2.0
3.43k stars 436 forks source link

Fix `chrono::DateTime<Utc>` tests #1170

Closed allan2 closed 4 weeks ago

allan2 commented 1 month ago

test_date_time_params and test_with_special_date_time_params could fail when run with a non-UTC system time zone. I encountered these failing tests when writing the tests for jiff.

In Postgres, if no time zone is stated in the input string, then it is assumed to be in system time.[1] This means that in these tests, a correctly parsed DateTime<Utc> could be compared to an incorrectly offset time.

The offset component is now included in the test strings of these tests. This component is already present in the test strings for time::OffsetDateTime.

[1] Postgres docs:

For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone. If no time zone is stated in the input string, then it is assumed to be in the time zone indicated by the system's TimeZone parameter, and is converted to UTC using the offset for the timezone zone.

sfackler commented 4 weeks ago

Thanks!