[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: representing a span of time

Berger, Daniel

9/5/2006 10:10:00 PM

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

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.

4 Answers

Brad Tilley

9/5/2006 10:26:00 PM

0

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

Ara.T.Howard

9/5/2006 10:44:00 PM

0

Brad Tilley

9/5/2006 11:59:00 PM

0

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

Ara.T.Howard

9/6/2006 1:26:00 AM

0