Skip to content

Instantly share code, notes, and snippets.

@tekin
Forked from alterisian/weekends.rb
Created June 6, 2011 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tekin/1009935 to your computer and use it in GitHub Desktop.
Save tekin/1009935 to your computer and use it in GitHub Desktop.
Weekends left til the end of summer
# 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}" }
@alterisian
Copy link

Like this. Will encorporate back into the original later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment