Class: Checkoff::Timing
- Inherits:
-
Object
- Object
- Checkoff::Timing
- Includes:
- Logging
- Defined in:
- lib/checkoff/timing.rb
Overview
Common vocabulary for managing time and time periods
Constant Summary collapse
- MINUTE =
60
- HOUR =
MINUTE * 60
- DAY =
24 * HOUR
- REALLY_LONG_CACHE_TIME =
HOUR * 1
- LONG_CACHE_TIME =
MINUTE * 15
- SHORT_CACHE_TIME =
MINUTE
Class Method Summary collapse
Instance Method Summary collapse
- #in_period?(date_or_time, period) ⇒ Boolean
-
#initialize(today_getter: Date, now_getter: Time) ⇒ Timing
constructor
A new instance of Timing.
Methods included from Logging
#debug, #error, #finer, #info, #logger, #warn
Constructor Details
#initialize(today_getter: Date, now_getter: Time) ⇒ Timing
Returns a new instance of Timing.
30 31 32 33 34 |
# File 'lib/checkoff/timing.rb', line 30 def initialize(today_getter: Date, now_getter: Time) @today_getter = today_getter @now_getter = now_getter end |
Class Method Details
Instance Method Details
#in_period?(date_or_time, period) ⇒ Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/checkoff/timing.rb', line 40 def in_period?(date_or_time, period) return this_week?(date_or_time) if period == :this_week return day_of_week?(date_or_time, period) if %i[monday tuesday wednesday thursday friday saturday sunday].include?(period) return true if period == :indefinite return now_or_before?(date_or_time) if period == :now_or_before if period.is_a?(Array) # @sg-ignore # @type [Symbol] period_name = period.first args = period[1..] return compound_in_period?(date_or_time, period_name, *args) end raise "Teach me how to handle period #{period.inspect}" end |