Adding this_quarter? to complete the predicate family?

this_week?, this_month?, and this_year? were introduced in #55770, but this_quarter? was not included. Looking at the full method matrix for date/time periods, quarter is fully supported across every other verb:

               week  month  quarter  year
beginning_of_*  ✓     ✓      ✓       ✓
end_of_*        ✓     ✓      ✓       ✓
all_*           ✓     ✓      ✓       ✓
next_*          ✓     ✓      ✓       ✓
prev_*          ✓     ✓      ✓       ✓
this_*?         ✓     ✓      —       ✓

this_quarter? is the only gap in the entire grid. Today this requires Date.current.all_quarter.include?(date), while the week/month/year cases each have a one-call predicate. The implementation would follow the same pattern as its siblings:

def this_quarter?
  ::Date.current.all_quarter.include?(to_date)
end

It’s purely additive and fully backward-compatible. Quarter-based checks come up fairly often in financial reporting and billing contexts. Would this be welcome as a PR?

3 Likes

PR opened: #57963. Happy to adjust if there are any concerns.

The PR has been merged!

Thank you to everyone who gave it a :heart: — it helped confirm the direction. Also opened a follow-up (#57997) to bring the sibling predicates in line with cover? for better performance, as suggested by @fatkodima during review.