What is this
Shouldn’t it be better to use all_month while reviewing with seniors? I was interested, so I looked up and looked up. It was defined in DateAndTime::Calculations of ActiveSupport, so read the surrounding methods
I looked at the internal implementation of all_month. It is an internal implementation of rails/rails, but you can understand it from the readable code.
def all_month beginning_of_month..end_of_month end
Looking in the same file, there were all_xxx methods other than all_month. There are many methods that can be used because the target range changes.
- all_quarter: Get date and time information every 3 months
- all_week: You can decide the start date of the week
Notice 1. future?, past?
There is a method that determines whether it is the future or the past! You can use what is rails/rails without redefining it! !! Notice.
Date.yesterday.past? => true Date.yesterday.future? => false Date.tomorrow.future? => true Date.tomorrow.past? => false
Notice 2. next_xxx and prev_xxx exist as well as all_xxx
next_xxx and prev_xxx are defined. prev_xxx is aliased to last_xxx.
Date.current => Sun, 11 Jul 2020 Date.current.next_week => Mon, 13 Jul 2020 Date.current.prev_week => Mon, 29 Jun 2020 Date.current.last_week => Mon, 29 Jun 2020