why do datetime.datetime and pendulum.datetime produce different results

30 views Asked by At

Why datetime and pendulum produce different results in that code snippet? What am I missing?

from pytz import timezone
from pendulum import datetime as pendulum_datetime
from datetime import datetime as datetime_datetime

tz = timezone('US/Eastern')
# both `dt_pendulum` and `dt_dt` represent the same point in time: 2022, March 25, 10am (in US/Eastern)
dt_pendulum = pendulum_datetime(2022, 3, 25, 10, 0, tz=tz)
dt_dt = datetime_datetime(2022, 3, 25, 10, 0, tzinfo=tz)

# both datetimes are further converted to `US/Pacific`
# thus, they still represent the same point in time, just in different time zone.
dt_pendulum_pacific = dt_pendulum.astimezone(tz=timezone('US/Pacific'))
dt_dt_pacific = dt_dt.astimezone(tz=timezone('US/Pacific'))

print(dt_pendulum_pacific)
print(dt_dt_pacific)

produces:

2022-03-25T07:00:00-07:00
2022-03-25 07:56:00-07:00

I'm so confused by 07:56 thing returned by datetime. I thought datetime.datetime and pendulum.datetime should produce the same result in that example.

0

There are 0 answers