def timezone(location): ''' Get the timezone for a location. ''' try: return l_timezone(location) except UnknownTimeZoneError: pass timestamp = time() coordinates = geocode(location) return l_timezone(request( "timezone", location="{lat},{lng}".format(**coordinates), timestamp=timestamp )['timeZoneId'])
def test_direct_timezone(self): ''' Check if directly passing timezones works. ''' self.assertEqual(timezone('Asia/Calcutta'), l_timezone('Asia/Calcutta'))