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


Python Timeperiod.is_time_valid方法代碼示例

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


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

示例1: test_issue_1385

# 需要導入模塊: from alignak.objects.timeperiod import Timeperiod [as 別名]
# 或者: from alignak.objects.timeperiod.Timeperiod import is_time_valid [as 別名]
    def test_issue_1385(self):
        """
        https://github.com/naparuba/shinken/issues/1385
        """
        tp = Timeperiod()
        tp.timeperiod_name = 'mercredi2-22-02'
        tp.resolve_daterange(tp.dateranges, 'wednesday 2              00:00-02:00,22:00-24:00')
        tp.resolve_daterange(tp.dateranges, 'thursday 2                00:00-02:00,22:00-24:00')

        valid_times = (
            (2014, 11, 12, 1, 0),  # second wednesday of november @ 01:00
            (2014, 11, 12, 23, 0),  # same @23:00
            (2014, 11, 13, 0, 0),  # second thursday @ 00:00
            # in december:
            (2014, 12, 10, 1, 0),  # second wednesday @ 01:00
            (2014, 12, 10, 23, 0),  # second wednesday @ 23:00
            (2014, 12, 11, 1, 0),  # second thursday @ 01:00
            (2014, 12, 11, 23, 0),  # second thursday @ 23:00
        )
        for valid in valid_times:
            dt = datetime.datetime(*valid)
            valid_tm = time.mktime(dt.timetuple())
            self.assertTrue(tp.is_time_valid(valid_tm))

        invalid_times = (
            (2014, 11, 12, 3, 0),  # second wednesday of november @ 03:00
            (2014, 11, 3, 1, 0),  # first wednesday ..
            (2014, 11, 4, 1, 0),  # first thursday
            (2014, 11, 17, 1, 0),  # third monday
            (2014, 11, 18, 1, 0),  # third tuesday
            # in december:
            (2014, 12, 5, 3, 0),  # first friday
            (2014, 12, 17, 1, 0),  # third wednesday
            (2014, 12, 18, 1, 0),  # third thursday
            (2014, 12, 24, 1, 0),  # fourth wednesday
            (2014, 12, 25, 1, 0),  # fourth thursday
            (2014, 12, 31, 1, 0),
        )
        for invalid in invalid_times:
            dt = datetime.datetime(*invalid)
            invalid_tm = time.mktime(dt.timetuple())
            self.assertFalse(tp.is_time_valid(invalid_tm))
開發者ID:Alignak-monitoring,項目名稱:alignak,代碼行數:44,代碼來源:test_timeperiods.py


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