1

I am reading a paradox file with the .DB extension. I have successfully read header and records but I have some problem on the Timestamp type. Timestamp take 8 bytes and are formatted like this:

Float field where the integer portion is the number of days since Jan 1, 0001 and the fractional part is the time -- expressed as a proportion of the day. For example, 6:00 PM would be .75 since it is 3/4 of the day past midnight.

I have already read Date type (number of days since Jan 1, 0001). And I know the two following :

1 10000101100 1100111100010110100010001100111000010010101010000000  > 14/11/2017 09:05:18
1 10000101100 1100111010011000001111011111111100101100000000000000  > 21/09/2015 15:01:39

I have the following code:

#include <math.h>
#include <cmath>
union Converter { uint64_t i; double d; };

std::bitset<64> timestamp(0);
double intpart, fractpart;

for (int i = 0; i<end-start; i++) {
    timestamp <<= 8;
    timestamp ^= (unsigned char)(buffer[start+i]);
}
fractpart = modf(convert(timestamp.to_ullong()),&intpart);
unsigned long int test = (unsigned long int)intpart;
std::cout<<test;

Which returns 786841003 for the integer portion, and that number is way too big, even divided by 1000.

EDIT:

std::cout<<std::fixed<<'\n'<<convert(timestamp.to_ullong());
std::cout<<std::fixed<<'\n'<<intpart;

-63578530899343.000000
-63578530899343.000000

I don't have any fractional part, I am maybe reading the bytes in a wrong order?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Mercor
  • 11
  • 2
  • why are you doing all this fancy bit twiddling. Its a double, use the standard methods of getting the integer part and fraction part of a double – pm100 Sep 19 '18 at 22:29
  • https://stackoverflow.com/questions/23993898/how-to-separate-float-into-an-integer-and-a-fractional-part – pm100 Sep 19 '18 at 22:30

1 Answers1

0

The way to read it was wrong : Timestamp is a double that old the number of millisecond from 1/1/0001 so I convert It like this :

    double tmsDouble = abs(convert(timestamp.to_ullong()));
    long long int tms= (long long int)tmsDouble ;
    std::cout<<'\n'<<((tms/(86400*1000))-719163)*86400;

And I get a standard epoch time. 719163 is the number of days between 1/1/1970 and 1/1/0001.

Mercor
  • 11
  • 2