commit e765ec56c4d77e8167313c37938095971e3066ef
parent dac14b7dbbc3abe6f975192b05e7661c6f8058eb
Author: Marc Stibane <marc@taler.net>
Date: Fri, 2 Aug 2024 17:31:01 +0200
Convenience, cleanup
Diffstat:
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/taler-swift/Sources/taler-swift/Time.swift b/taler-swift/Sources/taler-swift/Time.swift
@@ -59,8 +59,17 @@ public enum RelativeTime: Codable, Hashable, Sendable {
}
}
-
-
+extension RelativeTime {
+ public func microseconds() throws -> UInt64 {
+ switch self {
+ case .microseconds(let d_us):
+ return d_us
+ case .forever:
+ throw TimestampError.invalidUInt64Value
+ }
+ }
+}
+// MARK: -
/// A point in time, represented by milliseconds from January 1, 1970..
public enum Timestamp: Codable, Hashable, Sendable {
case milliseconds(UInt64)
@@ -129,7 +138,6 @@ extension Timestamp {
return Timestamp.milliseconds(now + (UInt64(minutes) * seconds * 1000))
}
-
/// convenience initializer from UInt64 (milliseconds from January 1, 1970)
public init(from: UInt64) {
self = Timestamp.milliseconds(from)
@@ -145,7 +153,7 @@ extension Timestamp {
}
}
}
-
+// MARK: -
/// extend iOS Date to work with milliseconds since 1970
extension Date {
public var millisecondsSince1970: UInt64 {
@@ -156,7 +164,7 @@ extension Date {
self = Date(timeIntervalSince1970: TimeInterval(milliseconds) / 1000)
}
}
-
+// MARK: -
/// A duration of time, measured in milliseconds.
public enum Duration: Equatable {
case milliseconds(UInt64)