Last active
December 16, 2015 18:09
-
-
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.
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
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