Module: IceCube::Validations::HourOfDay
- Included in:
- DailyRule, HourlyRule, MinutelyRule, MonthlyRule, SecondlyRule, WeeklyRule, YearlyRule
- Defined in:
- lib/ice_cube/validations/hour_of_day.rb
Defined Under Namespace
Classes: Validation
Instance Method Summary collapse
-
#hour_of_day(*hours) ⇒ Object
Add hour of day validations.
- #realign(opening_time, start_time) ⇒ Object
Instance Method Details
#hour_of_day(*hours) ⇒ Object
Add hour of day validations
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/ice_cube/validations/hour_of_day.rb', line 6 def hour_of_day(*hours) hours.flatten.each do |hour| unless hour.is_a?(Integer) raise ArgumentError, "expecting Integer value for hour, got #{hour.inspect}" end verify_alignment(hour, :hour, :hour_of_day) { |error| raise error } validations_for(:hour_of_day) << Validation.new(hour) end clobber_base_validations(:hour) self end |
#realign(opening_time, start_time) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ice_cube/validations/hour_of_day.rb', line 20 def realign(opening_time, start_time) return super unless validations[:hour_of_day] freq = base_interval_validation.interval first_hour = Array(validations[:hour_of_day]).min_by(&:value) time = TimeUtil::TimeWrapper.new(start_time, false) if freq > 1 && base_interval_validation.type == :hour offset = first_hour.validate(opening_time, start_time) time.add(:hour, offset - freq) else time.hour = first_hour.value end super opening_time, time.to_time end |