X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ftime%2Frawtime.cpp;h=a299246a0fde69acfb77ed86e948e5265586c1a9;hp=5c21a683ce295a026b6bd8e4f970950e2d952aba;hb=2959598108418ebebe84c76c274d58eda0eab5e8;hpb=03bacb2343eb5d17819732582c0866f087e9ce27 diff --git a/source/time/rawtime.cpp b/source/time/rawtime.cpp index 5c21a68..a299246 100644 --- a/source/time/rawtime.cpp +++ b/source/time/rawtime.cpp @@ -1,10 +1,41 @@ #include "rawtime.h" #include "rawtime_private.h" +namespace { + +#ifdef WIN32 +/// Returns the unixtime epoch as filetime +Msp::Time::RawTime get_epoch() +{ + SYSTEMTIME st; + st.wYear = 1970; + st.wMonth = 1; + st.wDay = 1; + st.wHour = 0; + st.wMinute = 0; + st.wSecond = 0; + st.wMilliseconds = 0; + + FILETIME ft; + SystemTimeToFileTime(&st, &ft); + return (ft.dwLowDateTime+(static_cast(ft.dwHighDateTime)<<32))/10; +} +#endif + +} + + namespace Msp { namespace Time { -#ifndef WIN32 +#ifdef WIN32 +RawTime filetime_to_rawtime(const FILETIME &ft) +{ + static RawTime epoch = get_epoch(); + + return (ft.dwLowDateTime+(static_cast(ft.dwHighDateTime)<<32))/10-epoch; +} +#else timeval rawtime_to_timeval(RawTime raw) { timeval tv; @@ -20,6 +51,11 @@ timespec rawtime_to_timespec(RawTime raw) ts.tv_nsec = (raw%1000000)*1000; return ts; } + +RawTime timeval_to_rawtime(const timeval &tv) +{ + return tv.tv_sec*1000000LL+tv.tv_usec; +} #endif } // namespace Time