Skip to content

Commit 42e3325

Browse files
authored
Use winrt for time conversion (microsoft#5763)
## Change [The Old New Thing](https://devblogs.microsoft.com/oldnewthing/20251001-00/?p=111643) pointed out that `winrt` provides a helper to do this conversion that I recently added. Use it instead.
1 parent ae31791 commit 42e3325

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

src/AppInstallerSharedLib/DateTime.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,7 @@ namespace AppInstaller::Utility
146146

147147
std::chrono::system_clock::time_point ConvertFiletimeToSystemClock(const FILETIME& fileTime)
148148
{
149-
// Windows epoch (1601) to Unix epoch (1970) offset in 100-nanosecond intervals
150-
constexpr int64_t EPOCH_DIFFERENCE = 116444736000000000LL;
151-
152-
// Combine FILETIME into a 64-bit value
153-
uint64_t fileTimeValue = (static_cast<uint64_t>(fileTime.dwHighDateTime) << 32) | fileTime.dwLowDateTime;
154-
155-
// Convert to 100-nanosecond intervals since Unix epoch
156-
int64_t unixTime100ns = static_cast<int64_t>(fileTimeValue) - EPOCH_DIFFERENCE;
157-
158-
// Convert to chrono duration (system_clock::duration is usually nanoseconds or microseconds)
159-
return std::chrono::system_clock::time_point(
160-
std::chrono::duration_cast<std::chrono::system_clock::duration>(
161-
std::chrono::nanoseconds(unixTime100ns * 100)));
149+
return winrt::clock::to_sys(winrt::clock::from_FILETIME(fileTime));
162150
}
163151

164152
std::chrono::system_clock::time_point GetTimePointFromVersion(const UInt64Version& version)

0 commit comments

Comments
 (0)