Class: Checkoff::Timing

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

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.

Parameters:

  • today_getter (Class<Date>) (defaults to: Date)
  • now_getter (Class<Time>) (defaults to: Time)


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

.runvoid

This method returns an undefined value.



217
218
219
220
221
# File 'lib/checkoff/timing.rb', line 217

def run
  time = Checkoff::Timing.new
  # time = time.time_or_raise(workspace_name, time_name)
  puts "Results: #{time}"
end

Instance Method Details

#in_period?(date_or_time, period) ⇒ Boolean

Parameters:

  • date_or_time (Date, Time, nil)
  • period (Symbol, Array<(Symbol,Integer)>)

    Valid values: :this_week, :now_or_before, :indefinite, [:less_than_n_days_ago, Integer]

Returns:

  • (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