当前位置: 首页>>代码示例>>Python>>正文


Python pytz.exceptions方法代码示例

本文整理汇总了Python中pytz.exceptions方法的典型用法代码示例。如果您正苦于以下问题:Python pytz.exceptions方法的具体用法?Python pytz.exceptions怎么用?Python pytz.exceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pytz的用法示例。


在下文中一共展示了pytz.exceptions方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _localize_or_normalize

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import exceptions [as 别名]
def _localize_or_normalize(self, func, dt, is_dst=False):
        """localize() and normalize() have common code paths

        Args:
          func:
          dt:
          is_dst:  (Default value = 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 = getattr(super(EWSTimeZone, self), func)(dt, is_dst=is_dst)
            except pytz.exceptions.AmbiguousTimeError as exc:
                raise AmbiguousTimeError(str(dt)) from exc
            except pytz.exceptions.NonExistentTimeError as exc:
                raise NonExistentTimeError(str(dt)) from exc
        else:
            res = getattr(super(EWSTimeZone, self), func)(dt)
        if not isinstance(res.tzinfo, EWSTimeZone):
            return res.replace(tzinfo=self.from_pytz(res.tzinfo))
        return res 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:25,代码来源:ewsdatetime.py

示例2: test_nonexistent_raise_coerce

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import exceptions [as 别名]
def test_nonexistent_raise_coerce(self):
        # See issue 13057
        from pytz.exceptions import NonExistentTimeError
        times = ['2015-03-08 01:00', '2015-03-08 02:00', '2015-03-08 03:00']
        index = DatetimeIndex(times)
        tz = 'US/Eastern'
        pytest.raises(NonExistentTimeError,
                      index.tz_localize, tz=tz)
        pytest.raises(NonExistentTimeError,
                      index.tz_localize, tz=tz, errors='raise')
        result = index.tz_localize(tz=tz, errors='coerce')
        test_times = ['2015-03-08 01:00-05:00', 'NaT',
                      '2015-03-08 03:00-04:00']
        expected = DatetimeIndex(test_times)\
            .tz_localize('UTC').tz_convert('US/Eastern')
        tm.assert_index_equal(result, expected)

    # test utility methods 
开发者ID:securityclippy,项目名称:elasticintel,代码行数:20,代码来源:test_timezones.py

示例3: localzone

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import exceptions [as 别名]
def localzone(cls):
        try:
            tz = tzlocal.get_localzone()
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnknownTimeZone("Failed to guess local timezone")
        return cls.from_pytz(tz) 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:8,代码来源:ewsdatetime.py

示例4: timezone

# 需要导入模块: import pytz [as 别名]
# 或者: from pytz import exceptions [as 别名]
def timezone(cls, location):
        # Like pytz.timezone() but returning EWSTimeZone instances
        try:
            tz = pytz.timezone(location)
        except pytz.exceptions.UnknownTimeZoneError:
            raise UnknownTimeZone("Timezone '%s' is unknown by pytz" % location)
        return cls.from_pytz(tz) 
开发者ID:ecederstrand,项目名称:exchangelib,代码行数:9,代码来源:ewsdatetime.py


注:本文中的pytz.exceptions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。