Skip to content

Commit

Permalink
Merge pull request #3 from YOCKOW/development
Browse files Browse the repository at this point in the history
Add some properties.
  • Loading branch information
YOCKOW authored Apr 23, 2019
2 parents 60755e3 + c7a3043 commit 28d94af
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/TimeSpecification/TimeSpecification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 28d94af

Please sign in to comment.