Skip to content

Introduce this_week?, this_month?, and this_year? to Date/Time#55770

Merged
dhh merged 2 commits intorails:mainfrom
MatheusRich:time-calculations
Feb 18, 2026
Merged

Introduce this_week?, this_month?, and this_year? to Date/Time#55770
dhh merged 2 commits intorails:mainfrom
MatheusRich:time-calculations

Conversation

@MatheusRich
Copy link
Contributor

Similar to today?, tomorrow?, and yesterday?, these methods are useful to
query time instances against the current period.

unless some_date.in_this_week?
  link_to "See week recap", week_recap_path(some_date)
end

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.


# Returns true if the date/time falls within the current week.
def this_week?
::Date.current.all_week.include?(to_date)
Copy link
Contributor Author

@MatheusRich MatheusRich Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought comparing as date made sense for these units. Unless we plan to add current_hour? too, which then it would be best to convert to_time instead.

@MatheusRich MatheusRich changed the title Introduce in_this_week?, in_this_month?, and in_this_year? meth… Introduce in_this_week?, in_this_month?, and in_this_year? to Date/Time Sep 25, 2025
@p8
Copy link
Member

p8 commented Oct 1, 2025

A comment about a similar PR to add methods like yesterday? probably applies here as well:

New Active Support core extensions that aren't used internally by Rails are often rejected in favour of being proposed to Ruby directly, but since these complement existing Active Support methods it seems reasonable to consider adding them here. That decision will have to be made by a committer though.

#37625 (comment)

@MatheusRich
Copy link
Contributor Author

@jeremy @dhh sorry to ping y'all directly, I'd love a thumbs up/down on this. We have simimilar query methods, and I'm assuming you have experience with similar methods because of HEY.

@dhh
Copy link
Member

dhh commented Feb 18, 2026

I prefer skipping the aliases. We already use #in_ for conversions, like #in_minutes. But #this_week? matches #today? So I'm good with this without the #in_ aliases 👍

…te/Time

Similar to `today?`, `tomorrow?`, and `yesterday?`, these methods are useful to
query time instances against the current period.

```ruby
unless date.this_week?
  link_to "See week recap", week_recap_path(date)
end
```
@MatheusRich
Copy link
Contributor Author

@dhh Done. Thank you!

@dhh dhh merged commit 12e24ea into rails:main Feb 18, 2026
2 of 4 checks passed
@MatheusRich MatheusRich changed the title Introduce in_this_week?, in_this_month?, and in_this_year? to Date/Time Introduce this_week?, this_month?, and this_year? to Date/Time Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants