Representing a span of time

Are these values seconds since epoch? If so:

irb(main):002:0> Time.at(1157489583.2798 - 64299600.0)
=> Sun Aug 22 09:53:03 MDT 2004

Regards,

Dan

This communication is the property of Qwest and may contain confidential or
privileged information. Unauthorized use of this communication is strictly
prohibited and may be unlawful. If you have received this communication
in error, please immediately notify the sender by reply e-mail and destroy
all copies of the communication and any attachments.

···

-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Brad Tilley
Sent: Tuesday, September 05, 2006 3:02 PM
To: ruby-talk ML
Subject: representing a span of time

Say I have two time objects represented as floats like so:

x = 64299600.0
y = 1157489583.2798

I want to subtract x from y and then represent the difference
as years,
months, days, hours, minutes and seconds.

I don't see how the Time library would do this. Has anyone done
something like this? If so, how?

Thanks,
Brad

Berger, Daniel wrote:

x = 64299600.0
Brad

Are these values seconds since epoch? If so:

irb(main):002:0> Time.at(1157489583.2798 - 64299600.0)
=> Sun Aug 22 09:53:03 MDT 2004

They are dates in time from Time.mktime(1972, 1, 15, 0, 0, 0) and
Time.now() represented as floats. Basically, I would like to show the
difference in a human significant way (years, months, days, etc.)

···

--
Posted via http://www.ruby-forum.com/\.

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

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

delta = b - a

puts delta.decades
puts delta.years
puts delta.months
puts delta.days
puts delta.minutes
puts delta.seconds

harp:~ > ruby a.rb
3.76567099435856
37.6567099435856
451.880519323027
12652.6545410448
18219822.5391045
1093189352.34627

-a

···

On Wed, 6 Sep 2006, Brad Tilley wrote:

Berger, Daniel wrote:

x = 64299600.0
Brad

Are these values seconds since epoch? If so:

irb(main):002:0> Time.at(1157489583.2798 - 64299600.0)
=> Sun Aug 22 09:53:03 MDT 2004

They are dates in time from Time.mktime(1972, 1, 15, 0, 0, 0) and
Time.now() represented as floats. Basically, I would like to show the
difference in a human significant way (years, months, days, etc.)

They are dates in time from Time.mktime(1972, 1, 15, 0, 0, 0) and
Time.now() represented as floats. Basically, I would like to show the

--
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

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)

···

--
Posted via http://www.ruby-forum.com/\.

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

···

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)

--
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