Skip to content

Instantly share code, notes, and snippets.

@johana-star
Last active December 16, 2015 18:09
Show Gist options
  • Save johana-star/5475560 to your computer and use it in GitHub Desktop.
Save johana-star/5475560 to your computer and use it in GitHub Desktop.
This took me way longer than I would have preferred to write.
require 'active_support/time'
def Time.month; self.strftime("%_m").to_i; end
def Date.month; self.strftime("%_m").to_i; end
def fridays_in_month(date_or_time)
month = date_or_time.month
current_week = Date.new(date_or_time.year, date_or_time.month).
prev_week(day = :friday).
next_week(day = :friday)
fridays = []
loop do
fridays << current_week if current_week.month == month
current_week = current_week.next_week(day = :friday)
break unless current_week < date_or_time.end_of_month.to_date
end
fridays
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment