Class: Runt::REDay
- Inherits:
-
Object
- Object
- Runt::REDay
- 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.
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.
Constant Summary collapse
Instance Attribute Summary collapse
-
#range ⇒ Object
readonly
Returns the value of attribute range.
-
#spans_midnight ⇒ Object
readonly
Returns the value of attribute spans_midnight.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #include?(date) ⇒ Boolean
-
#initialize(start_hour, start_minute, end_hour, end_minute, less_precise_match = true) ⇒ REDay
constructor
A new instance of REDay.
- #to_s ⇒ Object
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.
623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
# 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 |
Instance Attribute Details
#range ⇒ Object (readonly)
Returns the value of attribute range.
621 622 623 |
# File 'lib/runt/temporalexpression.rb', line 621 def range @range end |
#spans_midnight ⇒ Object (readonly)
Returns the value of attribute spans_midnight.
621 622 623 |
# File 'lib/runt/temporalexpression.rb', line 621 def spans_midnight @spans_midnight end |
Instance Method Details
#==(o) ⇒ Object
638 639 640 |
# 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) ⇒ Boolean
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# 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 ⇒ Object
659 660 661 |
# File 'lib/runt/temporalexpression.rb', line 659 def to_s "from #{Runt.format_time(@range.begin)} to #{Runt.format_time(@range.end)} daily" end |