Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extension Date {
li.LowPart = ft.dwLowDateTime
li.HighPart = ft.dwHighDateTime
// FILETIME represents 100-ns intervals since January 1, 1601 (UTC)
return TimeInterval((li.QuadPart - 1164447360_000_000) / 1_000_000_000)
return TimeInterval(Double(li.QuadPart) / 10_000_000.0 - Self.timeIntervalBetween1601AndReferenceDate)
#else
var ts: timespec = timespec()
clock_gettime(CLOCK_REALTIME, &ts)
Expand Down
6 changes: 6 additions & 0 deletions Tests/FoundationEssentialsTests/DateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ final class DateTests : XCTestCase {
XCTAssertEqual("<description unavailable>", date.description)
#endif
}

func testNowIsAfterReasonableDate() {
let date = Date.now
XCTAssert(date.timeIntervalSinceReferenceDate > 742100000.0) // "2024-07-08T02:53:20Z"
XCTAssert(date.timeIntervalSinceReferenceDate < 3896300000.0) // "2124-06-21T01:33:20Z"
}
}

// MARK: - Bridging
Expand Down