@@ -29,7 +29,12 @@ class HourlyInterval(object):
2929 def __init__ (self , start_time , end_time , interval_value ):
3030 self .start_time = start_time
3131 self .end_time = end_time
32- self .interval = interval_value
32+
33+ # interval should be a tuple, if it is not, assign as a tuple with single value
34+ if isinstance (interval_value , tuple ):
35+ self .interval = interval_value
36+ else :
37+ self .interval = (interval_value ,)
3338
3439 @property
3540 def _frequency (self ):
@@ -60,25 +65,44 @@ def interval(self):
6065 return self ._interval
6166
6267 @interval .setter
63- def interval (self , interval ):
68+ def interval (self , intervals ):
6469 VALID_INTERVALS = {0.25 , 0.5 , 1 , 2 , 4 , 6 , 8 , 12 }
65- if float (interval ) not in VALID_INTERVALS :
66- error = "Invalid interval {} not in {}" .format (interval , str (VALID_INTERVALS ))
67- raise ValueError (error )
70+ for interval in intervals :
71+ # if an hourly interval is a string, then it is a weekDay interval
72+ if isinstance (interval , str ) and not interval .isnumeric () and not hasattr (IntervalItem .Day , interval ):
73+ error = "Invalid weekDay interval {}" .format (interval )
74+ raise ValueError (error )
75+
76+ # if an hourly interval is a number, it is an hours or minutes interval
77+ if isinstance (interval , (int , float )) and float (interval ) not in VALID_INTERVALS :
78+ error = "Invalid interval {} not in {}" .format (interval , str (VALID_INTERVALS ))
79+ raise ValueError (error )
6880
69- self ._interval = interval
81+ self ._interval = intervals
7082
7183 def _interval_type_pairs (self ):
72- # We use fractional hours for the two minute-based intervals.
73- # Need to convert to minutes from hours here
74- if self .interval in {0.25 , 0.5 }:
75- calculated_interval = int (self .interval * 60 )
76- interval_type = IntervalItem .Occurrence .Minutes
77- else :
78- calculated_interval = self .interval
79- interval_type = IntervalItem .Occurrence .Hours
84+ interval_type_pairs = []
85+ for interval in self .interval :
86+ # We use fractional hours for the two minute-based intervals.
87+ # Need to convert to minutes from hours here
88+ if interval in {0.25 , 0.5 }:
89+ calculated_interval = int (interval * 60 )
90+ interval_type = IntervalItem .Occurrence .Minutes
91+
92+ interval_type_pairs .append ((interval_type , str (calculated_interval )))
93+ else :
94+ # if the interval is a non-numeric string, it will always be a weekDay
95+ if isinstance (interval , str ) and not interval .isnumeric ():
96+ interval_type = IntervalItem .Occurrence .WeekDay
97+
98+ interval_type_pairs .append ((interval_type , str (interval )))
99+ # otherwise the interval is hours
100+ else :
101+ interval_type = IntervalItem .Occurrence .Hours
80102
81- return [(interval_type , str (calculated_interval ))]
103+ interval_type_pairs .append ((interval_type , str (interval )))
104+
105+ return interval_type_pairs
82106
83107
84108class DailyInterval (object ):
@@ -105,8 +129,45 @@ def interval(self):
105129 return self ._interval
106130
107131 @interval .setter
108- def interval (self , interval ):
109- self ._interval = interval
132+ def interval (self , intervals ):
133+ VALID_INTERVALS = {0.25 , 0.5 , 1 , 2 , 4 , 6 , 8 , 12 }
134+
135+ for interval in intervals :
136+ # if an hourly interval is a string, then it is a weekDay interval
137+ if isinstance (interval , str ) and not interval .isnumeric () and not hasattr (IntervalItem .Day , interval ):
138+ error = "Invalid weekDay interval {}" .format (interval )
139+ raise ValueError (error )
140+
141+ # if an hourly interval is a number, it is an hours or minutes interval
142+ if isinstance (interval , (int , float )) and float (interval ) not in VALID_INTERVALS :
143+ error = "Invalid interval {} not in {}" .format (interval , str (VALID_INTERVALS ))
144+ raise ValueError (error )
145+
146+ self ._interval = intervals
147+
148+ def _interval_type_pairs (self ):
149+ interval_type_pairs = []
150+ for interval in self .interval :
151+ # We use fractional hours for the two minute-based intervals.
152+ # Need to convert to minutes from hours here
153+ if interval in {0.25 , 0.5 }:
154+ calculated_interval = int (interval * 60 )
155+ interval_type = IntervalItem .Occurrence .Minutes
156+
157+ interval_type_pairs .append ((interval_type , str (calculated_interval )))
158+ else :
159+ # if the interval is a non-numeric string, it will always be a weekDay
160+ if isinstance (interval , str ) and not interval .isnumeric ():
161+ interval_type = IntervalItem .Occurrence .WeekDay
162+
163+ interval_type_pairs .append ((interval_type , str (interval )))
164+ # otherwise the interval is hours
165+ else :
166+ interval_type = IntervalItem .Occurrence .Hours
167+
168+ interval_type_pairs .append ((interval_type , str (interval )))
169+
170+ return interval_type_pairs
110171
111172
112173class WeeklyInterval (object ):
@@ -146,7 +207,12 @@ def _interval_type_pairs(self):
146207class MonthlyInterval (object ):
147208 def __init__ (self , start_time , interval_value ):
148209 self .start_time = start_time
149- self .interval = str (interval_value )
210+
211+ # interval should be a tuple, if it is not, assign as a tuple with single value
212+ if isinstance (interval_value , tuple ):
213+ self .interval = interval_value
214+ else :
215+ self .interval = (interval_value ,)
150216
151217 @property
152218 def _frequency (self ):
@@ -167,24 +233,24 @@ def interval(self):
167233 return self ._interval
168234
169235 @interval .setter
170- def interval (self , interval_value ):
171- error = "Invalid interval value for a monthly frequency: {}." .format (interval_value )
172-
236+ def interval (self , interval_values ):
173237 # This is weird because the value could be a str or an int
174238 # The only valid str is 'LastDay' so we check that first. If that's not it
175239 # try to convert it to an int, if that fails because it's an incorrect string
176240 # like 'badstring' we catch and re-raise. Otherwise we convert to int and check
177241 # that it's in range 1-31
242+ for interval_value in interval_values :
243+ error = "Invalid interval value for a monthly frequency: {}." .format (interval_value )
178244
179- if interval_value != "LastDay" :
180- try :
181- if not (1 <= int (interval_value ) <= 31 ):
182- raise ValueError (error )
183- except ValueError :
184- if interval_value != "LastDay" :
185- raise ValueError (error )
245+ if interval_value != "LastDay" :
246+ try :
247+ if not (1 <= int (interval_value ) <= 31 ):
248+ raise ValueError (error )
249+ except ValueError :
250+ if interval_value != "LastDay" :
251+ raise ValueError (error )
186252
187- self ._interval = str ( interval_value )
253+ self ._interval = interval_values
188254
189255 def _interval_type_pairs (self ):
190256 return [(IntervalItem .Occurrence .MonthDay , self .interval )]
0 commit comments