Class: Runt::REDay

Inherits:
TExpr
  • Object
show all
Defined in:
lib/runt/temporalexpression.rb

Overview

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.

See also: Date

Constant Summary collapse

CURRENT =
28
NEXT =
29
ANY_DATE =
PDate.day(2002,8,CURRENT)

Instance Method Summary collapse

Methods inherited from TExpr

#&, #-, #and, #minus, #or, #|

Constructor Details

#initialize(start_hour, start_minute, end_hour, end_minute) ⇒ REDay

Returns a new instance of REDay.



394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/runt/temporalexpression.rb', line 394

def initialize(start_hour, start_minute, end_hour, end_minute)

  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
end

Instance Method Details

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (TypeError)


408
409
410
411
412
413
414
415
416
417
418
# File 'lib/runt/temporalexpression.rb', line 408

def include?(date)
  raise TypeError, 'expected date' unless date.kind_of?(Date)

  if(@spans_midnight&&date.hour<12) then
    #Assume next day
    return @range.include?(get_next(date.hour,date.min))
  end

  #Same day
  return @range.include?(get_current(date.hour,date.min))
end


424
425
426
427
# File 'lib/runt/temporalexpression.rb', line 424

def print(date)
  puts "DIMonth: #{date}"
  puts "include? == #{include?(date)}"
end

#to_sObject



420
421
422
# File 'lib/runt/temporalexpression.rb', line 420

def to_s
  "REDay"
end