]> git.tdb.fi Git - libs/core.git/blob - source/time/rawtime.cpp
Style fix: split function bodies to separate line outside of class
[libs/core.git] / source / time / rawtime.cpp
1 #include "rawtime.h"
2 #include "rawtime_private.h"
3
4 namespace {
5
6 #ifdef WIN32
7 /// Returns the unixtime epoch as filetime
8 Msp::Time::RawTime get_epoch()
9 {
10         SYSTEMTIME st;
11         st.wYear = 1970;
12         st.wMonth = 1;
13         st.wDay = 1;
14         st.wHour = 0;
15         st.wMinute = 0;
16         st.wSecond = 0;
17         st.wMilliseconds = 0;
18
19         FILETIME ft;
20         SystemTimeToFileTime(&st, &ft);
21         return (ft.dwLowDateTime+(static_cast<Msp::Time::RawTime>(ft.dwHighDateTime)<<32))/10;
22 }
23 #endif
24
25 }
26
27
28 namespace Msp {
29 namespace Time {
30
31 #ifdef WIN32
32 RawTime filetime_to_rawtime(const FILETIME &ft)
33 {
34         static RawTime epoch = get_epoch();
35         
36         return (ft.dwLowDateTime+(static_cast<RawTime>(ft.dwHighDateTime)<<32))/10-epoch;
37 }
38 #else
39 timeval rawtime_to_timeval(RawTime raw)
40 {
41         timeval tv;
42         tv.tv_sec = raw/1000000;
43         tv.tv_usec = raw%1000000;
44         return tv;
45 }
46
47 timespec rawtime_to_timespec(RawTime raw)
48 {
49         timespec ts;
50         ts.tv_sec = raw/1000000;
51         ts.tv_nsec = (raw%1000000)*1000;
52         return ts;
53 }
54
55 RawTime timeval_to_rawtime(const timeval &tv)
56 {
57         return tv.tv_sec*1000000LL+tv.tv_usec;
58 }
59 #endif
60
61 } // namespace Time
62 } // namespace Msp