Skip to content

Commit

Permalink
Proper implementation for GetSystemTime and GetLocalTime (#73)
Browse files Browse the repository at this point in the history
* Implement

* GetLocalTime
  • Loading branch information
AngheloAlf authored Mar 23, 2024
1 parent 0fbe877 commit 396008c
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions dll/kernel32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,19 +1133,36 @@ namespace kernel32 {

void WIN_FUNC GetSystemTime(SYSTEMTIME *lpSystemTime) {
DEBUG_LOG("GetSystemTime\n");
lpSystemTime->wYear = 0;
lpSystemTime->wMonth = 0;
lpSystemTime->wDayOfWeek = 0;
lpSystemTime->wDay = 0;
lpSystemTime->wHour = 0;
lpSystemTime->wMinute = 0;
lpSystemTime->wSecond = 0;

time_t t = time(NULL);
struct tm *tm = gmtime(&t);
assert(tm != NULL);

lpSystemTime->wYear = tm->tm_year + 1900;
lpSystemTime->wMonth = tm->tm_mon + 1;
lpSystemTime->wDayOfWeek = tm->tm_wday;
lpSystemTime->wDay = tm->tm_mday;
lpSystemTime->wHour = tm->tm_hour;
lpSystemTime->wMinute = tm->tm_min;
lpSystemTime->wSecond = tm->tm_sec;
lpSystemTime->wMilliseconds = 0;
}

void WIN_FUNC GetLocalTime(SYSTEMTIME *lpSystemTime) {
DEBUG_LOG("GetLocalTime\n");
GetSystemTime(lpSystemTime);

time_t t = time(NULL);
struct tm *tm = localtime(&t);
assert(tm != NULL);

lpSystemTime->wYear = tm->tm_year + 1900;
lpSystemTime->wMonth = tm->tm_mon + 1;
lpSystemTime->wDayOfWeek = tm->tm_wday;
lpSystemTime->wDay = tm->tm_mday;
lpSystemTime->wHour = tm->tm_hour;
lpSystemTime->wMinute = tm->tm_min;
lpSystemTime->wSecond = tm->tm_sec;
lpSystemTime->wMilliseconds = 0;
}

int WIN_FUNC SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, FILETIME *lpFileTime) {
Expand Down

0 comments on commit 396008c

Please sign in to comment.