From 1fde22be164b2c6452f557f970661517a348c745 Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Thu, 28 May 2020 13:08:49 +0900 Subject: [PATCH 1/2] Add a property `Float80`. --- Sources/TimeSpecification/TimeSpecification.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/TimeSpecification/TimeSpecification.swift b/Sources/TimeSpecification/TimeSpecification.swift index e77eee6..4f43828 100644 --- a/Sources/TimeSpecification/TimeSpecification.swift +++ b/Sources/TimeSpecification/TimeSpecification.swift @@ -121,6 +121,14 @@ extension TimeSpecification { /// Double representation of the time. @inlinable public var doubleValue: Double { return Double(self.nanoseconds) * 1.0E-9 + Double(self.seconds) } + + #if arch(i386) || arch(x86_64) + /// Float80 representation of the time. + @inlinable + public var float80Value: Float80 { + return Float80(self.nanoseconds) * 1.0E-9 + Float80(self.seconds) + } + #endif } extension TimeSpecification: CustomStringConvertible, CustomDebugStringConvertible { From 6d9ab30d315d1cffd51dfb7eeba00025758846a4 Mon Sep 17 00:00:00 2001 From: YOCKOW Date: Thu, 28 May 2020 14:40:05 +0900 Subject: [PATCH 2/2] Add type aliases of `TimeSpecification`. --- .../TimeSpecification/TimeSpecification.swift | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sources/TimeSpecification/TimeSpecification.swift b/Sources/TimeSpecification/TimeSpecification.swift index 4f43828..ef16893 100644 --- a/Sources/TimeSpecification/TimeSpecification.swift +++ b/Sources/TimeSpecification/TimeSpecification.swift @@ -112,6 +112,11 @@ extension TimeSpecification: ExpressibleByFloatLiteral { let double_seconds = floor(value) self.init(seconds: Int64(double_seconds), nanoseconds: Int32((value - double_seconds) * 1.0E+9)) } + + /// Creates an instance initialized to the specified floating-point value. + public init(_ value: F) where F: BinaryFloatingPoint { + self.init(floatLiteral: FloatLiteralType(value)) + } } extension TimeSpecification { @@ -218,6 +223,23 @@ extension TimeSpecification { } } +/// Type used to represent a specific point in time relative +/// to the absolute reference date of 1 Jan 2001 00:00:00 GMT. +public typealias NanosecondAbsoluteTime = TimeSpecification + +/// Type used to represent elapsed time in naoseconds. +public typealias NanosecondTimeInterval = TimeSpecification + +extension TimeSpecification { + /// The number of nanoseconds from 1 January 1970 to the reference date, 1 January 2001. + public static let timeIntervalBetween1970AndReferenceDate = NanosecondTimeInterval(Date.timeIntervalBetween1970AndReferenceDate) + + /// The interval between 00:00:00 UTC on 1 January 2001 and the current date and time. + public static var timeIntervalSinceReferenceDate: NanosecondAbsoluteTime { + return TimeSpecification(clock: .calendar) - TimeSpecification.timeIntervalBetween1970AndReferenceDate + } +} + extension TimeSpecification { /// Measure a processing time of the closure. ///