|
1 | | -#winKernel.py |
2 | | -#A part of NonVisual Desktop Access (NVDA) |
3 | | -#Copyright (C) 2006-2019 NV Access Limited, Rui Batista, Aleksey Sadovoy, Peter Vagner, Mozilla Corporation, Babbage B.V., Joseph Lee |
4 | | -#This file is covered by the GNU General Public License. |
5 | | -#See the file COPYING for more details. |
| 1 | +# A part of NonVisual Desktop Access (NVDA) |
| 2 | +# Copyright (C) 2006-2021 NV Access Limited, Rui Batista, Aleksey Sadovoy, Peter Vagner, |
| 3 | +# Mozilla Corporation, Babbage B.V., Joseph Lee, Łukasz Golonka |
| 4 | +# This file is covered by the GNU General Public License. |
| 5 | +# See the file COPYING for more details. |
6 | 6 |
|
7 | 7 | """Functions that wrap Windows API functions from kernel32.dll and advapi32.dll""" |
8 | 8 |
|
9 | 9 | import contextlib |
10 | 10 | import ctypes |
11 | 11 | import ctypes.wintypes |
12 | | -from ctypes import WinError |
| 12 | +from ctypes import byref, Structure, WinError |
13 | 13 | from ctypes import * |
14 | 14 | from ctypes.wintypes import * |
15 | 15 |
|
@@ -160,6 +160,40 @@ class SYSTEMTIME(ctypes.Structure): |
160 | 160 | ("wMilliseconds", WORD) |
161 | 161 | ) |
162 | 162 |
|
| 163 | + |
| 164 | +class FILETIME(Structure): |
| 165 | + _fields_ = ( |
| 166 | + ("dwLowDateTime", DWORD), |
| 167 | + ("dwHighDateTime", DWORD) |
| 168 | + ) |
| 169 | + |
| 170 | + |
| 171 | +def time_tToFileTime(time_tToConvert: float) -> FILETIME: |
| 172 | + """Converts time_t as returned from `time.time` to a FILETIME structure. |
| 173 | + Based on a code snipped from: |
| 174 | + https://docs.microsoft.com/en-us/windows/win32/sysinfo/converting-a-time-t-value-to-a-file-time |
| 175 | + """ |
| 176 | + timeAsFileTime = FILETIME() |
| 177 | + res = (int(time_tToConvert) * 10000000) + 116444736000000000 |
| 178 | + timeAsFileTime.dwLowDateTime = res |
| 179 | + timeAsFileTime.dwHighDateTime = res >> 32 |
| 180 | + return timeAsFileTime |
| 181 | + |
| 182 | + |
| 183 | +def FileTimeToSystemTime(lpFileTime: FILETIME, lpSystemTime: SYSTEMTIME) -> None: |
| 184 | + if kernel32.FileTimeToSystemTime(byref(lpFileTime), byref(lpSystemTime)) == 0: |
| 185 | + raise WinError() |
| 186 | + |
| 187 | + |
| 188 | +def SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation, lpUniversalTime, lpLocalTime): |
| 189 | + if lpTimeZoneInformation is not None: |
| 190 | + lpTimeZoneInformation = byref(lpTimeZoneInformation) |
| 191 | + if kernel32.SystemTimeToTzSpecificLocalTime( |
| 192 | + lpTimeZoneInformation, byref(lpUniversalTime), byref(lpLocalTime) |
| 193 | + ) == 0: |
| 194 | + raise WinError() |
| 195 | + |
| 196 | + |
163 | 197 | def GetDateFormatEx(Locale,dwFlags,date,lpFormat): |
164 | 198 | if date is not None: |
165 | 199 | date=SYSTEMTIME(date.year,date.month,0,date.day,date.hour,date.minute,date.second,0) |
|
0 commit comments