# Re: representing a span of time

**URL:** <https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677>\
**Category:** Ruby\
**Created:** [September 6, 2006, 12:18am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677 "2006-09-06T00:18:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 6, 2006, 12:18am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677/1 "2006-09-06T00:18:44Z")

</div>

> 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

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.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 6, 2006, 12:25am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677/2 "2006-09-06T00:25:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 6, 2006, 12:46am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677/3 "2006-09-06T00:46:46Z")

</div>

On Wed, 6 Sep 2006, Brad T. wrote:

> 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

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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 6, 2006, 3:26am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677/4 "2006-09-06T03:26:57Z")

</div>

On Wed, 6 Sep 2006, Brad T. wrote:

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

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [September 6, 2006, 1:59am UTC](https://www.ruby-forum.com/t/re-representing-a-span-of-time/67677/5 "2006-09-06T01:59:01Z")

</div>

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