+ >>> o.hour == h
+ True
+
+ """
+ return datetime.datetime(
+ dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second, dt.microsecond,
+ tzinfo=tz
+ )
+
+
+def translate_timezone(dt: datetime.datetime,
+ tz: datetime.tzinfo) -> datetime.datetime:
+ """
+ Translates dt into a different timezone by adjusting the year, month,
+ day, hour, minute, second, micro, etc... appropriately. The returned
+ dt is the same instant in another timezone.
+
+ >>> from pytz import UTC
+ >>> 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.hour == h
+ False