I am using ParquetSharp to read a parquet file. One of the columns is typed as Int96. In reality it is a DateTime. I need to convert said ParquetSharp.Int96 to a System.DateTime.
Asked
Active
Viewed 545 times
1 Answers
1
I did this using the oddly named int A, int B, int C properties of the Int96 type. These Properties correspond to the 4 byte blocks that make up the int96.
using info found in here: Cast int96 timestamp from parquet to golang Int96Value to Date string
(there is some mention of magic numbers in these links.)
I was able to come up with this:
DateTime ConvertToDateTime(Int96 typed)
{
var date = DateTime.FromOADate(typed.C - 2415018.5);
var a = BitConverter.GetBytes(typed.A);
var b = BitConverter.GetBytes(typed.B);
var nano = a.Concat(b).ToArray();
var nanoLong = BitConverter.ToInt64(nano, 0);
var result = date.AddTicks(nanoLong / 100);
return result;
}