How to reference a different epoch.

P

Phil Henley

I'm trying to use the 'at' method in Time on some data pulled from an
OSX file:

Time.at(317192535.56501901)

And my result is off by 30 years. I assume this is because Ruby is
referencing the Unix epoch of 1/1/1970 and I need to reference the OSX
epoch of 1/1/2000. Is there an easy way to change this so I'm
referencing the OSX epoch?
 
J

Jonathan Nielsen

I'm trying to use the 'at' method in Time on some data pulled from an
OSX file:

Time.at(317192535.56501901)

And my result is off by 30 years. =C2=A0I assume this is because Ruby is
referencing the Unix epoch of 1/1/1970 and I need to reference the OSX
epoch of 1/1/2000. =C2=A0Is there aSn easy way to change this so I'm
referencing the OSX epoch?
Sure, you should be able to add 978307200 to the result of your
Time.at call. I believe that's the right number anyway, it's the
result of Time.mktime("2001 Jan 01") - Time.mktime("1970 Jan 01").

-Jonathan Nielsen
 
R

Robert Klemme

I'm trying to use the 'at' method in Time on some data pulled from an
OSX file:

Time.at(317192535.56501901)

And my result is off by 30 years. =A0I assume this is because Ruby is
referencing the Unix epoch of 1/1/1970 and I need to reference the OSX
epoch of 1/1/2000. =A0Is there an easy way to change this so I'm
referencing the OSX epoch?

That seems fairly easy

irb(main):001:0> OSX_EPOCH =3D Time.new(2001,1,1).to_i
=3D> 978303600
irb(main):002:0> Time.at(317192535.56501901 + OSX_EPOCH)
=3D> 2011-01-20 05:02:15 +0100

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top