Skip to content

Instantly share code, notes, and snippets.

@KattyaCuevas
Created October 24, 2019 16:07
Show Gist options
  • Save KattyaCuevas/0d6c8be730f8d506fc891f4270137bb1 to your computer and use it in GitHub Desktop.
Save KattyaCuevas/0d6c8be730f8d506fc891f4270137bb1 to your computer and use it in GitHub Desktop.
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