Skip to content

Commit 742e4c2

Browse files
committed
Add TimePoint Correction Factor On Windows
1 parent 72f0785 commit 742e4c2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Sources/SwiftDriver/Utilities/VirtualPath.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,24 @@ extension TSCBasic.FileSystem {
754754
// that regenerate lots of symlinks but do not otherwise alter the
755755
// contents of files - like Bazel - quite happy.
756756
let path = resolveSymlinks(path)
757-
let interval = try localFileSystem.getFileInfo(path).modTime.timeIntervalSince1970
757+
#if os(Windows)
758+
// The NT epoch is 1601, so we need to add a correction factor to bridge
759+
// between Foundation.Date's insistence on using the Mac epoch time of
760+
// 2001 as its reference date.
761+
//
762+
// This factor is a coarse approximation of the difference between
763+
// (Jan 1, 1970 at midnight GMT) and (Jan 1, 1601 at midnight GMT).
764+
//
765+
// DO NOT RELY ON THIS VALUE
766+
//
767+
// This whole thing needs to be replaced by APIs that traffic in values
768+
// derived from uncorrected Windows clocks.
769+
let correction: TimeInterval = 11_644_473_600.0
770+
let unixReferenceDate = try localFileSystem.getFileInfo(path).modTime.timeIntervalSince1970
771+
let interval: TimeInterval = unixReferenceDate + correction
772+
#else
773+
let interval: TimeInterval = try localFileSystem.getFileInfo(path).modTime.timeIntervalSince1970
774+
#endif
758775
return TimePoint(seconds: UInt64(interval.rounded(.down)), nanoseconds: 0)
759776
#endif
760777
}

0 commit comments

Comments
 (0)