Skip to content

Commit 4473b74

Browse files
committed
WinSDK: add convenience conversions for FILETIME/time_t
This conversion is error prone and pretty common. Provide a helper initializer and conversion through a getter.
1 parent 3ee1add commit 4473b74

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/public/Windows/WinSDK.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ public let TOOLBARW_CLASSW: [WCHAR] = Array<WCHAR>("ToolbarWindow32".utf16)
7171
public let TRACKBAR_CLASSW: [WCHAR] = Array<WCHAR>("msctls_trackbar32".utf16)
7272
public let UPDOWN_CLASSW: [WCHAR] = Array<WCHAR>("msctls_updown32".utf16)
7373

74+
// Swift Convenience
75+
public extension FILETIME {
76+
var time_t: time_t {
77+
let NTTime: Int64 = Int64(self.dwLowDateTime) | (Int64(self.dwHighDateTime) << 32)
78+
return (NTTime - 116444736000000000) / 10000000
79+
}
80+
81+
init(from time: time_t) {
82+
let UNIXTime: Int64 = ((time * 10000000) + 116444736000000000)
83+
self = FILETIME(dwLowDateTime: DWORD(UNIXTime & 0xffffffff),
84+
dwHighDateTime: DWORD((UNIXTime >> 32) & 0xffffffff))
85+
}
86+
}
87+

0 commit comments

Comments
 (0)