Tuesday, April 19, 2005

Epoch

We are Microsoft, we will store dates with a different epoch and a different granularity to Unix.

An epoch of 01 Jan 1970 00:00:00 isn't good enough for us, no we want 01 Jan 1601, 00:00:00. There much better.

And whats this seconds rubbish, we want 100 nanosecond ticks thanks very much. And we will call it file time so as to really confuse you.

But its ok, well give you this really obvious conversion function so you can make all your code non standard.


#include

void TimetToFileTime( time_t t, LPFILETIME pft )
{
LONGLONG ll = Int32x32To64(t, 10000000)
+ 116444736000000000;
pft->dwLowDateTime = (DWORD) ll;
pft->dwHighDateTime = ll >>32;
}


Did you catch that ?


116444736000000000 / 10 = 11644473600000000 (Microseconds)
11644473600000000 / 1000 = 11644473600000 (Milliseconds)
11644473600000 / 1000 = 11644473600 (Seconds)
11644473600 / 60 = 194074560 (Minutes)
194074560 / 60 = 3234576 (Hours)
3234576 /24 = 134774 (Days)
134774 / 365 = ~369 (Years)


Which is roughly the interval between the two epochs, give or take a few leap years and leap seconds.

Oh yea, and then in .NET we will change it all again, just to be cool. Now we want the ultimate epoch - midnight on the 01 Jan A.D. Beat that Richard Stallman.