Created
June 5, 2011 18:32
-
-
Save alterisian/1009253 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 | |
#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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 :)