Skip to content

WinSDK: add convenience conversions for FILETIME/time_t #23342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions stdlib/public/Windows/WinSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,17 @@ public let TOOLBARW_CLASSW: [WCHAR] = Array<WCHAR>("ToolbarWindow32".utf16)
public let TRACKBAR_CLASSW: [WCHAR] = Array<WCHAR>("msctls_trackbar32".utf16)
public let UPDOWN_CLASSW: [WCHAR] = Array<WCHAR>("msctls_updown32".utf16)

// Swift Convenience
public extension FILETIME {
var time_t: time_t {
let NTTime: Int64 = Int64(self.dwLowDateTime) | (Int64(self.dwHighDateTime) << 32)
return (NTTime - 116444736000000000) / 10000000
}

init(from time: time_t) {
let UNIXTime: Int64 = ((time * 10000000) + 116444736000000000)
self = FILETIME(dwLowDateTime: DWORD(UNIXTime & 0xffffffff),
dwHighDateTime: DWORD((UNIXTime >> 32) & 0xffffffff))
}
}