def _get_timezone_distance(self, offset):
'''
Return the distance between the local timezone and
the one with offset 'offset'.
:param offset: the distance of a timezone to GMT.
:type offset: int
:returns: distance between local offset and param offset.
:rtype: int
'''
timezones = range(-11, 13)
tz1 = offset
tz2 = self._local_offset
distance = abs(timezones.index(tz1) - timezones.index(tz2))
if distance > 12:
if tz1 < 0:
distance = timezones.index(tz1) + timezones[::-1].index(tz2)
else:
distance = timezones[::-1].index(tz1) + timezones.index(tz2)
return distance
评论列表
文章目录