]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: fix return value of `DateFromTicks` and `TimeFromTicks`
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 1 May 2025 17:38:18 +0000 (19:38 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 4 May 2025 11:05:19 +0000 (13:05 +0200)
commite910e6a2707c77e089af7b1ee67901e5cd6709a3
tree7e946b94ba78adbc6f660b8244146cd8600e0f8c
parent9a7586f2e6e249643d169937858c5fd7174a9d8b
fix: fix return value of `DateFromTicks` and `TimeFromTicks`

These function are based on the return value of `TimestampFromTicks`.
Because this value returned by this function is timezone-aware and
localized to the current timezone, truncating the value (and implicitly
losing the timezone) might return the wrong result.

For example, at tick 0, in NY, it was 1969-12-31T19:00-05:00. By
truncating the timestamp on the date, the date would be the 1969-12-31
instead of the expected 1970-01-01.

This changeset actually changes `TimestampFromTicks` to return an UTC
timestamp instead of a local timestamp. We believe that this change is
not a problem because we don't change neither the type (tz-aware
datetime) nor the value of the returned object (old and new values
compare equal). An alternative would have been to decouple the Timestamp
function from the Date/Time functions, but I think it would be confusing
if the Timestamp function returned a datetime with the date in 1969 but the
Date function returned a date in 1970.

Adjust the tests to be *stricter* than before, making use of the fact
that now the output is not affected by the local timezone.

Close #1058.
docs/news.rst
psycopg/psycopg/dbapi20.py
tests/test_psycopg_dbapi20.py