Initially appeared on Andy Croll.
In Lively Help‘s extensions to the core Ruby lessons, a number of the most helpful and plentiful are associated to Time
.
Considered one of Rails’s founding makes use of was to supply useful, reusable strategies for repeatedly carried out duties. In our net functions we‘re usually working with instances and dates.
Enter the strategies from DateAndTime::Calculations. To seek out out extra try out the API documentation or the DateTime
part within the Core Extensions Rails information.
Familiarise your self with…
…the extensions to Date
:
as we speak = Date.as we speak
#=> Mon, 03 Oct 2022
as we speak.end_of_week
#=> Solar, 09 Oct 2022
as we speak.beginning_of_month
#=> Sat, 01 Oct 2022
as we speak.end_of_quarter
#=> Sat, 31 Dec 2022
as we speak.beginning_of_year
#=>…