Skip to content

Instantly share code, notes, and snippets.

@razielgn
Created January 18, 2011 17:04
Show Gist options
  • Save razielgn/784754 to your computer and use it in GitHub Desktop.
Save razielgn/784754 to your computer and use it in GitHub Desktop.
require 'date'
require 'progressbar'
curr = Date.parse("01/01/0001")
totals = (Date.today - curr).to_i
pbar = ProgressBar.new "Counting", totals
Months = []
currMonth = curr.mon
contSun = 0
contMon = 0
contSat = 0
while (curr != Date.today.next_month)
if curr.mon != currMonth
currMonth = curr.mon
contSun = 0
contMon = 0
contSat = 0
end
case curr.wday
when 1 then contMon += 1
when 6 then contSat += 1
when 0 then contSun += 1
else
end
Months << "#{Date::MONTHNAMES[currMonth]} - #{curr.year}" if contMon == 5 and contSat == 5 and contSun == 5
curr = curr.succ
pbar.inc
end
pbar.finish
Months.each {|mon| puts mon}
puts Months.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment