On Wed, 6 Sep 2006, Brad Tilley wrote:

>> a = Time.mktime(1972, 1, 15, 0, 0, 0).utc
>> b = Time.now.utc
>>
>> delta = b - a
>>
>> puts delta.decades
>> puts delta.years
>>
>> harp:~ > ruby a.rb
>> 3.76567099435856
>> 37.6567099435856 #This should be 34 years... what is it 37? (2006 - 1972 = 34)

basically because it's using 28 days months since it's impossible to tell when
one says

   2.months

whether that should be 28 + 31 vs. 29 + 31 days, etc.  so 1.month is simply
equal to 4.weeks and 1.year is 12.months.  however, i that is not good
behaviour so the latest release will give:

     harp:~ > cat a.rb
     require 'yaml'
     require 'rubygems'
     require 'timeunits'

     a = Time.mktime(1972, 1, 15, 0, 0, 0).utc
     b = Time.now.utc

     delta = b - a
     y 'delta.years' => delta.years

     seconds_per_day = 1.day
     y 'seconds_per_day' => seconds_per_day

     n_days = 0 and ((a += seconds_per_day and n_days += 1) while a < b)
     y 'n_days' => n_days

     days_per_year = 365
     n_years = Float(n_days)/Float(days_per_year)
     y 'n_years' => n_years


     harp:~ > ruby a.rb
     delta.years: 34.6651137623302
     seconds_per_day: 86400
     n_days: 12653
     n_years: 34.6657534246575


i may re-consider the method used to set the delta fields to another method.

thanks for the bug report.

-a
-- 
what science finds to be nonexistent, we must accept as nonexistent; but what
science merely does not find is a completely different matter... it is quite
clear that there are many, many mysterious things.
- h.h. the 14th dalai lama