Use Pendulum as a drop-in replacement for native Python datetimes
masterPendulum provides classes that inherit from Python's native datetime objects, making them drop-in replacements. It ensures correct timezone handling by performing comparisons in UTC or within the specific timezone of the datetime being used.
Note that the default timezone for Pendulum (except when calling now()) is always UTC.
import pendulum
# Create datetimes with specific timezones
dt_toronto = pendulum.datetime(2012, 1, 1, tz='America/Toronto')
dt_vancouver = pendulum.datetime(2012, 1, 1, tz='America/Vancouver')
# Perform timezone-aware differences
print(dt_vancouver.diff(dt_toronto).in_hours())