@@ -51,6 +51,14 @@ def other_interval_validations
51
51
Array ( @validations [ base_interval_validation . type ] )
52
52
end
53
53
54
+ def other_fixed_value_validations
55
+ @validations . values . flatten . select { |v |
56
+ interval_type = ( v . type == :wday ? :day : v . type )
57
+ v . class < Validations ::FixedValue &&
58
+ interval_type == base_interval_validation . type
59
+ }
60
+ end
61
+
54
62
# Compute the next time after (or including) the specified time in respect
55
63
# to the given start time
56
64
def next_time ( time , start_time , closing_time )
@@ -185,6 +193,29 @@ def validation_names
185
193
VALIDATION_ORDER & @validations . keys
186
194
end
187
195
196
+ def verify_alignment ( value , freq , rule_part , options = { } )
197
+ @validations [ :interval ] or return
198
+ interval_validation = @validations [ :interval ] . first
199
+ interval_validation . type == freq or return
200
+ fixed_validations = other_fixed_value_validations
201
+ ( last_validation = fixed_validations . min_by ( &:value ) ) or return
202
+
203
+ alignment = ( value - last_validation . value ) % interval_validation . interval
204
+ return if alignment . zero?
205
+
206
+ validation_values = fixed_validations . map ( &:value ) . join ( ', ' )
207
+ if rule_part == :interval
208
+ message = "interval(#{ value } ) " \
209
+ "must be a multiple of " \
210
+ "intervals in #{ last_validation . key } (#{ validation_values } )"
211
+ else
212
+ message = "intervals in #{ last_validation . key } (#{ validation_values } , #{ value } ) " \
213
+ "must be multiples of " \
214
+ "interval(#{ interval_validation . interval } )"
215
+ end
216
+ yield ArgumentError . new ( message )
217
+ end
218
+
188
219
end
189
220
190
221
end
0 commit comments