Пример #1
0
    def test_create_from_fixed_gmt_offset(self):
        raw = dict(foo="bar")
        tz = from_fixed_gmt_offset(self.timezone_gmt_offset_hours, raw)

        self.assertEqual(tz.raw['foo'], 'bar')
        # pytz.FixedOffset is not an instanse of pytz.tzinfo.BaseTzInfo.
        self.assertIsInstance(tz.pytz_timezone, datetime.tzinfo)

        olson_tz = pytz.timezone(self.timezone_name)
        dt = datetime.datetime.utcnow()
        self.assertEqual(tz.pytz_timezone.utcoffset(dt), olson_tz.utcoffset(dt))
Пример #2
0
    def _parse_json_timezone(self, response):
        self._raise_for_error(response)

        timezone_id = response.get("timezoneId")
        if timezone_id is None:
            # Sometimes (e.g. for Antarctica) GeoNames doesn't return
            # a `timezoneId` value, but it returns GMT offsets.
            # Apparently GeoNames always returns these offsets -- for
            # every single point on the globe.
            raw_offset = response["rawOffset"]
            return from_fixed_gmt_offset(raw_offset, raw=response)
        else:
            return from_timezone_name(timezone_id, raw=response)