]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: fix return value of `DateFromTicks` and `TimeFromTicks` 1061/head
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 10:58:44 +0000 (12:58 +0200)
commit2fe2885ceebafddb6c9356f1e0e98375294f80e9
treed79f8402c3e0c2089b7c91455e227b03c0b9bd37
parentefa7db38c5c6b80a72ea3dc39bc7e300e73b57ff
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