本文整理汇总了Python中alignak.objects.timeperiod.Timeperiod.resolve_daterange方法的典型用法代码示例。如果您正苦于以下问题:Python Timeperiod.resolve_daterange方法的具体用法?Python Timeperiod.resolve_daterange怎么用?Python Timeperiod.resolve_daterange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alignak.objects.timeperiod.Timeperiod
的用法示例。
在下文中一共展示了Timeperiod.resolve_daterange方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_monweekday_timeperiod_with_exclude
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_monweekday_timeperiod_with_exclude(self):
"""
Test mon week day timeperiod with exclude
:return: None
"""
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
# Then a funny daterange
print("Testing daterange", 'tuesday -1 july - monday 1 september 16:30-24:00')
timeperiod = Timeperiod()
timeperiod.timeperiod_name = 'T1'
timeperiod.resolve_daterange(timeperiod.dateranges,
'tuesday -1 july - monday 1 september 16:30-24:00')
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print("Next without exclude", t_next)
self.assertEqual("Tue Jul 27 16:30:00 2010", t_next)
# Now we add this timeperiod an exception
# and from april (before) to august monday 3 (monday 16 august),
t2 = Timeperiod()
t2.timeperiod_name = 'T2'
t2.resolve_daterange(t2.dateranges, 'thursday 1 april - monday 3 august 00:00-24:00')
timeperiod.exclude = [t2]
timeperiod.cache = {}
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
self.assertEqual('Tue Aug 17 16:30:00 2010', t_next)
示例2: test_mondayweek_timeperiod_with_exclude
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_mondayweek_timeperiod_with_exclude(self):
"""
Test monday week timeperiod with exclude
:return: None
"""
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
# Then a simple same day
timeperiod = Timeperiod()
timeperiod.timeperiod_name = 'T1'
timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 3 16:30-24:00')
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
self.assertEqual("Tue Jul 20 16:30:00 2010", t_next)
# Now we add this timeperiod an exception
# And a good one: from april (so before) to august (after), and full time.
# But the 17 is a tuesday, but the 3 of august, so the next 3 tuesday is
# ..... the Tue Sep 21 :) Yes, we should wait quite a lot :)
t2 = Timeperiod()
t2.timeperiod_name = 'T2'
t2.resolve_daterange(t2.dateranges, 'april 1 - august 23 00:00-24:00')
timeperiod.exclude = [t2]
timeperiod.cache = {}
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
self.assertEqual('Tue Sep 21 16:30:00 2010', t_next)
t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
t_exclude_inv = time.asctime(time.localtime(t_exclude_inv))
self.assertEqual('Tue Aug 24 00:00:00 2010', t_exclude_inv)
示例3: test_dayweek_timeperiod_with_exclude
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_dayweek_timeperiod_with_exclude(self):
self.print_header()
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
# Then a simple same day
t = Timeperiod()
t.timeperiod_name = 'T1'
t.resolve_daterange(t.dateranges, 'tuesday 2 16:30-24:00')
t_next = t.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print "T next", t_next
self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)
# Now we add this timeperiod an exception
t2 = Timeperiod()
t2.timeperiod_name = 'T2'
t2.resolve_daterange(t2.dateranges, 'tuesday 00:00-23:58')
t.exclude = [t2]
# We are a bad boy: first time period want a tuesday
# but exclude do not want it until 23:58. So next is 58 + 1second :)
t.cache = {}
t_next = t.get_next_valid_time_from_t(july_the_12)
t_exclude = t2.get_next_valid_time_from_t(july_the_12)
t_exclude_inv = t2.get_next_invalid_time_from_t(july_the_12)
print "T next raw", t_next
t_next = time.asctime(time.localtime(t_next))
print "TOTO T next", t_next
self.assertEqual('Tue Jul 13 23:58:01 2010', t_next)
示例4: test_simple_with_multiple_time
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_simple_with_multiple_time(self):
"""
Test timeperiod with 2 ranges:
* tuesday 00:00-07:00
* tuesday 21:30-24:00
:return: None
"""
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
print(july_the_12)
# Then a simple same day
print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
timeperiod = Timeperiod()
timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print("RES:", t_next)
self.assertEqual("Tue Jul 13 00:00:00 2010", t_next)
# Now ask about at 00:00 time?
july_the_12 = time.mktime(time.strptime("12 Jul 2010 00:00:00", "%d %b %Y %H:%M:%S"))
# Then a simple same day
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print("Next?", t_next)
self.assertEqual("Tue Jul 13 00:00:00 2010", t_next)
示例5: test_resolve_daterange_case23
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_resolve_daterange_case23(self):
""" Test resolve daterange, case 23
:return: None
"""
timeperiod = Timeperiod()
entry = 'sunday 00:00-24:00'
timeperiod.resolve_daterange(timeperiod.dateranges, entry)
assert 'sunday' == timeperiod.dateranges[0].day
示例6: test_timeperiod_no_daterange
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_timeperiod_no_daterange(self):
"""
Test with a timeperiod have no daterange
:return: None
"""
now = time.time()
timeperiod = Timeperiod()
timeperiod.resolve_daterange(timeperiod.dateranges, '1999-01-28 00:00-24:00')
t_next = timeperiod.get_next_valid_time_from_t(now)
self.assertIsNone(t_next)
示例7: test_get_valid_time
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_get_valid_time(self):
"""
Test get next valid time
:return: None
"""
timeperiod = Timeperiod()
timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-24:00')
first_nov = int(time.mktime(time.strptime("26 Oct 2010 00:00:00", "%d %b %Y %H:%M:%S")))
print(first_nov)
start = timeperiod.get_next_valid_time_from_t(first_nov)
self.assertIsNotNone(start)
start = time.asctime(time.localtime(start))
self.assertEqual("Mon Nov 1 00:00:00 2010", start)
示例8: test_dayweek_exclusion_timeperiod
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_dayweek_exclusion_timeperiod(self):
"""
Test week day timeperiod with exclusion
:return: None
"""
now = time.time()
# Get the 13 of july 2010 at 15:00, tuesday
july_the_13 = time.mktime(time.strptime("13 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
print(july_the_13)
# Now we add this timeperiod an exception
timeperiod = Timeperiod()
timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-24:00')
timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 00:00-24:00')
timeperiod.resolve_daterange(timeperiod.dateranges, 'wednesday 00:00-24:00')
t2 = Timeperiod()
t2.timeperiod_name = ''
t2.resolve_daterange(t2.dateranges, 'tuesday 00:00-24:00')
timeperiod.exclude = [t2]
t_next = timeperiod.get_next_valid_time_from_t(july_the_13)
t_next = time.asctime(time.localtime(t_next))
print("T next", t_next)
self.assertEqual("Wed Jul 14 00:00:00 2010", t_next)
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
t_inv = timeperiod.get_next_invalid_time_from_t(july_the_12)
t_inv = time.asctime(time.localtime(t_inv))
self.assertEqual('Tue Jul 13 00:00:00 2010', t_inv)
示例9: test_next_invalid_day
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_next_invalid_day(self):
self.print_header()
# Get the 13 of july 2010 at 15:00, tuesday
july_the_13 = time.mktime(time.strptime("13 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
print july_the_13
t = Timeperiod()
t.timeperiod_name = 'test_next_invalid_day'
t.resolve_daterange(t.dateranges, 'tuesday 00:00-24:00')
t.exclude = []
t_next_invalid = t.get_next_invalid_time_from_t(july_the_13)
t_next_invalid = time.asctime(time.localtime(t_next_invalid))
print "T next invalid", t_next_invalid
self.assertEqual("Wed Jul 14 00:00:01 2010", t_next_invalid)
示例10: test_resolve_daterange_case12
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_resolve_daterange_case12(self):
t = Timeperiod()
entry = 'tuesday 3 july - friday 2 september 00:00-24:00'
t.resolve_daterange(t.dateranges, entry)
self.assertEqual(0, t.dateranges[0].syear)
self.assertEqual(7, t.dateranges[0].smon)
self.assertEqual(0, t.dateranges[0].smday)
self.assertEqual(1, t.dateranges[0].swday)
self.assertEqual(3, t.dateranges[0].swday_offset)
self.assertEqual(0, t.dateranges[0].eyear)
self.assertEqual(9, t.dateranges[0].emon)
self.assertEqual(0, t.dateranges[0].emday)
self.assertEqual(4, t.dateranges[0].ewday)
self.assertEqual(2, t.dateranges[0].ewday_offset)
self.assertEqual(0, t.dateranges[0].skip_interval)
self.assertEqual('00:00-24:00', t.dateranges[0].other)
示例11: test_resolve_daterange_case5
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_resolve_daterange_case5(self):
t = Timeperiod()
entry = 'tuesday 1 october - friday 2 may / 6 00:00-24:00'
t.resolve_daterange(t.dateranges, entry)
self.assertEqual(0, t.dateranges[0].syear)
self.assertEqual(10, t.dateranges[0].smon)
self.assertEqual(0, t.dateranges[0].smday)
self.assertEqual(1, t.dateranges[0].swday)
self.assertEqual(1, t.dateranges[0].swday_offset)
self.assertEqual(0, t.dateranges[0].eyear)
self.assertEqual(5, t.dateranges[0].emon)
self.assertEqual(0, t.dateranges[0].emday)
self.assertEqual(4, t.dateranges[0].ewday)
self.assertEqual(2, t.dateranges[0].ewday_offset)
self.assertEqual(6, t.dateranges[0].skip_interval)
self.assertEqual('00:00-24:00', t.dateranges[0].other)
示例12: test_resolve_daterange_case17
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_resolve_daterange_case17(self):
t = Timeperiod()
entry = 'april 10 - may 15 00:00-24:00'
t.resolve_daterange(t.dateranges, entry)
self.assertEqual(0, t.dateranges[0].syear)
self.assertEqual(4, t.dateranges[0].smon)
self.assertEqual(10, t.dateranges[0].smday)
self.assertEqual(0, t.dateranges[0].swday)
self.assertEqual(0, t.dateranges[0].swday_offset)
self.assertEqual(0, t.dateranges[0].eyear)
self.assertEqual(5, t.dateranges[0].emon)
self.assertEqual(15, t.dateranges[0].emday)
self.assertEqual(0, t.dateranges[0].ewday)
self.assertEqual(0, t.dateranges[0].ewday_offset)
self.assertEqual(0, t.dateranges[0].skip_interval)
self.assertEqual('00:00-24:00', t.dateranges[0].other)
示例13: test_simple_with_multiple_time_multiple_days
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_simple_with_multiple_time_multiple_days(self):
"""
Test timeperiod with multiple daterange on multiple days:
* monday 00:00-07:00
* monday 21:30-24:00
* tuesday 00:00-07:00
* tuesday 21:30-24:00
:return: None
"""
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
print(july_the_12)
# Then a simple same day
timeperiod = Timeperiod()
print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
timeperiod.resolve_daterange(timeperiod.dateranges, 'monday 00:00-07:00,21:30-24:00')
timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 00:00-07:00,21:30-24:00')
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print("RES:", t_next)
self.assertEqual("Mon Jul 12 21:30:00 2010", t_next)
# what about the next invalid?
t_next_inv = timeperiod.get_next_invalid_time_from_t(july_the_12)
t_next_inv = time.asctime(time.localtime(t_next_inv))
print("RES:", t_next_inv)
self.assertEqual("Mon Jul 12 15:00:00 2010", t_next_inv)
# what about a valid time and ask next invalid? Like at 22:00h?
july_the_12 = time.mktime(time.strptime("12 Jul 2010 22:00:00", "%d %b %Y %H:%M:%S"))
t_next_inv = timeperiod.get_next_invalid_time_from_t(july_the_12)
t_next_inv = time.asctime(time.localtime(t_next_inv))
print("RES:", t_next_inv) #, t.is_time_valid(july_the_12)
self.assertEqual("Tue Jul 13 07:00:01 2010", t_next_inv)
# Now ask about at 00:00 time?
july_the_12 = time.mktime(time.strptime("12 Jul 2010 00:00:00", "%d %b %Y %H:%M:%S"))
print("Cheking validity for", time.asctime(time.localtime(july_the_12)))
# Then a simple same day
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print("Next?", t_next)
self.assertEqual("Mon Jul 12 00:00:00 2010", t_next)
示例14: test_simple_timeperiod
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_simple_timeperiod(self):
"""
Test a timeperiod with one timerange
:return: None
"""
now = time.time()
# Get the 12 of july 2010 at 15:00, monday
july_the_12 = time.mktime(time.strptime("12 Jul 2010 15:00:00", "%d %b %Y %H:%M:%S"))
print(july_the_12)
timeperiod = Timeperiod()
timeperiod.resolve_daterange(timeperiod.dateranges, 'tuesday 16:30-24:00')
t_next = timeperiod.get_next_valid_time_from_t(july_the_12)
t_next = time.asctime(time.localtime(t_next))
print(t_next)
self.assertEqual("Tue Jul 13 16:30:00 2010", t_next)
示例15: test_resolve_daterange_case22
# 需要导入模块: from alignak.objects.timeperiod import Timeperiod [as 别名]
# 或者: from alignak.objects.timeperiod.Timeperiod import resolve_daterange [as 别名]
def test_resolve_daterange_case22(self):
t = Timeperiod()
entry = 'day 3 00:00-24:00'
t.resolve_daterange(t.dateranges, entry)
self.assertEqual(0, t.dateranges[0].syear)
self.assertEqual(0, t.dateranges[0].smon)
self.assertEqual(3, t.dateranges[0].smday)
self.assertEqual(0, t.dateranges[0].swday)
self.assertEqual(0, t.dateranges[0].swday_offset)
self.assertEqual(0, t.dateranges[0].eyear)
self.assertEqual(0, t.dateranges[0].emon)
self.assertEqual(3, t.dateranges[0].emday)
self.assertEqual(0, t.dateranges[0].ewday)
self.assertEqual(0, t.dateranges[0].ewday_offset)
self.assertEqual(0, t.dateranges[0].skip_interval)
self.assertEqual('00:00-24:00', t.dateranges[0].other)