Skip to content

Commit

Permalink
winapi: Implement GetLocalTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryzee119 authored and mborgerson committed Jul 7, 2023
1 parent 410ec61 commit 5aba581
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/winapi/sysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

// SPDX-FileCopyrightText: 2019 Stefan Schmidt
// SPDX-FileCopyrightText: 2020 Samuel Cuella
// SPDX-FileCopyrightText: 2023 Ryan Wendland

#include <sysinfoapi.h>
#include <timezoneapi.h>
#include <assert.h>
#include <xboxkrnl/xboxkrnl.h>

Expand Down Expand Up @@ -50,3 +52,41 @@ void GetSystemInfo (LPSYSTEM_INFO lpSystemInfo)
lpSystemInfo->dwNumberOfProcessors = 1;
lpSystemInfo->dwAllocationGranularity = 4096;
}

void GetLocalTime (LPSYSTEMTIME lpSystemTime)
{
assert(lpSystemTime != NULL);

LARGE_INTEGER kTime;
TIME_FIELDS timeFields;
TIME_ZONE_INFORMATION tzInfo;
LONG bias;

switch (GetTimeZoneInformation(&tzInfo)) {
case TIME_ZONE_ID_UNKNOWN:
bias = tzInfo.Bias;
break;
case TIME_ZONE_ID_STANDARD:
bias = tzInfo.Bias + tzInfo.StandardBias;
break;
case TIME_ZONE_ID_DAYLIGHT:
bias = tzInfo.Bias + tzInfo.DaylightBias;
break;
default:
bias = 0;
break;
}

KeQuerySystemTime(&kTime);
kTime.QuadPart -= (bias * 60LL * 10000000LL);

RtlTimeToTimeFields(&kTime, &timeFields);
lpSystemTime->wYear = timeFields.Year;
lpSystemTime->wMonth = timeFields.Month;
lpSystemTime->wDay = timeFields.Day;
lpSystemTime->wHour = timeFields.Hour;
lpSystemTime->wMinute = timeFields.Minute;
lpSystemTime->wSecond = timeFields.Second;
lpSystemTime->wMilliseconds = timeFields.Millisecond;
lpSystemTime->wDayOfWeek = timeFields.Weekday;
}
1 change: 1 addition & 0 deletions lib/winapi/sysinfoapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ extern "C" {
void GetSystemTime (LPSYSTEMTIME lpSystemTime);
void GetSystemTimePreciseAsFileTime (LPFILETIME lpSystemTimeAsFileTime);
DWORD GetTickCount (void);
void GetLocalTime (LPSYSTEMTIME lpSystemTime);

// Unprovided fields are intentionally disabled to catch code trying to access them
typedef struct _SYSTEM_INFO
Expand Down

0 comments on commit 5aba581

Please sign in to comment.