-
-
Save douglas/c22244bccb499b108e705d442afeb4b6 to your computer and use it in GitHub Desktop.
Rails: Calculate the number of Calendar Weeks in a Year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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