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
6 # Hartmut Goebel, h.goebel@goebel-consult.de
8 #This file is part of Shinken.
10 #Shinken is free software: you can redistribute it and/or modify
11 #it under the terms of the GNU Affero General Public License as published by
12 #the Free Software Foundation, either version 3 of the License, or
13 #(at your option) any later version.
15 #Shinken is distributed in the hope that it will be useful,
16 #but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #GNU Affero General Public License for more details.
20 #You should have received a copy of the GNU Affero General Public License
21 #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
24 #Calendar date: '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' => len = 8 => CALENDAR_DATE
25 # '(\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' => len = 5 => CALENDAR_DATE
26 # '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' => len = 7 => CALENDAR_DATE
27 # '(\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' => len = 4 => CALENDAR_DATE
29 #Month week day:'([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) / (\d+) ([0-9:, -]+)' => len = 8 => MONTH WEEK DAY
30 # ex: wednesday 1 january - thursday 2 july / 3
32 # '([a-z]*) (\d+) - ([a-z]*) (\d+) / (\d+) ([0-9:, -]+)' => len = 6
33 # ex: february 1 - march 15 / 3 => MONTH DATE
34 # ex: monday 2 - thusday 3 / 2 => WEEK DAY
35 # ex: day 2 - day 6 / 3 => MONTH DAY
37 # '([a-z]*) (\d+) - (\d+) / (\d+) ([0-9:, -]+)' => len = 6
38 # ex: february 1 - 15 / 3 => MONTH DATE
39 # ex: thursday 2 - 4 => WEEK DAY
40 # ex: day 1 - 4 => MONTH DAY
42 # '([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 7
43 # ex: wednesday 1 january - thursday 2 july => MONTH WEEK DAY
45 # '([a-z]*) (\d+) - (\d+) ([0-9:, -]+)' => len = 7
46 # ex: thursday 2 - 4 => WEEK DAY
47 # ex: february 1 - 15 / 3 => MONTH DATE
48 # ex: day 1 - 4 => MONTH DAY
50 # '([a-z]*) (\d+) - ([a-z]*) (\d+) ([0-9:, -]+)' => len = 5
51 # ex: february 1 - march 15 => MONTH DATE
52 # ex: monday 2 - thusday 3 => WEEK DAY
53 # ex: day 2 - day 6 => MONTH DAY
55 # '([a-z]*) (\d+) ([0-9:, -]+)' => len = 3
56 # ex: february 3 => MONTH DATE
57 # ex: thursday 2 => WEEK DAY
58 # ex: day 3 => MONTH DAY
60 # '([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 4
61 # ex: thusday 3 february => MONTH WEEK DAY
63 # '([a-z]*) ([0-9:, -]+)' => len = 6
64 # ex: thusday => normal values
75 from item
import Item
, Items
76 from shinken
.util
import *
79 from shinken
.daterange
import Daterange
,CalendarDaterange
,StandardDaterange
,MonthWeekDayDaterange
80 from shinken
.daterange
import MonthDateDaterange
,WeekDayDaterange
,MonthDayDaterange
81 from shinken
.brok
import Brok
82 from shinken
.property import IntegerProp
, StringProp
, ListProp
85 class Timeperiod(Item
):
87 my_type
= 'timeperiod'
90 'timeperiod_name': StringProp (fill_brok
=['full_status']),
91 'alias': StringProp (default
='',fill_brok
=['full_status']),
92 'use': StringProp (default
=''),
93 'exclude': StringProp (default
=''),
94 'register': IntegerProp(default
='1'),
95 #All errors and warning raised during the configuration parsing
96 #and taht will raised real warning/errors during the is_correct
97 'configuration_warnings': ListProp(default
=[]),
98 'configuration_errors': ListProp(default
=[]),
99 # These are needed if a broker module calls methods on timeperiod objects
100 'dateranges': ListProp (fill_brok
=['full_status'], default
=[]),
101 'exclude': ListProp (fill_brok
=['full_status'], default
=[]),
105 def __init__(self
, params
={}):
106 self
.id = Timeperiod
.id
107 Timeperiod
.id = Timeperiod
.id + 1
113 self
.invalid_entries
= []
115 if key
in ['name', 'alias', 'timeperiod_name', 'exclude', 'use', 'register']:
116 setattr(self
, key
, params
[key
])
118 self
.unresolved
.append(key
+' '+params
[key
])
120 self
.cache
= {} #For tunning purpose only
121 self
.configuration_errors
= []
122 self
.configuration_warnings
= []
126 return self
.timeperiod_name
133 #We fillfull properties with template ones if need
134 #for the unresolved values (like sunday ETCETC)
135 def get_unresolved_properties_by_inheritance(self
, items
):
136 #Ok, I do not have prop, Maybe my templates do?
138 for i
in self
.templates
:
139 self
.unresolved
.extend(i
.unresolved
)
143 def is_time_valid(self
, t
):
144 if self
.has('exclude'):
145 for dr
in self
.exclude
:
146 if dr
.is_time_valid(t
):
148 for dr
in self
.dateranges
:
149 if dr
.is_time_valid(t
):
154 #will give the first time > t which is valid
155 def get_min_from_t(self
, t
):
157 for dr
in self
.dateranges
:
158 mins_incl
.append(dr
.get_min_from_t(t
))
159 return min(mins_incl
)
162 #will give the first time > t which is not valid
163 def get_not_in_min_from_t(self
, f
):
167 def find_next_valid_time_from_cache(self
, t
):
174 #clean the get_next_valid_time_from_t cache
175 #The entries are a dict on t. t < now are useless
176 #Because we do not care about past anymore.
177 #If not, it's not important, it's just a cache after all :)
178 def clean_cache(self
):
179 now
= int(time
.time())
188 def get_next_valid_time_from_t(self
, t
):
189 #first find from cache
193 #print self.get_name(), "Check valid time for", time.asctime(time.localtime(t))
195 res_from_cache
= self
.find_next_valid_time_from_cache(t
)
196 if res_from_cache
is not None:
197 return res_from_cache
202 #Loop for all minutes...
204 #print self.get_name(), '\nLoop'
207 for dr
in self
.dateranges
:
208 dr_mins
.append(dr
.get_next_valid_time_from_t(t
))
210 #print "TOTO", self.get_name(), 'Mins:', dr_mins
212 # print "FUCK",time.asctime(time.localtime(o)), "\n"
214 #Min but not the None valus...
216 local_min
= min([d
for d
in dr_mins
if d
is not None])
217 except ValueError: #dr_mins if full of None, not good
220 #if local_min != None:
221 # print "Poposed?", local_min
222 # print "Proposed local min", time.asctime(time.localtime(local_min))
225 #We do not loop unless the local_min is not valid
228 #if we've got a real value, we check it with the exclude
229 if local_min
is not None:
230 #Now check if local_min is not valid
231 for tp
in self
.exclude
:
232 #print self.get_name(), "Check in TP"
233 if tp
.is_time_valid(local_min
):
236 #print self.get_name(), "TP pas content:", tp.get_name(), time.asctime(time.localtime(local_min))
237 local_min
= tp
.get_next_invalid_time_from_t(local_min
+60)
238 #if local_min != None:
239 # print "Exclude TP proposed new local min", time.asctime(time.localtime(local_min))
241 #print "Is it really a invalid date?", tp.is_time_valid(local_min), "if true FUCK"
242 #print self.get_name(), "Apres content:", tp.get_name(), time.asctime(time.localtime(local_min))
244 # print self.get_name(), "Tp ca lui va", tp.get_name()
246 if local_min
is None:
250 #No loop more than one year
251 if t
> original_t
+ 3600*24*366 + 1:
256 #Ok, we update the cache...
257 self
.cache
[original_t
] = local_min
261 def get_next_invalid_time_from_t(self
, t
):
262 #print '\n\n', self.get_name(), 'search for next invalid from', time.asctime(time.localtime(t))
267 if not self
.is_time_valid(t
):
272 #Loop for all minutes...
274 #print "Invalid loop with", time.asctime(time.localtime(local_min))
276 # #Ok, not in cache...
277 # #print self.get_name(), "Begin loop with", time.asctime(time.localtime(local_min))
278 # next_exclude = None
279 # for dr in self.exclude:
280 # m = dr.get_next_valid_time_from_t(local_min)
282 # #print time.asctime(time.localtime(m))
283 # if next_exclude == None or m <= next_exclude:
286 # #Maybe the min of exclude is not valid, it is the min we can find.
287 # if next_exclude != None and not self.is_time_valid(next_exclude):
288 # #print self.get_name(), "find a possible early exit for invalid ! with", time.asctime(time.localtime(next_exclude))
293 #But maybe we can find a better solution with next invalid of standart dateranges
294 #print self.get_name(), "After valid of exclude, local_min =", time.asctime(time.localtime(local_min))
295 for dr
in self
.dateranges
:
296 #print self.get_name(), "Search a next invalid from DR", time.asctime(time.localtime(local_min))
298 m
= dr
.get_next_invalid_time_from_t(local_min
)
300 #print self.get_name(), "Dr give me next invalid", time.asctime(time.localtime(m))
302 #But maybe it's invalid for this dr, but valid for other ones.
303 if not self
.is_time_valid(m
):
304 #print "Final : Got a next invalid at", time.asctime(time.localtime(m))
306 #print "Add a m", time.asctime(time.localtime(m))
309 # print "FUCK bad result\n\n\n"
312 local_min
= min(dr_mins
)
313 #print "After dr : found invalid local min:", time.asctime(time.localtime(local_min)), "is valid", self.is_time_valid(local_min)
315 #print self.get_name(), 'Invalid: local min', time.asctime(time.localtime(local_min))
316 #We do not loop unless the local_min is not valid
319 #if we've got a real value, we check it with the exclude
320 if local_min
is not None:
321 #Now check if local_min is not valid
322 for tp
in self
.exclude
:
323 #print self.get_name(),"we check for invalid", time.asctime(time.localtime(local_min)), 'with tp', tp.name
324 if tp
.is_time_valid(local_min
):
327 local_min
= tp
.get_next_invalid_time_from_t(local_min
+60)
328 #No loop more than one year
329 if local_min
> original_t
+ 60*24*366 + 1:
333 if not still_loop
:#We find a possible value
334 #We take the result the minimal possible
335 if res
is None or local_min
< res
:
338 #print "Finished Return the next invalid", time.asctime(time.localtime(local_min))
343 return hasattr(self
, prop
)
346 #We are correct only if our daterange are
347 #and if we have no unmatch entries
348 def is_correct(self
):
350 for dr
in self
.dateranges
:
353 #Even one invalid is non correct
354 for e
in self
.invalid_entries
:
356 print "Error : The timeperiod %s got an invalid entry '%s'" % (self
.get_name(), e
)
362 s
+= str(self
.__dict
__)+'\n'
363 for elt
in self
.dateranges
:
365 (start
,end
) = elt
.get_start_and_end_time()
366 start
= time
.asctime(time
.localtime(start
))
367 end
= time
.asctime(time
.localtime(end
))
368 s
+= "\nStart and end:"+str((start
, end
))
370 for elt
in self
.exclude
:
376 def resolve_daterange(self
, dateranges
, entry
):
377 #print "Trying to resolve ", entry
379 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
381 #print "Googd catch 1"
382 (syear
, smon
, smday
, eyear
, emon
, emday
, skip_interval
, other
) = res
.groups()
383 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, skip_interval
, other
))
386 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
388 #print "Good catch 2"
389 (syear
, smon
, smday
, skip_interval
, other
) = res
.groups()
393 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, skip_interval
, other
))
396 res
= re
.search('(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry
)
398 #print "Googd catch 3"
399 (syear
, smon
, smday
, eyear
, emon
, emday
, other
) = res
.groups()
400 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, 0, other
))
403 res
= re
.search('(\d{4})-(\d{2})-(\d{2})[\s\t]*([0-9:, -]+)', entry
)
405 #print "Googd catch 4"
406 (syear
, smon
, smday
, other
) = res
.groups()
410 dateranges
.append(CalendarDaterange(syear
, smon
, smday
, 0, 0, eyear
, emon
, emday
, 0, 0, 0, other
))
413 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
415 #print "Googd catch 5"
416 (swday
, swday_offset
, smon
, ewday
, ewday_offset
, emon
, skip_interval
, other
) = res
.groups()
417 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
, 0, emon
, 0, ewday
, ewday_offset
, skip_interval
, other
))
420 res
= re
.search('([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
422 #print "Googd catch 6"
423 (t0
, smday
, t1
, emday
, skip_interval
, other
) = res
.groups()
424 if t0
in Daterange
.weekdays
and t1
in Daterange
.weekdays
:
429 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, skip_interval
, other
))
431 elif t0
in Daterange
.months
and t1
in Daterange
.months
:
434 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0,skip_interval
,other
))
436 elif t0
== 'day' and t1
== 'day':
437 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0,skip_interval
, other
))
440 res
= re
.search('([a-z]*) ([\d-]+) - ([\d-]+) / (\d+)[\s\t]*([0-9:, -]+)', entry
)
442 #print "Googd catch 7"
443 (t0
, smday
, emday
, skip_interval
, other
) = res
.groups()
444 if t0
in Daterange
.weekdays
:
449 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, skip_interval
, other
))
451 elif t0
in Daterange
.months
:
454 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0,skip_interval
, other
))
457 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
,0,0,skip_interval
,other
))
461 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*) - ([a-z]*) ([\d-]+) ([a-z]*) [\s\t]*([0-9:, -]+)', entry
)
463 #print "Googd catch 8"
464 (swday
, swday_offset
, smon
, ewday
, ewday_offset
, emon
, other
) = res
.groups()
465 #print "Debug:", (swday, swday_offset, smon, ewday, ewday_offset, emon, other)
466 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
, 0, emon
, 0, ewday
, ewday_offset
, 0, other
))
470 res
= re
.search('([a-z]*) ([\d-]+) - ([\d-]+)[\s\t]*([0-9:, -]+)', entry
)
472 #print "Googd catch 9"
473 (t0
, smday
, emday
, other
) = res
.groups()
474 if t0
in Daterange
.weekdays
:
479 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, 0, other
))
481 elif t0
in Daterange
.months
:
484 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0, other
))
487 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
,0,0,0,other
))
490 res
= re
.search('([a-z]*) ([\d-]+) - ([a-z]*) ([\d-]+)[\s\t]*([0-9:, -]+)', entry
)
492 #print "Googd catch 10"
493 (t0
, smday
, t1
, emday
, other
) = res
.groups()
494 if t0
in Daterange
.weekdays
and t1
in Daterange
.weekdays
:
499 dateranges
.append(WeekDayDaterange(0, 0, 0, swday
, swday_offset
, 0,0,0, ewday
, ewday_offset
, 0, other
))
501 elif t0
in Daterange
.months
and t1
in Daterange
.months
:
504 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0,other
))
506 elif t0
== 'day' and t1
== 'day':
507 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0, 0, other
))
510 res
= re
.search('([a-z]*) ([\d-]+) ([a-z]*)[\s\t]*([0-9:, -]+)', entry
)
512 #print "Good catch 11"
513 (t0
, swday_offset
, t1
,other
) = res
.groups()
514 if t0
in Daterange
.weekdays
and t1
in Daterange
.months
:
519 ewday_offset
= swday_offset
520 dateranges
.append(MonthWeekDayDaterange(0, smon
, 0, swday
, swday_offset
,0,emon
,0,ewday
,ewday_offset
,0,other
))
523 res
= re
.search('([a-z]*) ([\d-]+)[\s\t]+([0-9:, -]+)', entry
)
525 #print "Good catch 12"
526 (t0
, smday
, other
) = res
.groups()
527 if t0
in Daterange
.weekdays
:
531 ewday_offset
= swday_offset
532 dateranges
.append(WeekDayDaterange(0,0,0,swday
,swday_offset
,0,0,0,ewday
,ewday_offset
,0,other
))
534 if t0
in Daterange
.months
:
538 dateranges
.append(MonthDateDaterange(0, smon
, smday
, 0,0,0,emon
,emday
,0,0, 0,other
))
542 dateranges
.append(MonthDayDaterange(0,0,smday
,0,0,0,0,emday
, 0,0, 0, other
))
545 res
= re
.search('([a-z]*)[\s\t]+([0-9:, -]+)', entry
)
547 #print "Good catch 13"
548 (t0
, other
) = res
.groups()
549 if t0
in Daterange
.weekdays
:
551 dateranges
.append(StandardDaterange(day
, other
))
553 print "No match for", entry
554 self
.invalid_entries
.append(entry
)
557 def apply_inheritance(self
):
561 #create daterange from unresolved param
562 def explode(self
, timeperiods
):
563 for entry
in self
.unresolved
:
564 #print "Revolving entry", entry
565 self
.resolve_daterange(self
.dateranges
, entry
)
569 #Will make tp in exclude with id of the timeperiods
570 def linkify(self
, timeperiods
):
572 if self
.has('exclude') and self
.exclude
!= '':
573 print "I have excluded"
574 print self
.get_name(), self
.exclude
575 excluded_tps
= self
.exclude
.split(',')
576 #print "I will exclude from:", excluded_tps
577 for tp_name
in excluded_tps
:
578 tp
= timeperiods
.find_by_name(tp_name
.strip())
580 new_exclude
.append(tp
)
582 print "Error : the timeperiod", tp_name
, "is unknown!"
583 self
.exclude
= new_exclude
586 def check_exclude_rec(self
):
588 print "Error :", self
.get_name(), "is in a loop in exclude parameter"
591 for tp
in self
.exclude
:
592 tp
.check_exclude_rec()
596 def fill_data_brok_from(self
, data
, brok_type
):
598 #Now config properties
599 for prop
, entry
in cls
.properties
.items():
600 #Is this property intended for brokking?
601 # if 'fill_brok' in entry:
602 if brok_type
in entry
.fill_brok
:
603 if hasattr(self
, prop
):
604 data
[prop
] = getattr(self
, prop
)
605 elif 'default' in entry
:
606 data
[prop
] = entry
.default
609 #Get a brok with initial status
610 def get_initial_status_brok(self
):
612 my_type
= cls
.my_type
613 data
= {'id' : self
.id}
615 self
.fill_data_brok_from(data
, 'full_status')
616 b
= Brok('initial_'+my_type
+'_status', data
)
621 class Timeperiods(Items
):
622 name_property
= "timeperiod_name"
623 inner_class
= Timeperiod
627 for id in self
.items
:
633 for id in self
.items
:
638 def apply_inheritance(self
):
639 #The only interesting property to inherit is exclude
640 self
.apply_partial_inheritance('exclude')
642 i
.get_customs_properties_by_inheritance(self
)
644 #And now apply inheritance for unresolved properties
645 #like the dateranges in fact
647 tp
.get_unresolved_properties_by_inheritance(self
.items
)
650 #check for loop in definition
651 def is_correct(self
):
653 #We do not want a same hg to be explode again and again
655 for tp
in self
.items
.values():
658 for tp
in self
.items
.values():
659 for tmp_tp
in self
.items
.values():
660 tmp_tp
.rec_tag
= False
661 r
&= tp
.check_exclude_rec()
664 for tp
in self
.items
.values():
667 #And check all timeperiods for correct (sounday is false)
676 if __name__
== '__main__':
678 test
= ['1999-01-28 00:00-24:00',
679 'monday 3 00:00-24:00 ',
681 'february 10 00:00-24:00',
682 'february -1 00:00-24:00',
683 'friday -2 00:00-24:00',
684 'thursday -1 november 00:00-24:00',
685 '2007-01-01 - 2008-02-01 00:00-24:00',
686 'monday 3 - thursday 4 00:00-24:00',
687 'day 1 - 15 00:00-24:00',
688 'day 20 - -1 00:00-24:00',
689 'july -10 - -1 00:00-24:00',
690 'april 10 - may 15 00:00-24:00',
691 'tuesday 1 april - friday 2 may 00:00-24:00',
692 '2007-01-01 - 2008-02-01 / 3 00:00-24:00',
693 '2008-04-01 / 7 00:00-24:00',
694 'day 1 - 15 / 5 00:00-24:00',
695 'july 10 - 15 / 2 00:00-24:00',
696 'tuesday 1 april - friday 2 may / 6 00:00-24:00',
697 'tuesday 1 october - friday 2 may / 6 00:00-24:00',
698 'monday 3 - thursday 4 / 2 00:00-24:00',
699 'monday 4 - thursday 3 / 2 00:00-24:00',
700 'day -1 - 15 / 5 01:00-24:00,00:30-05:60',
701 'tuesday 00:00-24:00',
702 'sunday 00:00-24:00',
703 'saturday 03:00-24:00,00:32-01:02',
704 'wednesday 09:00-15:46,00:00-21:00',
705 'may 7 - february 2 00:00-10:00',
706 'day -1 - 5 00:00-10:00',
707 'tuesday 1 february - friday 1 may 01:00-24:00,00:30-05:60',
708 'december 2 - may -15 00:00-24:00',
711 print "**********************"
714 t
.timeperiod_name
= ''
715 t
.resolve_daterange(t
.dateranges
, entry
)
717 #t.resolve_daterange(t.exclude, 'monday 00:00-19:00')
718 #t.check_valid_for_today()
720 #print "Is valid NOW?", t.is_time_valid(now)
721 t_next
= t
.get_next_valid_time_from_t(now
+ 5*60)
722 if t_next
is not None:
723 print "Get next valid for now + 5 min ==>", time
.asctime(time
.localtime(t_next
)),"<=="
725 print "===> No future time!!!"
726 #print "End date:", t.get_end_time()
727 #print "Next valid", time.asctime(time.localtime(t.get_next_valid_time()))
730 print "*************************************************************"
732 t3
.timeperiod_name
= 't3'
733 t3
.resolve_daterange(t3
.dateranges
, 'day 1 - 10 10:30-15:00')
737 t2
.timeperiod_name
= 't2'
738 t2
.resolve_daterange(t2
.dateranges
, 'day 1 - 10 12:00-17:00')
743 t
.timeperiod_name
= 't'
744 t
.resolve_daterange(t
.dateranges
, 'day 1 - 10 14:00-15:00')
747 print "Mon T", str(t
)+'\n\n'
748 t_next
= t
.get_next_valid_time_from_t(now
)
749 t_no_next
= t
.get_next_invalid_time_from_t(now
)
750 print "Get next valid for now ==>", time
.asctime(time
.localtime(t_next
)),"<=="
751 print "Get next invalid for now ==>", time
.asctime(time
.localtime(t_no_next
)),"<=="