Hi everyone,
The recently introduced this_week? predicate method is a great addition — it makes time-range checks much more readable. However, I noticed that it doesn’t accept a start_day argument, unlike the related methods it depends on internally.
Current behavior
def this_week?
::Date.current.all_week.include?(to_date)
end
this_week? always uses the global Date.beginning_of_week setting. There is no way to specify the start day on a per-call basis.
Inconsistency with existing API
Several related methods already accept a start_dayargument:
-
all_week(start_day = Date.beginning_of_week) -
beginning_of_week(start_day = Date.beginning_of_week) -
end_of_week(start_day = Date.beginning_of_week)
It feels natural and consistent for this_week? to follow the same pattern.
Proposed change
def this_week?(start_day = Date.beginning_of_week)
::Date.current.all_week(start_day).include?(to_date)
end
Use case
For applications that need to handle multiple week-start conventions (e.g., :sunday in the US, :mondayin Europe) within the same codebase, it’s useful to be able to specify start_day at the call site without changing the global configuration:
date.this_week?(:sunday) # Check against Sun-Sat week
date.this_week?(:monday) # Check against Mon-Sun week
date.this_week? # Uses global default (unchanged)
This is a minimal, backward-compatible change — the default value preserves existing behavior.
I’m happy to submit a PR with the implementation and tests if this sounds reasonable.
Thanks for your feedback!