Class: Runt::REDay

Inherits:
Object
  • Object
show all
Includes:
TExpr
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.

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.

See also: Date

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from TExpr

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

Constructor Details

#initialize(start_hour, start_minute, end_hour, end_minute, less_precise_match = true) ⇒ REDay

Returns a new instance of REDay.



569
570
571
572
573
574
575
576
577
578
579
580
581
582
# File 'lib/runt/temporalexpression.rb', line 569

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

Instance Method Details

#include?(date) ⇒ Boolean

Returns:

  • (Boolean)


584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/runt/temporalexpression.rb', line 584

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 && date.date_precision <= DPrecision::DAY
  if(@spans_midnight&&date.hour<12) then
    #Assume next day
    n = get_next(date.hour,date.min)
    return false unless @range.begin <= n
    return false unless @range.end >= n
    true
  end

  #Same day
  c = get_current(date.hour,date.min)
  return false unless @range.begin <= c
  return false unless @range.end >= c
  true
end

#to_sObject



604
605
606
# File 'lib/runt/temporalexpression.rb', line 604

def to_s
  "from #{Runt.format_time(@range.begin)} to #{Runt.format_time(@range.end)} daily"
end