day, hour, minute, second, micro, etc... appropriately. The returned
dt is the same instant in another timezone.
- >>> from pytz import UTC
+ >>> import pytz
>>> d = now_pacific()
>>> d.tzinfo.tzname(d)[0] # Note: could be PST or PDT
'P'
>>> h = d.hour
- >>> o = translate_timezone(d, UTC)
- >>> o.tzinfo.tzname(o)
- 'UTC'
+ >>> o = translate_timezone(d, pytz.timezone('US/Eastern'))
+ >>> o.tzinfo.tzname(o)[0] # Again, could be EST or EDT
+ 'E'
>>> o.hour == h
False
-
+ >>> expected = h + 3 # Three hours later in E?T than P?T
+ >>> expected = expected % 24 # Handle edge case
+ >>> expected == o.hour
+ True
"""
- return dt.replace(tzinfo=None).astimezone(tz=tz)
+ return dt.replace().astimezone(tz=tz)
def now() -> datetime.datetime: