Created
October 24, 2019 16:07
-
-
Save KattyaCuevas/0d6c8be730f8d506fc891f4270137bb1 to your computer and use it in GitHub Desktop.
This file contains 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 get_days(date) | |
last_day = date.end_of_month.day | |
first_wday = date.wday | |
total_days = [6, 7].include?(first_wday) ? 0 : 1 | |
(1..(last_day - 1)).reduce(total_days) do |result, _element| | |
wday = ((first_wday + 1) > 7) ? first_wday % 7 + 1 : first_wday + 1 | |
first_wday += 1 | |
result += 1 unless [6, 7].include?(wday) | |
result | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment