Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse timestamps given as 64-bit integer in little-endian format with Ruby?

I'm curious how to parse these weird timestamps in Ruby:

566455139129676
566455199011666
566455199892825
566455259010949
566455319010859
566455335000847
566455336000936
566455336127533
566455347898055

Here's what I know about the format of these timestamps:

The value is a 64-bit integer in little-endian format containing the number of microseconds since Julian day: Jan 01 2000 00:00:00 in the UTC timezone.

For the curious, these are Vertica's internal representation of timestamps: https://my.vertica.com/docs/9.0.x/HTML/index.htm#Authoring/AdministratorsGuide/BinaryFilesAppendix/ColumnDefinitions.htm

Any help would be most appreciated.

like image 916
twneale Avatar asked Feb 01 '26 04:02

twneale


1 Answers

Not really sure what endianness would have to do with anything here. You've got an integer already.

So Epoch is Jan 01, 2000? Basically you just need to account for diff between epochs, 1969-12-31 and theirs...

epoch = Time.new(2000, 1, 1)

epochOffset = epoch.to_i - Time.at(0).to_i;

ts = Time.at((566455347898055 / 1000000) + epochOffset)

print ts.strftime "%Y-%m-%d %H:%M:%S %z";

> 2017-12-13 04:42:27 +0000
like image 129
ficuscr Avatar answered Feb 03 '26 01:02

ficuscr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!