當前位置: 首頁>>代碼示例>>Python>>正文


Python exceptions.AmbiguousTimeError方法代碼示例

本文整理匯總了Python中pytz.exceptions.AmbiguousTimeError方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.AmbiguousTimeError方法的具體用法?Python exceptions.AmbiguousTimeError怎麽用?Python exceptions.AmbiguousTimeError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pytz.exceptions的用法示例。


在下文中一共展示了exceptions.AmbiguousTimeError方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: utcoffset

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def utcoffset(self, dt, is_dst=None):
        '''See datetime.tzinfo.utcoffset

        The is_dst parameter may be used to remove ambiguity during DST
        transitions.

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
        >>> ambiguous = datetime(2009, 10, 31, 23, 30)

        >>> str(tz.utcoffset(ambiguous, is_dst=False))
        '-1 day, 20:30:00'

        >>> str(tz.utcoffset(ambiguous, is_dst=True))
        '-1 day, 21:30:00'

        >>> try:
        ...     tz.utcoffset(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous

        '''
        if dt is None:
            return None
        elif dt.tzinfo is not self:
            dt = self.localize(dt, is_dst)
            return dt.tzinfo._utcoffset
        else:
            return self._utcoffset 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:32,代碼來源:tzinfo.py

示例2: dst

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def dst(self, dt, is_dst=None):
        '''See datetime.tzinfo.dst

        The is_dst parameter may be used to remove ambiguity during DST
        transitions.

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')

        >>> normal = datetime(2009, 9, 1)

        >>> str(tz.dst(normal))
        '1:00:00'
        >>> str(tz.dst(normal, is_dst=False))
        '1:00:00'
        >>> str(tz.dst(normal, is_dst=True))
        '1:00:00'

        >>> ambiguous = datetime(2009, 10, 31, 23, 30)

        >>> str(tz.dst(ambiguous, is_dst=False))
        '0:00:00'
        >>> str(tz.dst(ambiguous, is_dst=True))
        '1:00:00'
        >>> try:
        ...     tz.dst(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous

        '''
        if dt is None:
            return None
        elif dt.tzinfo is not self:
            dt = self.localize(dt, is_dst)
            return dt.tzinfo._dst
        else:
            return self._dst 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:40,代碼來源:tzinfo.py

示例3: tzname

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def tzname(self, dt, is_dst=None):
        '''See datetime.tzinfo.tzname

        The is_dst parameter may be used to remove ambiguity during DST
        transitions.

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')

        >>> normal = datetime(2009, 9, 1)

        >>> tz.tzname(normal)
        'NDT'
        >>> tz.tzname(normal, is_dst=False)
        'NDT'
        >>> tz.tzname(normal, is_dst=True)
        'NDT'

        >>> ambiguous = datetime(2009, 10, 31, 23, 30)

        >>> tz.tzname(ambiguous, is_dst=False)
        'NST'
        >>> tz.tzname(ambiguous, is_dst=True)
        'NDT'
        >>> try:
        ...     tz.tzname(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous
        '''
        if dt is None:
            return self.zone
        elif dt.tzinfo is not self:
            dt = self.localize(dt, is_dst)
            return dt.tzinfo._tzname
        else:
            return self._tzname 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:39,代碼來源:tzinfo.py

示例4: test_tz_localize_ambiguous_bool

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def test_tz_localize_ambiguous_bool(self):
        # make sure that we are correctly accepting bool values as ambiguous
        # GH#14402
        ts = Timestamp('2015-11-01 01:00:03')
        expected0 = Timestamp('2015-11-01 01:00:03-0500', tz='US/Central')
        expected1 = Timestamp('2015-11-01 01:00:03-0600', tz='US/Central')

        with pytest.raises(pytz.AmbiguousTimeError):
            ts.tz_localize('US/Central')

        result = ts.tz_localize('US/Central', ambiguous=True)
        assert result == expected0

        result = ts.tz_localize('US/Central', ambiguous=False)
        assert result == expected1 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:17,代碼來源:test_timezones.py

示例5: test_tz_localize_errors_ambiguous

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def test_tz_localize_errors_ambiguous(self):
        # GH#13057
        ts = Timestamp('2015-11-1 01:00')
        with pytest.raises(AmbiguousTimeError):
            with tm.assert_produces_warning(FutureWarning):
                ts.tz_localize('US/Pacific', errors='coerce') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_timezones.py

示例6: utcoffset

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def utcoffset(self, dt, is_dst=None):
        '''See datetime.tzinfo.utcoffset

        The is_dst parameter may be used to remove ambiguity during DST
        transitions.

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')
        >>> ambiguous = datetime(2009, 10, 31, 23, 30)

        >>> tz.utcoffset(ambiguous, is_dst=False)
        datetime.timedelta(-1, 73800)

        >>> tz.utcoffset(ambiguous, is_dst=True)
        datetime.timedelta(-1, 77400)

        >>> try:
        ...     tz.utcoffset(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous

        '''
        if dt is None:
            return None
        elif dt.tzinfo is not self:
            dt = self.localize(dt, is_dst)
            return dt.tzinfo._utcoffset
        else:
            return self._utcoffset 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:32,代碼來源:tzinfo.py

示例7: dst

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def dst(self, dt, is_dst=None):
        '''See datetime.tzinfo.dst

        The is_dst parameter may be used to remove ambiguity during DST
        transitions.

        >>> from pytz import timezone
        >>> tz = timezone('America/St_Johns')

        >>> normal = datetime(2009, 9, 1)

        >>> tz.dst(normal)
        datetime.timedelta(0, 3600)
        >>> tz.dst(normal, is_dst=False)
        datetime.timedelta(0, 3600)
        >>> tz.dst(normal, is_dst=True)
        datetime.timedelta(0, 3600)

        >>> ambiguous = datetime(2009, 10, 31, 23, 30)

        >>> tz.dst(ambiguous, is_dst=False)
        datetime.timedelta(0)
        >>> tz.dst(ambiguous, is_dst=True)
        datetime.timedelta(0, 3600)
        >>> try:
        ...     tz.dst(ambiguous)
        ... except AmbiguousTimeError:
        ...     print('Ambiguous')
        Ambiguous

        '''
        if dt is None:
            return None
        elif dt.tzinfo is not self:
            dt = self.localize(dt, is_dst)
            return dt.tzinfo._dst
        else:
            return self._dst 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:40,代碼來源:tzinfo.py

示例8: test_tz_localize_errors_ambiguous

# 需要導入模塊: from pytz import exceptions [as 別名]
# 或者: from pytz.exceptions import AmbiguousTimeError [as 別名]
def test_tz_localize_errors_ambiguous(self):
        # GH#13057
        ts = Timestamp('2015-11-1 01:00')
        with pytest.raises(AmbiguousTimeError):
            ts.tz_localize('US/Pacific', errors='coerce') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:7,代碼來源:test_timezones.py


注:本文中的pytz.exceptions.AmbiguousTimeError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。