lib/checkoff/timing.rb in checkoff-0.107.0 vs lib/checkoff/timing.rb in checkoff-0.108.0
- old
+ new
@@ -29,17 +29,10 @@
@today_getter = today_getter
@now_getter = now_getter
end
# @param date_or_time [Date,Time,nil]
- def now_or_before?(date_or_time)
- return true if date_or_time.nil?
-
- date_or_time.to_time < @now_getter.now
- end
-
- # @param date_or_time [Date,Time,nil]
# @param period [Symbol,Array<(Symbol,Integer)>]
#
# Valid values: :this_week, :now_or_before, :indefinite, [:less_than_n_days_ago, Integer]
def in_period?(date_or_time, period)
return this_week?(date_or_time) if period == :this_week
@@ -52,21 +45,33 @@
# @sg-ignore
# @type [Symbol]
period_name = period.first
args = period[1..]
- # @sg-ignore
- return less_than_n_days_ago?(date_or_time, *args) if period_name == :less_than_n_days_ago
+ return compound_in_period?(date_or_time, period_name, *args)
end
raise "Teach me how to handle period #{period.inspect}"
end
private
# @param date_or_time [Date,Time,nil]
# @param num_days [Integer]
+ def greater_than_or_equal_to_n_days_from_today?(date_or_time, num_days)
+ return false if date_or_time.nil?
+
+ date = date_or_time.to_date
+
+ # @sg-ignore
+ n_days_from_today = @today_getter.today + num_days
+ # @sg-ignore
+ date >= n_days_from_today
+ end
+
+ # @param date_or_time [Date,Time,nil]
+ # @param num_days [Integer]
def less_than_n_days_ago?(date_or_time, num_days)
return false if date_or_time.nil?
date = date_or_time.to_date
@@ -89,9 +94,30 @@
end_of_week = beginning_of_week + 6
date = date_or_time.to_date
date >= beginning_of_week && date <= end_of_week
+ end
+
+ # @param date_or_time [Date,Time,nil]
+ def now_or_before?(date_or_time)
+ return true if date_or_time.nil?
+
+ date_or_time.to_time < @now_getter.now
+ end
+
+ # @param date_or_time [Date,Time,nil]
+ # @param period_name [Symbol]
+ # @param args [Object]
+ def compound_in_period?(date_or_time, period_name, *args)
+ # @sg-ignore
+ return less_than_n_days_ago?(date_or_time, *args) if period_name == :less_than_n_days_ago
+
+ if period_name == :greater_than_or_equal_to_n_days_from_today
+ return greater_than_or_equal_to_n_days_from_today?(date_or_time,
+ *args)
+ end
+ raise "Teach me how to handle period [#{period_name.inspect}, #{args.join(', ')}]"
end
# bundle exec ./time.rb
# :nocov:
class << self