Using quarter method by rails
source link: https://blog.saeloun.com/2023/06/16/add-quarter-to-date-time/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using quarter method by rails
Jun 16, 2023•
Mayank Agnihotri
I'm a React and Rails enthusiast with two years of experience creating innovative software solutions that improve business productivity. I work well in teams and am always up for challenging projects. Born and raised in Navi Mumbai, I enjoy gaming and travelling in my free time.
Rails have quite a few methods for use with the date and time just as strftime
, beginning_of_day
, mday
, etc.
Similarly, rails also provide some methods like beginning_of_quarter
and end_of_quarter
for getting dates of when the quarter for the calendar year and month is.
Rails do not provide methods for getting the monthly number for the quarter. For that, we would use something like -
Before
def quarter(date)
date.strftime("%m")
end
After
In the upcoming version of Rails 7, it’ll provide a method for getting quarter of the date it is used upon -
date = Date.new(2023, 6, 15)
d.quarter
Look at PR for more information.
Share this post!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK