Ruby's date/time helpers are useful but I found a discrepancy. It seems that 12.months does not equal 1.year. Check 1.month and you'll find it's equal to 30.days and, of course, 12 * 30.days = 360.days, 5.25 days short of an actual year's length.
I came across this when I set access to certain components of our web site based on the number of months granted, as specified by the client. I discovered that a 36.month term expired a couple of weeks early when running my tests. The solution was something like this:
def months_to_seconds(number_of_months)
( (number_of_months.to_f / 12) * 1.year).to_i.seconds
end
This returns the number of seconds in whatever fraction of a year is represented by the number_of_months.
Since 1.year is equal in seconds to 365.25 days, why do you suppose they didn't have 1.month return the seconds for 1/12 of a year instead of 30 days?
Has anyone run across this before? Does anyone have a better solution?