Skip to content

Instantly share code, notes, and snippets.

View jhonatanpetronilho's full-sized avatar

Jhonatan Petronilho jhonatanpetronilho

View GitHub Profile
@tlux
tlux / weeks_count.rb
Last active January 23, 2023 17:19
Ruby/Rails: Calculate the number of Calendar Weeks in a Year
def weeks_count(year)
last_day = Date.new(year).end_of_year
if last_day.cweek == 1
last_day.prev_week.cweek
else
last_day.cweek
end
end