diff --git a/Sources/FoundationEssentials/Date.swift b/Sources/FoundationEssentials/Date.swift index 107fe3711..8811aa433 100644 --- a/Sources/FoundationEssentials/Date.swift +++ b/Sources/FoundationEssentials/Date.swift @@ -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) diff --git a/Tests/FoundationEssentialsTests/DateTests.swift b/Tests/FoundationEssentialsTests/DateTests.swift index 12dd8c493..e5bd5ba3f 100644 --- a/Tests/FoundationEssentialsTests/DateTests.swift +++ b/Tests/FoundationEssentialsTests/DateTests.swift @@ -127,6 +127,12 @@ final class DateTests : XCTestCase { XCTAssertEqual("", 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