Python pass tzinfo to naive datetime without pytz
For what it's worth, the answer @skyl provided is more-or-less equivalent to what pytz
does.
Here is the relevant pytz
source. It just calls replace
on the datetime
object with the tzinfo
kwarg:
def localize(self, dt, is_dst=False):
'''Convert naive time to local time'''
if dt.tzinfo is not None:
raise ValueError('Not naive datetime (tzinfo is already set)')
return dt.replace(tzinfo=self)
Use x_dt.replace(tzinfo=Eastern)
(found from this Google Groups thread).
x_dt.replace(tzinfo=Eastern).utcoffset()
returns datetime.timedelta(-1, 72000)
which corresponds to -4 hours! (from Question's comment)