Skip to content

Instantly share code, notes, and snippets.

@tlux
Last active January 23, 2023 17:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tlux/8401053 to your computer and use it in GitHub Desktop.
Save tlux/8401053 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment