Skip to content

Instantly share code, notes, and snippets.

@alterisian
Created June 5, 2011 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alterisian/1009253 to your computer and use it in GitHub Desktop.
Save alterisian/1009253 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
#I'm running as part of a rails project with:
# ruby script/runner lib\weekends.rb
# Returns parameter from_date if it is a Friday.
def next_friday( from_date )
while from_date.cwday!=5
from_date = from_date + 1.day
end
from_date
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
# Notionally decided 21st September is the end of Summer!
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
Author

Wow. Thanks for the feedback. Spent about 15 minutes writing it, and I agree about the tests for sure.
I suppose a detailed comment of what I was trying to achieve would have been useful too.
Initially for creating a list of weekends I can poll mates other availability for. Then, I thought perhaps it could be used to generate doddle.ch questionnaires, then I was thinking maybe I could just create my own app on the side. Either way I thought putting the code 'out there' may actually be of use for others.
Anyways, Thanks loads for the feedback. Wanting to keep my Ruby active, so this will help a lot. I will try to evaluate it properly, and refine it. Cheers :)

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