lib/checkoff/timing.rb in checkoff-0.110.0 vs lib/checkoff/timing.rb in checkoff-0.111.0
- old
+ new
@@ -68,10 +68,19 @@
date >= n_days_from_today
end
# @param date_or_time [Date,Time,nil]
# @param num_days [Integer]
+ def greater_than_or_equal_to_n_days_from_now?(date_or_time, num_days)
+ return false if date_or_time.nil?
+
+ n_days_from_now = (@now_getter.now + (num_days * 24 * 60 * 60))
+ date_or_time >= n_days_from_now
+ 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
@@ -80,10 +89,19 @@
# @sg-ignore
date < n_days_ago
end
# @param date_or_time [Date,Time,nil]
+ # @param num_days [Integer]
+ def less_than_n_days_from_now?(date_or_time, num_days)
+ return false if date_or_time.nil?
+
+ n_days_from_now = (@now_getter.now + (num_days * 24 * 60 * 60))
+ date_or_time < n_days_from_now
+ end
+
+ # @param date_or_time [Date,Time,nil]
def this_week?(date_or_time)
return true if date_or_time.nil?
today = @today_getter.today
@@ -110,13 +128,20 @@
# @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
+ return less_than_n_days_from_now?(date_or_time, *args) if period_name == :less_than_n_days_from_now
+
+ if period_name == :greater_than_or_equal_to_n_days_from_now
+ return greater_than_or_equal_to_n_days_from_now?(date_or_time,
+ *args)
+ end
+
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)
+ 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: