Class: OnCalendar::Condition::Hour

Inherits:
Base
  • Object
show all
Defined in:
lib/on_calendar/condition/hour.rb

Constant Summary collapse

RANGE =
(0..23)

Instance Attribute Summary

Attributes inherited from Base

#base, #step, #wildcard

Instance Method Summary collapse

Methods inherited from Base

#distance_to_next, #initialize, #match?, range_bounds, #valid?

Constructor Details

This class inherits a constructor from OnCalendar::Condition::Base

Instance Method Details

#range(clamp: nil) ⇒ Object

NOTE: by default we validate number in default range but this needs to be context aware because not all days have all hours (ie: DST changes)



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/on_calendar/condition/hour.rb', line 10

def range(clamp: nil)
  # If we are dealing with DST
  if clamp.present? and dst_day?(clamp: clamp)
    hours = []
    cursor = clamp.beginning_of_day
    day = clamp.day
    zone = clamp.zone
    # Record each hour of the day until we change day || zone
    loop do
      hours << cursor.hour
      cursor = cursor + 1.hour
      break if cursor.day != day or clamp.zone != zone
    end
    hours
  else
    RANGE
  end
end