Skip to content

Instantly share code, notes, and snippets.

@agilous
Created December 31, 2011 20:18
Show Gist options
  • Save agilous/1545224 to your computer and use it in GitHub Desktop.
Save agilous/1545224 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'date'
def months_between(start, stop)
diff = (stop - start)
(diff/30).floor.to_i + (diff % 30 > 15 ? 1 : 0)
end
(0..12).each do |i|
(0..100).each do |j|
start = Date.new(2011,12,1) >> i
stop = (start >> 2) + 1
start = start + j
puts "There are #{months_between(start,stop)} months between dates #{stop - start} days apart."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment