sdispater / pendulum

Python datetimes made easy
https://pendulum.eustace.io
MIT License
6.21k stars 384 forks source link

v2.8.1 broke Pendulum math and timezone awareness #835

Closed mikenerone closed 3 months ago

mikenerone commented 3 months ago

Issue

v2.8.1 has broken the timezone awareness of pendulum objects

In [1]: import pendulum
   ...: from pydantic_extra_types.pendulum_dt import DateTime as pet_DateTime
   ...: from pydantic import TypeAdapter
   ...:
   ...: pet_DateTime_adapter = TypeAdapter(pet_DateTime)
   ...:
   ...: p_dt = pendulum.parse("2024-06-01T15:56:16.829203-05:00")
   ...: pet_dt = pet_DateTime_adapter.validate_python("2024-06-01T15:56:16.829203-05:00")

In [2]: p_dt.tz, p_dt.tzinfo  # What we expect with a straight pendulum DateTime
Out[2]: (FixedTimezone(-18000, name="-05:00"), FixedTimezone(-18000, name="-05:00"))

In [3]: pet_dt.tz, pet_dt.tzinfo  # What we get instead with a pydantic-extra-types DateTime
Out[3]: (None, TzInfo(-05:00))

This has knock-on effects of breaking math that requires these tz values, typically losing timezone in the results.

In [4]: p_dt.subtract(days=1)  # What we expect with a straight pendulum DateTime
Out[4]: DateTime(2024, 5, 31, 15, 56, 16, 829203, tzinfo=FixedTimezone(-18000, name="-05:00"))

In [5]: pet_dt.subtract(days=1)  # What we get instead with a pydantic-extra-types DateTime
Out[5]: DateTime(2024, 5, 31, 15, 56, 16, 829203)
mikenerone commented 3 months ago

My apologies. I totally posted this issue in the wrong repo. :D