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
9 changes: 4 additions & 5 deletions Sources/DistributedCluster/TimeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ extension TimeSpec {
@usableFromInline
internal static func + (a: timespec, b: timespec) -> timespec {
let totalNanos = a.toNanos() + b.toNanos()
let seconds = totalNanos / NANOS
var result = timespec()
result.tv_sec = seconds
result.tv_nsec = totalNanos % NANOS
result.tv_sec = Int(totalNanos / Int64(NANOS))
result.tv_nsec = Int(totalNanos % Int64(NANOS))
return result
}

@usableFromInline
internal func toNanos() -> Int {
self.tv_nsec + (self.tv_sec * NANOS)
internal func toNanos() -> Int64 {
Int64(self.tv_nsec) + (Int64(self.tv_sec) * Int64(NANOS))
}
}
2 changes: 1 addition & 1 deletion Tests/DistributedClusterTests/TimeSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class TimeSpecTests: XCTestCase {
}

func test_timeSpecShouldBeCreatedProperlyFromDuration() {
self.total.toNanos().shouldEqual(Int(self.totalDuration.nanoseconds))
self.total.toNanos().shouldEqual(Int64(self.totalDuration.nanoseconds))
self.total.tv_sec.shouldEqual(Int(self.totalDuration.nanoseconds) / NANOS)
self.total.tv_nsec.shouldEqual(Int(self.totalDuration.nanoseconds) % NANOS)
}
Expand Down