def guesstz(request): if request.is_ajax(): if "tz_offset" in request.POST: try: minutes = int(request.POST["tz_offset"]) from tz import guess_timezone return http.HttpResponse(guess_timezone(minutes)) except (ValueError, TypeError): return http.HttpResponseBadRequest() return http.HttpResponseBadRequest()
def test(self): tz_str = 'Asia/Shanghai' utc_time = tz.parseStr2utc('20110417T155959', tz_str) self.assertEqual(utc_time is not None, True) tz_time = tz.parseutc2tz(utc_time, tz_str) self.assertEqual(tz_time is not None, True) self.assertEqual(tz.get_utcnow() is not None, True) # guess timezone # offset from javascript new Date().getTimezoneOffset() mins = -480 # shanghai self.assertEqual(tz.guess_timezone(mins), 'Asia/Shanghai')