class Runt::REDay

TExpr that matches periods of the day with minute precision. If the start hour is greater than the end hour, than end hour is assumed to be on the following day.

NOTE: By default, this class will match any date expression whose precision is less than or equal to DPrecision::DAY. To override this behavior, pass the optional fifth constructor argument the value: false.

When the less_precise_match argument is true, the date-like object passed to :include? will be “promoted” to DPrecision::MINUTE if it has a precision of DPrecision::DAY or less.

Constants

ANY_DATE
CURRENT
NEXT

Attributes

range[R]
spans_midnight[R]

Public Class Methods

new(start_hour, start_minute, end_hour, end_minute, less_precise_match=true) click to toggle source
# File lib/runt/temporalexpression.rb, line 623
def initialize(start_hour, start_minute, end_hour, end_minute, less_precise_match=true)

  start_time = PDate.min(ANY_DATE.year,ANY_DATE.month,
            ANY_DATE.day,start_hour,start_minute)

  if(@spans_midnight = spans_midnight?(start_hour, end_hour)) then
    end_time = get_next(end_hour,end_minute)
  else
    end_time = get_current(end_hour,end_minute)
  end

  @range = start_time..end_time
  @less_precise_match = less_precise_match
end

Public Instance Methods

==(o) click to toggle source
Calls superclass method
# File lib/runt/temporalexpression.rb, line 638
def ==(o)
  o.is_a?(REDay) ? spans_midnight == o.spans_midnight && range == o.range : super(o)
end
include?(date) click to toggle source
# File lib/runt/temporalexpression.rb, line 642
def include?(date)
  #
  # If @less_precise_match == true and the precision of the argument
  #  is day or greater, then the result is always true
  return true if @less_precise_match && less_precise?(date)
      
      date_to_use = ensure_precision(date)
  
      if(@spans_midnight&&date_to_use.hour<12) then
    #Assume next day
    return @range.include?(get_next(date_to_use.hour,date_to_use.min))
  end

  #Same day
  return @range.include?(get_current(date_to_use.hour,date_to_use.min))
end
to_s() click to toggle source
# File lib/runt/temporalexpression.rb, line 659
def to_s
  "from #{Runt.format_time(@range.begin)} to #{Runt.format_time(@range.end)} daily"
end

Private Instance Methods

ensure_precision(date) click to toggle source
# File lib/runt/temporalexpression.rb, line 669
def ensure_precision(date)
      return date unless less_precise?(date)
      DPrecision.to_p(date,DPrecision::MIN)
end
get_current(hour,minute) click to toggle source
# File lib/runt/temporalexpression.rb, line 678
def get_current(hour,minute)
    PDate.min(ANY_DATE.year,ANY_DATE.month,CURRENT,hour,minute)
end
get_next(hour,minute) click to toggle source
# File lib/runt/temporalexpression.rb, line 682
def get_next(hour,minute)
    PDate.min(ANY_DATE.year,ANY_DATE.month,NEXT,hour,minute)
end
less_precise?(date) click to toggle source
# File lib/runt/temporalexpression.rb, line 665
def less_precise?(date)
      date.date_precision <= DPrecision::DAY
end
spans_midnight?(start_hour, end_hour) click to toggle source
# File lib/runt/temporalexpression.rb, line 674
def spans_midnight?(start_hour, end_hour)
  return end_hour < start_hour
end