diff --git a/Sources/TimeSpecification/TimeSpecification.swift b/Sources/TimeSpecification/TimeSpecification.swift index 05821a2..715cbc7 100644 --- a/Sources/TimeSpecification/TimeSpecification.swift +++ b/Sources/TimeSpecification/TimeSpecification.swift @@ -106,11 +106,11 @@ extension TimeSpecification { extension TimeSpecification: CustomStringConvertible, CustomDebugStringConvertible { public var description: String { - return String(format:"%.09f seconds", self.doubleValue) + return String(format:"\(self.seconds).%09d", self.nanoseconds) } public var debugDescription: String { - return self.description + return self.description + " seconds." } } diff --git a/Tests/TimeSpecificationTests/TimeSpecificationTests.swift b/Tests/TimeSpecificationTests/TimeSpecificationTests.swift index 669026f..22999ac 100644 --- a/Tests/TimeSpecificationTests/TimeSpecificationTests.swift +++ b/Tests/TimeSpecificationTests/TimeSpecificationTests.swift @@ -46,6 +46,11 @@ class TimeSpecificationTests: XCTestCase { XCTAssertEqual(L1 - R1, TimeSpecification(seconds:0, nanoseconds:-864_197_532), "Difference Test 1") } + func test_description() { + let spec = TimeSpecification(seconds: 123, nanoseconds: 456_789) + XCTAssertEqual(spec.description, "123.000456789") + } + func test_date() { let spec = TimeSpecification(seconds: 100, nanoseconds: 123_456_789) XCTAssertEqual(Date(timeIntervalSinceReferenceDate: spec),