Can anyone please help explain about the following. why don't I get even numbers for the hours?
I'm running Python 3.10. The following is from ptpython session:
>>> import pytz
... from datetime import datetime
...
... # Define time zones for Eastern Time and Pacific Time
... eastern_timezone = pytz.timezone("US/Eastern")
... pacific_timezone = pytz.timezone("US/Pacific")
...
... # Create datetime objects with accurate timezone offsets
... dt1 = datetime(2023, 1, 1, 11, 0, 0, 0, tzinfo=eastern_timezone) # Eastern Time
... dt2 = datetime(2023, 1, 1, 8, 0, 0, 0, tzinfo=pacific_timezone) # Pacific Time
...
... print(dt1)
... print(dt2)
2023-01-01 11:00:00-04:56
2023-01-01 08:00:00-07:53
>>> dt1 - dt2
datetime.timedelta(seconds=180)
*********
Update: The issue is pytz. It should not be used for timezone after Python 3.9. https://pypi.org/project/pytz-deprecation-shim/
I'm running Python 3.10. The following is from ptpython session:
`>>> import pytz
... from datetime import datetime
...
... # Define time zones for Eastern Time and Pacific Time
... eastern_timezone = pytz.timezone("US/Eastern")
... pacific_timezone = pytz.timezone("US/Pacific")
...
... # Create datetime objects with accurate timezone offsets
... dt1 = datetime(2023, 1, 1, 11, 0, 0, 0, tzinfo=eastern_timezone) # Eastern Time
... dt2 = datetime(2023, 1, 1, 8, 0, 0, 0, tzinfo=pacific_timezone) # Pacific Time
...
... print(dt1)
... print(dt2)
2023-01-01 11:00:00-04:56
2023-01-01 08:00:00-07:53
>>> dt1 - dt2
datetime.timedelta(seconds=180)
`*********
Update: The issue is pytz. It should not be used for timezone after Python 3.9. https://pypi.org/project/pytz-deprecation-shim/
Quote:pytz has served the Python community well for many years, but it is no longer the best option for providing time zones. pytz has a non-standard interface that is very easy to misuse; this interface was necessary when pytz was created, because datetime had no way to represent ambiguous datetimes, but this was solved in in Python 3.6, which added a fold attribute to datetimes in PEP 495. With the addition of the zoneinfo module in Python 3.9 (PEP 615), there has never been a better time to migrate away from pytz.