Last active
January 23, 2023 17:19
-
-
Save tlux/8401053 to your computer and use it in GitHub Desktop.
Ruby/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