I am not sure what is going wrong with the following snippet of code:
from datetime import datetime
import pytz
time_us_pacific = datetime(2017, 3, 16, 14, 30).replace(tzinfo=pytz.timezone("America/Los_Angeles"))
time_india = time_us_pacific.astimezone(pytz.timezone("Asia/Kolkata"))
print(time_india)
# Actual: 2017-03-17 03:53:00+05:30
# Expected: 2017-03-17 03:00:00+05:30
# Picking a date before DST switch:
time_us_pacific = datetime(2017, 2, 16, 14, 30).replace(tzinfo=pytz.timezone("America/Los_Angeles"))
time_india = time_us_pacific.astimezone(pytz.timezone("Asia/Kolkata"))
print(time_india)
# Actual: 2017-03-17 03:53:00+05:30
# Expected: 2017-03-17 04:00:00+05:30
There seem to be two issues:
pytz
timezones are not accounting for DST- The India timezone seems to prefer the more arcane local mean time (LMT) as opposed to Indian Standard Time
My application needs to do some serious timezone-based accounting of events and cannot afford to screw things up. My questions are:
- Am I using Python
datetime
andpytz
incorrectly? - Should I be using something else in place of
pytz
?
Thanks for any help or insights.