From: Robert Klemme Date: 2005-09-27T04:41:42+09:00 Subject: Re: Time interval Daniel Berger wrote: > Hi all, > > I was just wondering if anyone has implemented an "Interval" class of > some sort out there, i.e. something that would give you the years, > months, days, hours, minutes and seconds between two fixed DateTime > objects, rather than an absolute date. Note that it's easy to output difference in seconds, minutes, hours, days and weeks but then it starts to get more difficult. I once cooked up something albeit in Java that takes two arrays (an array with factors and an array with unit names) and a value and constructs a string from that. Untested: def create_units(val, factors, units) raise "mismatch" unless factors.size == units.size r = [] factors.zip(units) do |f,u| v = val % f r << "#{val} #{v}" if v != 0 val = (val - v) / f end r.reverse! r.join " " end Kind regards robert