How to reference a different epoch

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?

On Wed, Jan 19, 2011 at 10:51 PM, Phil H. [email protected]
wrote:

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

On Thu, Jan 20, 2011 at 6:51 AM, Phil H. [email protected]
wrote:

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?

That seems fairly easy

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

Kind regards

robert

Well those solutions seem obvious enough. Thanks for the help!