-
-
Save tekin/1009935 to your computer and use it in GitHub Desktop.
Weekends left til the end of summer
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
# Author: Ian Moss aka oceanician : http://twitter.com/oceanician | |
# First Published: https://gist.github.com/1009253 | |
# modulus is your friend! this works because of the way ruby | |
# modulus behaves when the dvidend is negative. | |
def friday_after(date) | |
date +(5 -date.cwday) % 7 | |
end | |
# Returns all the Fridays between today and the date specified. | |
def fridays_until(date) | |
friday = friday_after(Date.today) | |
fridays = [] | |
while friday <= date | |
fridays << friday | |
friday += 7.days | |
end | |
fridays | |
end | |
future_date = Date.civil(y=2011, m=9, d=21) | |
fridays = fridays_until(future_date) | |
puts "Make the most of the next #{fridays.size} weekends until, "+future_date.to_s(:long) | |
fridays.each{ |friday| puts "From: Fri #{friday.to_s} to Sun #{(friday.end_of_week).to_s}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Like this. Will encorporate back into the original later on.