2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
5 # Gregory Starck, g.starck@gmail.com
7 #This file is part of Shinken.
9 #Shinken is free software: you can redistribute it and/or modify
10 #it under the terms of the GNU Affero General Public License as published by
11 #the Free Software Foundation, either version 3 of the License, or
12 #(at your option) any later version.
14 #Shinken is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU Affero General Public License for more details.
19 #You should have received a copy of the GNU Affero General Public License
20 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
23 #Calendar date: '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' => len = 8 => CALENDAR_DATE
24 # '(\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' => len = 5 => CALENDAR_DATE
25 # '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' => len = 7 => CALENDAR_DATE
26 # '(\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' => len = 4 => CALENDAR_DATE
28 #Month week day:'([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) / (\d+) ([0-9:, -]+)' => len = 8 => MONTH WEEK DAY
29 # ex: wednesday 1 january - thursday 2 july / 3
31 # '([a-z]*) (\d+) - ([a-z]*) (\d+) / (\d+) ([0-9:, -]+)' => len = 6
32 # ex: february 1 - march 15 / 3 => MONTH DATE
33 # ex: monday 2 - thusday 3 / 2 => WEEK DAY
34 # ex: day 2 - day 6 / 3 => MONTH DAY
36 # '([a-z]*) (\d+) - (\d+) / (\d+) ([0-9:, -]+)' => len = 6
37 # ex: february 1 - 15 / 3 => MONTH DATE
38 # ex: thursday 2 - 4 => WEEK DAY
39 # ex: day 1 - 4 => MONTH DAY
41 # '([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 7
42 # ex: wednesday 1 january - thursday 2 july => MONTH WEEK DAY
44 # '([a-z]*) (\d+) - (\d+) ([0-9:, -]+)' => len = 7
45 # ex: thursday 2 - 4 => WEEK DAY
46 # ex: february 1 - 15 / 3 => MONTH DATE
47 # ex: day 1 - 4 => MONTH DAY
49 # '([a-z]*) (\d+) - ([a-z]*) (\d+) ([0-9:, -]+)' => len = 5
50 # ex: february 1 - march 15 => MONTH DATE
51 # ex: monday 2 - thusday 3 => WEEK DAY
52 # ex: day 2 - day 6 => MONTH DAY
54 # '([a-z]*) (\d+) ([0-9:, -]+)' => len = 3
55 # ex: february 3 => MONTH DATE
56 # ex: thursday 2 => WEEK DAY
57 # ex: day 3 => MONTH DAY
59 # '([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 4
60 # ex: thusday 3 february => MONTH WEEK DAY
62 # '([a-z]*) ([0-9:, -]+)' => len = 6
63 # ex: thusday => normal values
73 from shinken
.item
import Item
, Items
74 from shinken
.util
import *
77 from shinken
.daterange
import Daterange
,CalendarDaterange
,StandardDaterange
,MonthWeekDayDaterange
78 from shinken
.daterange
import MonthDateDaterange
,WeekDayDaterange
,MonthDayDaterange
79 from shinken
.brok
import Brok
80 from shinken
.property import UnusedProp
, BoolProp
, IntegerProp
, FloatProp
, CharProp
, StringProp
, ListProp
83 class Timeperiod(Item
):
85 my_type
= 'timeperiod'
88 'timeperiod_name' : StringProp(fill_brok
=['full_status']),
89 'alias' : StringProp(default
='',fill_brok
=['full_status']),
90 'use' : StringProp(default
=''),
91 'exclude' : StringProp(default
=''),
92 'register' : IntegerProp(default
='1'),
93 #All errors and warning raised during the configuration parsing
94 #and taht will raised real warning/errors during the is_correct
95 'configuration_warnings' : ListProp(default
=[]),
96 'configuration_errors' : ListProp(default
=[]),
97 # These are needed if a broker module calls methods on timeperiod objects
98 'dateranges' : ListProp(fill_brok
=['full_status'], default
=[]),
99 'exclude' : ListProp(fill_brok
=['full_status'], default
=[]),
103 def __init__(self
, params
={}):
104 self
.id = Timeperiod
.id
105 Timeperiod
.id = Timeperiod
.id + 1
111 self
.invalid_entries
= []
113 if key
in ['name', 'alias', 'timeperiod_name', 'exclude', 'use', 'register']:
114 setattr(self
, key
, params
[key
])
116 self
.unresolved
.append(key
+' '+params
[key
])
118 self
.cache
= {} #For tunning purpose only
119 self
.configuration_errors
= []
120 self
.configuration_warnings
= []
124 return self
.timeperiod_name
131 #We fillfull properties with template ones if need
132 #for the unresolved values (like sunday ETCETC)
133 def get_unresolved_properties_by_inheritance(self
, items
):
134 #Ok, I do not have prop, Maybe my templates do?
136 for i
in self
.templates
:
137 self
.unresolved
.extend(i
.unresolved
)
141 def is_time_valid(self
, t
):
142 if self
.has('exclude'):
143 for dr
in self
.exclude
:
144 if dr
.is_time_valid(t
):
146 for dr
in self
.dateranges
:
147 if dr
.is_time_valid(t
):
152 #will give the first time > t which is valid
153 def get_min_from_t(self
, t
):
155 for dr
in self
.dateranges
:
156 mins_incl
.append(dr
.get_min_from_t(t
))
157 return min(mins_incl
)
160 #will give the first time > t which is not valid
161 def get_not_in_min_from_t(self
, f
):
165 def find_next_valid_time_from_cache(self
, t
):
172 #clean the get_next_valid_time_from_t cache
173 #The entries are a dict on t. t < now are useless
174 #Because we do not care about past anymore.
175 #If not, it's not important, it's just a cache after all :)
176 def clean_cache(self
):
177 now
= int(time
.time())
186 def get_next_valid_time_from_t(self
, t
):
187 #first find from cache
191 #print self.get_name(), "Check valid time for", time.asctime(time.localtime(t))
193 res_from_cache
= self
.find_next_valid_time_from_cache(t
)
194 if res_from_cache
is not None:
195 return res_from_cache
200 #Loop for all minutes...
202 #print self.get_name(), '\nLoop'
205 for dr
in self
.dateranges
:
206 dr_mins
.append(dr
.get_next_valid_time_from_t(t
))
208 #print "TOTO", self.get_name(), 'Mins:', dr_mins
210 # print "FUCK",time.asctime(time.localtime(o)), "\n"
212 #Min but not the None valus...
214 local_min
= min([d
for d
in dr_mins
if d
!=None])
215 except ValueError: #dr_mins if full of None, not good
218 #if local_min != None:
219 # print "Poposed?", local_min
220 # print "Proposed local min", time.asctime(time.localtime(local_min))
223 #We do not loop unless the local_min is not valid
226 #if we've got a real value, we check it with the exclude
227 if local_min
!= None:
228 #Now check if local_min is not valid
229 for tp
in self
.exclude
:
230 #print self.get_name(), "Check in TP"
231 if tp
.is_time_valid(local_min
):
234 #print self.get_name(), "TP pas content:", tp.get_name(), time.asctime(time.localtime(local_min))
235 local_min
= tp
.get_next_invalid_time_from_t(local_min
+60)
236 #if local_min != None:
237 # print "Exclude TP proposed new local min", time.asctime(time.localtime(local_min))
239 #print "Is it really a invalid date?", tp.is_time_valid(local_min), "if true FUCK"
240 #print self.get_name(), "Apres content:", tp.get_name(), time.asctime(time.localtime(local_min))
242 # print self.get_name(), "Tp ca lui va", tp.get_name()
244 if local_min
== None:
248 #No loop more than one year
249 if t
> original_t
+ 3600*24*366 + 1:
254 #Ok, we update the cache...
255 self
.cache
[original_t
] = local_min
259 def get_next_invalid_time_from_t(self
, t
):
260 #print '\n\n', self.get_name(), 'search for next invalid from', time.asctime(time.localtime(t))
265 if not self
.is_time_valid(t
):
270 #Loop for all minutes...
272 #print "Invalid loop with", time.asctime(time.localtime(local_min))
274 # #Ok, not in cache...
275 # #print self.get_name(), "Begin loop with", time.asctime(time.localtime(local_min))
276 # next_exclude = None
277 # for dr in self.exclude:
278 # m = dr.get_next_valid_time_from_t(local_min)
280 # #print time.asctime(time.localtime(m))
281 # if next_exclude == None or m <= next_exclude:
284 # #Maybe the min of exclude is not valid, it is the min we can find.
285 # if next_exclude != None and not self.is_time_valid(next_exclude):
286 # #print self.get_name(), "find a possible early exit for invalid ! with", time.asctime(time.localtime(next_exclude))
291 #But maybe we can find a better solution with next invalid of standart dateranges
292 #print self.get_name(), "After valid of exclude, local_min =", time.asctime(time.localtime(local_min))
293 for dr
in self
.dateranges
:
294 #print self.get_name(), "Search a next invalid from DR", time.asctime(time.localtime(local_min))
296 m
= dr
.get_next_invalid_time_from_t(local_min
)
298 #print self.get_name(), "Dr give me next invalid", time.asctime(time.localtime(m))
300 #But maybe it's invalid for this dr, but valid for other ones.
301 if not self
.is_time_valid(m
):
302 #print "Final : Got a next invalid at", time.asctime(time.localtime(m))
304 #print "Add a m", time.asctime(time.localtime(m))
307 # print "FUCK bad result\n\n\n"
310 local_min
= min(dr_mins
)
311 #print "After dr : found invalid local min:", time.asctime(time.localtime(local_min)), "is valid", self.is_time_valid(local_min)
313 #print self.get_name(), 'Invalid: local min', time.asctime(time.localtime(local_min))
314 #We do not loop unless the local_min is not valid
317 #if we've got a real value, we check it with the exclude
318 if local_min
!= None:
319 #Now check if local_min is not valid
320 for tp
in self
.exclude
:
321 #print self.get_name(),"we check for invalid", time.asctime(time.localtime(local_min)), 'with tp', tp.name
322 if tp
.is_time_valid(local_min
):
325 local_min
= tp
.get_next_invalid_time_from_t(local_min
+60)
326 #No loop more than one year
327 if local_min
> original_t
+ 60*24*366 + 1:
331 if not still_loop
:#We find a possible value
332 #We take the result the minimal possible
333 if res
== None or local_min
< res
:
336 #print "Finished Return the next invalid", time.asctime(time.localtime(local_min))
341 return hasattr(self
, prop
)
344 #We are correct only if our daterange are
345 #and if we have no unmatch entries
346 def is_correct(self
):
348 for dr
in self
.dateranges
:
351 #Even one invalid is non correct
352 for e
in self
.invalid_entries
:
354 print "Error : The timeperiod %s got an invalid entry '%s'" % (self
.get_name(), e
)
360 s
+= str(self
.__dict
__)+'\n'
361 for elt
in self
.dateranges
:
363 (start
,end
) = elt
.get_start_and_end_time()
364 start
= time
.asctime(time
.localtime(start
))
365 end
= time
.asctime(time
.localtime(end
))
366 s
+= "\nStart and end:"+str((start
, end
))
368 for elt
in self
.exclude
:
374 def resolve_daterange(self
, dateranges
, entry
):
375 #print "Trying to resolve ", entry
377 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
379 #print "Googd catch 1"
380 (syear
, smon
, smday
, eyear
, emon
, emday
, skip_interval
, other
) = res
.groups()
381 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, skip_interval
, other
))
384 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
386 #print "Good catch 2"
387 (syear
, smon
, smday
, skip_interval
, other
) = res
.groups()
391 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, skip_interval
, other
))
394 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry
)
396 #print "Googd catch 3"
397 (syear
, smon
, smday
, eyear
, emon
, emday
, other
) = res
.groups()
398 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, 0, other
))
401 res
= re
.search('(\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry
)
403 #print "Googd catch 4"
404 (syear
, smon
, smday
, other
) = res
.groups()
408 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, 0, other
))
411 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
413 #print "Googd catch 5"
414 (swday
, swday_offset
, smon
, ewday
, ewday_offset
, emon
, skip_interval
, other
) = res
.groups()
415 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
, 0, emon
, 0, ewday
, ewday_offset
, skip_interval
, other
))
418 res
= re
.search('([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
420 #print "Googd catch 6"
421 (t0
, smday
, t1
, emday
, skip_interval
, other
) = res
.groups()
422 if t0
in Daterange
.weekdays
and t1
in Daterange
.weekdays
:
427 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, skip_interval
, other
))
429 elif t0
in Daterange
.months
and t1
in Daterange
.months
:
432 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0,skip_interval
,other
))
434 elif t0
== 'day' and t1
== 'day':
435 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0,skip_interval
, other
))
438 res
= re
.search('([a-z]*) ([\d-]+) - ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
440 #print "Googd catch 7"
441 (t0
, smday
, emday
, skip_interval
, other
) = res
.groups()
442 if t0
in Daterange
.weekdays
:
447 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, skip_interval
, other
))
449 elif t0
in Daterange
.months
:
452 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0,skip_interval
, other
))
455 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
,0,0,skip_interval
,other
))
459 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) [\s\t]*([0-9:, -]+)', entry
)
461 #print "Googd catch 8"
462 (swday
, swday_offset
, smon
, ewday
, ewday_offset
, emon
, other
) = res
.groups()
463 #print "Debug:", (swday, swday_offset, smon, ewday, ewday_offset, emon, other)
464 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
, 0, emon
, 0, ewday
, ewday_offset
, 0, other
))
468 res
= re
.search('([a-z]*) ([\d-]+) - ([\d-]+)[\s\t]*([0-9:, -]+)', entry
)
470 #print "Googd catch 9"
471 (t0
, smday
, emday
, other
) = res
.groups()
472 if t0
in Daterange
.weekdays
:
477 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, 0, other
))
479 elif t0
in Daterange
.months
:
482 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0, other
))
485 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
,0,0,0,other
))
488 res
= re
.search('([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+)[\s\t]*([0-9:, -]+)', entry
)
490 #print "Googd catch 10"
491 (t0
, smday
, t1
, emday
, other
) = res
.groups()
492 if t0
in Daterange
.weekdays
and t1
in Daterange
.weekdays
:
497 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, 0, other
))
499 elif t0
in Daterange
.months
and t1
in Daterange
.months
:
502 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0,other
))
504 elif t0
== 'day' and t1
== 'day':
505 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0, 0, other
))
508 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*)[\s\t]*([0-9:, -]+)', entry
)
510 #print "Good catch 11"
511 (t0
, swday_offset
, t1
,other
) = res
.groups()
512 if t0
in Daterange
.weekdays
and t1
in Daterange
.months
:
517 ewday_offset
= swday_offset
518 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
,0,emon
,0,ewday
,ewday_offset
,0,other
))
521 res
= re
.search('([a-z]*) ([\d-]+)[\s\t]+([0-9:, -]+)', entry
)
523 #print "Good catch 12"
524 (t0
, smday
, other
) = res
.groups()
525 if t0
in Daterange
.weekdays
:
529 ewday_offset
= swday_offset
530 dateranges
.append(WeekDayDaterange(0,0,0,swday
,swday_offset
,0,0,0,ewday
,ewday_offset
,0,other
))
532 if t0
in Daterange
.months
:
536 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0,other
))
540 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0, 0, other
))
543 res
= re
.search('([a-z]*)[\s\t]+([0-9:, -]+)', entry
)
545 #print "Good catch 13"
546 (t0
, other
) = res
.groups()
547 if t0
in Daterange
.weekdays
:
549 dateranges
.append(StandardDaterange(day
, other
))
551 print "No match for", entry
552 self
.invalid_entries
.append(entry
)
555 def apply_inheritance(self
):
559 #create daterange from unresolved param
560 def explode(self
, timeperiods
):
561 for entry
in self
.unresolved
:
562 #print "Revolving entry", entry
563 self
.resolve_daterange(self
.dateranges
, entry
)
567 #Will make tp in exclude with id of the timeperiods
568 def linkify(self
, timeperiods
):
570 if self
.has('exclude') and self
.exclude
!= '':
571 print "I have excluded"
572 print self
.get_name(), self
.exclude
573 excluded_tps
= self
.exclude
.split(',')
574 #print "I will exclude from:", excluded_tps
575 for tp_name
in excluded_tps
:
576 tp
= timeperiods
.find_by_name(tp_name
.strip())
578 new_exclude
.append(tp
)
580 print "Error : the timeperiod", tp_name
, "is unknown!"
581 self
.exclude
= new_exclude
584 def check_exclude_rec(self
):
586 print "Error :", self
.get_name(), "is in a loop in exclude parameter"
589 for tp
in self
.exclude
:
590 tp
.check_exclude_rec()
594 def fill_data_brok_from(self
, data
, brok_type
):
596 #Now config properties
597 for prop
in cls
.properties
:
598 #Is this property intended for brokking?
599 # if 'fill_brok' in cls.properties[prop]:
600 if brok_type
in cls
.properties
[prop
].fill_brok
:
601 if hasattr(self
, prop
):
602 data
[prop
] = getattr(self
, prop
)
603 elif 'default' in cls
.properties
[prop
]:
604 data
[prop
] = cls
.properties
[prop
].default
607 #Get a brok with initial status
608 def get_initial_status_brok(self
):
610 my_type
= cls
.my_type
611 data
= {'id' : self
.id}
613 self
.fill_data_brok_from(data
, 'full_status')
614 b
= Brok('initial_'+my_type
+'_status', data
)
619 class Timeperiods(Items
):
620 name_property
= "timeperiod_name"
621 inner_class
= Timeperiod
625 for id in self
.items
:
631 for id in self
.items
:
636 def apply_inheritance(self
):
637 #The only interesting property to inherit is exclude
638 self
.apply_partial_inheritance('exclude')
640 i
.get_customs_properties_by_inheritance(self
)
642 #And now apply inheritance for unresolved properties
643 #like the dateranges in fact
645 tp
.get_unresolved_properties_by_inheritance(self
.items
)
648 #check for loop in definition
649 def is_correct(self
):
651 #We do not want a same hg to be explode again and again
653 for tp
in self
.items
.values():
656 for tp
in self
.items
.values():
657 for tmp_tp
in self
.items
.values():
658 tmp_tp
.rec_tag
= False
659 r
&= tp
.check_exclude_rec()
662 for tp
in self
.items
.values():
665 #And check all timeperiods for correct (sounday is false)
674 if __name__
== '__main__':
676 test
= ['1999-01-28 00:00-24:00',
677 'monday 3 00:00-24:00 ',
679 'february 10 00:00-24:00',
680 'february -1 00:00-24:00',
681 'friday -2 00:00-24:00',
682 'thursday -1 november 00:00-24:00',
683 '2007-01-01 - 2008-02-01 00:00-24:00',
684 'monday 3 - thursday 4 00:00-24:00',
685 'day 1 - 15 00:00-24:00',
686 'day 20 - -1 00:00-24:00',
687 'july -10 - -1 00:00-24:00',
688 'april 10 - may 15 00:00-24:00',
689 'tuesday 1 april - friday 2 may 00:00-24:00',
690 '2007-01-01 - 2008-02-01 / 3 00:00-24:00',
691 '2008-04-01 / 7 00:00-24:00',
692 'day 1 - 15 / 5 00:00-24:00',
693 'july 10 - 15 / 2 00:00-24:00',
694 'tuesday 1 april - friday 2 may / 6 00:00-24:00',
695 'tuesday 1 october - friday 2 may / 6 00:00-24:00',
696 'monday 3 - thursday 4 / 2 00:00-24:00',
697 'monday 4 - thursday 3 / 2 00:00-24:00',
698 'day -1 - 15 / 5 01:00-24:00,00:30-05:60',
699 'tuesday 00:00-24:00',
700 'sunday 00:00-24:00',
701 'saturday 03:00-24:00,00:32-01:02',
702 'wednesday 09:00-15:46,00:00-21:00',
703 'may 7 - february 2 00:00-10:00',
704 'day -1 - 5 00:00-10:00',
705 'tuesday 1 february - friday 1 may 01:00-24:00,00:30-05:60',
706 'december 2 - may -15 00:00-24:00',
709 print "**********************"
712 t
.timeperiod_name
= ''
713 t
.resolve_daterange(t
.dateranges
, entry
)
715 #t.resolve_daterange(t.exclude, 'monday 00:00-19:00')
716 #t.check_valid_for_today()
718 #print "Is valid NOW?", t.is_time_valid(now)
719 t_next
= t
.get_next_valid_time_from_t(now
+ 5*60)
720 if t_next
is not None:
721 print "Get next valid for now + 5 min ==>", time
.asctime(time
.localtime(t_next
)),"<=="
723 print "===> No future time!!!"
724 #print "End date:", t.get_end_time()
725 #print "Next valid", time.asctime(time.localtime(t.get_next_valid_time()))
728 print "*************************************************************"
730 t3
.timeperiod_name
= 't3'
731 t3
.resolve_daterange(t3
.dateranges
, 'day 1 - 10 10:30-15:00')
735 t2
.timeperiod_name
= 't2'
736 t2
.resolve_daterange(t2
.dateranges
, 'day 1 - 10 12:00-17:00')
741 t
.timeperiod_name
= 't'
742 t
.resolve_daterange(t
.dateranges
, 'day 1 - 10 14:00-15:00')
745 print "Mon T", str(t
)+'\n\n'
746 t_next
= t
.get_next_valid_time_from_t(now
)
747 t_no_next
= t
.get_next_invalid_time_from_t(now
)
748 print "Get next valid for now ==>", time
.asctime(time
.localtime(t_next
)),"<=="
749 print "Get next invalid for now ==>", time
.asctime(time
.localtime(t_no_next
)),"<=="