93 lines
2.5 KiB
C
93 lines
2.5 KiB
C
/*! \file pitime_win.h
|
|
* \brief PITime conversions for Windows
|
|
*
|
|
* This file declare time conversions for Windows
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
PITime conversions for Windows
|
|
Copyright (C) 2020 Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#ifndef PITIME_WIN_H
|
|
#define PITIME_WIN_H
|
|
|
|
#include "pibase.h"
|
|
#ifdef WINDOWS
|
|
|
|
#include "pitime.h"
|
|
#include <windows.h>
|
|
|
|
|
|
//inline PISystemTime SYSTEMTIME2PISystemTime(SYSTEMTIME &t) {
|
|
// PISystemTime st;
|
|
|
|
//}
|
|
|
|
inline PISystemTime FILETIME2PISystemTime(const FILETIME &t) {
|
|
PISystemTime st;
|
|
ullong lt = ullong(t.dwHighDateTime) * 0x100000000U + ullong(t.dwLowDateTime);
|
|
st.seconds = lt / 10000000U;
|
|
st.nanoseconds = (lt % 10000000U) * 100U;
|
|
return st;
|
|
}
|
|
|
|
|
|
|
|
inline PIDateTime SYSTEMTIME2PIDateTime(const SYSTEMTIME &t) {
|
|
PIDateTime dt;
|
|
dt.year = t.wYear;
|
|
dt.month = t.wMonth;
|
|
dt.day = t.wDay;
|
|
dt.hours = t.wHour;
|
|
dt.minutes = t.wMinute;
|
|
dt.seconds = t.wSecond;
|
|
dt.milliseconds = t.wMilliseconds;
|
|
return dt;
|
|
}
|
|
|
|
inline PIDateTime FILETIME2PIDateTime(const FILETIME &t) {
|
|
FILETIME lt;
|
|
SYSTEMTIME st;
|
|
FileTimeToLocalFileTime(&t, <);
|
|
FileTimeToSystemTime(<, &st);
|
|
return SYSTEMTIME2PIDateTime(st);
|
|
}
|
|
|
|
inline SYSTEMTIME PIDateTime2SYSTEMTIME(const PIDateTime &dt) {
|
|
SYSTEMTIME st;
|
|
st.wYear = dt.year;
|
|
st.wMonth = dt.month;
|
|
st.wDay = dt.day;
|
|
st.wHour = dt.hours;
|
|
st.wMinute = dt.minutes;
|
|
st.wSecond = dt.seconds;
|
|
st.wMilliseconds = dt.milliseconds;
|
|
return st;
|
|
}
|
|
|
|
inline FILETIME PIDateTime2FILETIME(const PIDateTime &dt) {
|
|
FILETIME lt, ret;
|
|
SYSTEMTIME st = PIDateTime2SYSTEMTIME(dt);
|
|
SystemTimeToFileTime(&st, <);
|
|
LocalFileTimeToFileTime(<, &ret);
|
|
return ret;
|
|
}
|
|
|
|
|
|
|
|
#endif // WINDOWS
|
|
#endif // PITIME_WIN_H
|