Skip to content

Instantly share code, notes, and snippets.

@douglas
Forked from tlux/weeks_count.rb
Created January 18, 2019 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglas/c22244bccb499b108e705d442afeb4b6 to your computer and use it in GitHub Desktop.
Save douglas/c22244bccb499b108e705d442afeb4b6 to your computer and use it in GitHub Desktop.
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