def localize(self, dt, is_dst=False):
# super() returns a dt.tzinfo of class pytz.tzinfo.FooBar. We need to return type EWSTimeZone
if is_dst is not False:
# Not all pytz timezones support 'is_dst' argument. Only pass it on if it's set explicitly.
try:
res = super(EWSTimeZone, self).localize(dt, is_dst=is_dst)
except pytz.exceptions.AmbiguousTimeError:
raise AmbiguousTimeError(str(dt))
except pytz.exceptions.NonExistentTimeError:
raise NonExistentTimeError(str(dt))
else:
res = super(EWSTimeZone, self).localize(dt)
if not isinstance(res.tzinfo, EWSTimeZone):
return res.replace(tzinfo=self.from_pytz(res.tzinfo))
return res
评论列表
文章目录