Skip to content

Instantly share code, notes, and snippets.

@tekin
Forked from alterisian/weekends.rb
Created June 6, 2011 08:30
Show Gist options
  • 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
def next_friday(d)
while d.cwday!=5
d = d+1.day
end
d
end
def weekends_til( end_date )
weekends = []
friday_count = next_friday( Date.today )
while ( friday_count <= end_date )
weekends << friday_count
friday_count = friday_count + 7.days
end
weekends
end
#calculate all the weekends from now, until the middle of September.
#I'm running as part of a rails project with:
# ruby script/runner lib\weekends.rb
#future = Date.today + 5.months + 3.weeks
future = Date.civil(y=2011, m=9, d=21)
weekends=weekends_til(future)
puts "Make the most of the next #{weekends.size} weekends until, "+future.to_s(:long)
weekends.each{|w| puts "From: Fri "+w.to_s+" to Sun " +(w+3.days).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