Merge pull request #3 from YOCKOW/development

Add some properties.
This commit is contained in:
YOCKOW 2019-04-23 20:13:13 +09:00 committed by GitHub
commit 28d94af3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,8 @@ import Glibc
private typealias CTimeSpec = timespec
#endif
import Foundation
/// The representation for the time in nanoseconds.
public struct TimeSpecification {
public var seconds: Int64 = 0
@ -90,6 +92,24 @@ extension TimeSpecification: ExpressibleByFloatLiteral {
}
}
extension TimeSpecification {
/// The value of seconds
public var integerValue: Int { return Int(self.seconds) }
/// Double representation of the time.
public var doubleValue: Double { return Double(self.nanoseconds) * 1.0E-9 + Double(self.seconds) }
}
extension TimeSpecification: CustomStringConvertible, CustomDebugStringConvertible {
public var description: String {
return String(format:"%.09f seconds", self.doubleValue)
}
public var debugDescription: String {
return self.description
}
}
// sum and difference
extension TimeSpecification {
public static func +(lhs:TimeSpecification, rhs:TimeSpecification) -> TimeSpecification {