Created
June 21, 2016 18:20
-
-
Save shirts/b3b1c816ba0bfaea80360a3429a5858c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/ruby | |
require 'date' | |
class Date | |
def self.months_between(d1, d2) | |
months = [] | |
start_date = Date.civil(d1.year, d1.month, 1) | |
end_date = Date.civil(d2.year, d2.month, 1) | |
raise ArgumentError unless d1 <= d2 | |
while (start_date < end_date) | |
months << start_date | |
start_date = start_date >>1 | |
end | |
months << end_date | |
end | |
end | |
# Date.months_between '2012-09-01'.to_date, Date.today.to_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment