1
|
|
|
## |
2
|
|
|
## |
3
|
|
|
|
4
|
|
|
# File auto-generated against equivalent DynamicSerialize Java class |
5
|
|
|
# |
6
|
|
|
# 03/20/2013 #1774 randerso Removed setters, added isValid. |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
import logging |
10
|
|
|
|
11
|
|
|
HOUR = 3600; |
|
|
|
|
12
|
|
|
DAY = 24 * HOUR; |
|
|
|
|
13
|
|
|
|
14
|
|
View Code Duplication |
class TimeConstraints(object): |
|
|
|
|
15
|
|
|
|
16
|
|
|
def __init__(self, duration=0, repeatInterval=0, startTime=0): |
17
|
|
|
duration = int(duration) |
18
|
|
|
repeatInterval = int(repeatInterval) |
19
|
|
|
startTime = int(startTime) |
20
|
|
|
|
21
|
|
|
self.valid = False; |
|
|
|
|
22
|
|
|
if duration == 0 and repeatInterval == 0 and startTime == 0: |
23
|
|
|
self.valid = True; |
|
|
|
|
24
|
|
|
else: |
25
|
|
|
if self.isInvalidInterval(repeatInterval, duration, startTime): |
26
|
|
|
logging.warning("Bad init values for TimeConstraints: ", self); |
|
|
|
|
27
|
|
|
self.valid = False; |
|
|
|
|
28
|
|
|
duration = 0; |
|
|
|
|
29
|
|
|
repeatInterval = 0; |
|
|
|
|
30
|
|
|
startTime = 0; |
|
|
|
|
31
|
|
|
else: |
32
|
|
|
self.valid = True; |
|
|
|
|
33
|
|
|
|
34
|
|
|
self.duration = duration |
35
|
|
|
self.repeatInterval = repeatInterval |
36
|
|
|
self.startTime = startTime |
37
|
|
|
|
38
|
|
|
def __str__(self): |
39
|
|
|
return self.__repr__() |
40
|
|
|
|
41
|
|
|
def __repr__(self): |
42
|
|
|
if not self.isValid(): |
|
|
|
|
43
|
|
|
return "<Invalid>" |
44
|
|
|
elif not self.anyConstraints(): |
45
|
|
|
return "<NoConstraints>" |
46
|
|
|
else: |
47
|
|
|
return "[s=" + str(self.startTime / HOUR) + "h, i=" + \ |
48
|
|
|
str(self.repeatInterval / HOUR) + "h, d=" + \ |
49
|
|
|
str(self.duration / HOUR) + "h]" |
50
|
|
|
|
51
|
|
|
def __eq__(self, other): |
52
|
|
|
if not isinstance(other, TimeConstraints): |
53
|
|
|
return False |
54
|
|
|
if self.isValid() != other.isValid(): |
55
|
|
|
return False |
56
|
|
|
if self.duration != other.duration: |
57
|
|
|
return False |
58
|
|
|
if self.repeatInterval != other.repeatInterval: |
59
|
|
|
return False |
60
|
|
|
return (self.startTime == other.startTime) |
|
|
|
|
61
|
|
|
|
62
|
|
|
def __ne__(self, other): |
63
|
|
|
return (not self.__eq__(other)) |
|
|
|
|
64
|
|
|
|
65
|
|
|
def anyConstraints(self): |
66
|
|
|
return (self.duration != 0) |
|
|
|
|
67
|
|
|
|
68
|
|
|
def isValid(self): |
69
|
|
|
return self.valid |
70
|
|
|
|
71
|
|
|
def getDuration(self): |
72
|
|
|
return self.duration |
73
|
|
|
|
74
|
|
|
def getRepeatInterval(self): |
75
|
|
|
return self.repeatInterval |
76
|
|
|
|
77
|
|
|
def getStartTime(self): |
78
|
|
|
return self.startTime |
79
|
|
|
|
80
|
|
|
def isInvalidInterval(self, interval, duration, startTime): |
|
|
|
|
81
|
|
|
if interval <= 0 or interval > DAY or interval < duration: |
82
|
|
|
return False |
83
|
|
|
if startTime < 0 or startTime > DAY: |
84
|
|
|
return False |
85
|
|
|
if duration < 0 or duration > DAY: |
86
|
|
|
return False |
87
|
|
|
if DAY % interval != 0: |
88
|
|
|
return False |
89
|
|
|
return True |
90
|
|
|
|