Unique timestamp for different datafiles

Hello guys, :)

I have a question which is a little bit far from C++ programming. But I didn't really know where I could post it.

I have a few data files which of timestamps of the form "2011-05-23_18:23:09.115_UTC". I need to compare such timestamps between different files with some tolerance in milli-seconds. I could make a function that separates everything in it to something like:

1
2
3
4
5
6
7
year = 2011;
month = 05;
day = 23;
hour = 18;
minute = 23;
second = 09;
msecond = 115;


So the problem is now, how can I combine all these numbers to get a unique timestamp with no conflicts? the result has to be stored in a 64-bit integer.

If having an integer is a bad idea, is there a better one? I need an efficient method for huge data files.

thank you for any efforts :)
You can use the different bits in the 64-bit number to store the data.

Here is an example:

Use first 12 bits to store the year. This will give you a number from 0 to 4095. Plenty.

Use next 4 bits to store month.

Next 5 bits to store day.

Next 5 bits for hour.

Next 5 bits for minute.

Next 6 bits for second.

Leaving over 25 bits left for the milliseconds. Plenty.

To do this, you can use the bitshift operator and the bitwise or operator.

It might look something like this, for example.

1
2
3
4
int_64 someValue = 0; // 64 bits
someValue  = someValue | year;
someValue  = somevalue | (month<<12); // Make sure that whatever type month is has enough space to bitshift 12 places
someValue  = somevalue | (day<<17); // Make sure that whatever type day is has enough space to bitshift 17 places 


and so on.


Last edited on
In your function example, you could convert all of the values to mili-seconds and add them up. Then just compare one value to another to another
The operating system may not maintain millisec accuracy on files. In fact, I know that Windows doesn't. So any processing that relies on this level of accuracy will have race conditions.
Thanks guys! I think 2 good ideas are present here! I'll try them both :D

Thanks again!! :)
Topic archived. No new replies allowed.