[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-ios] 20/29: RelativeTime
From: |
gnunet |
Subject: |
[taler-taler-ios] 20/29: RelativeTime |
Date: |
Tue, 28 May 2024 09:06:03 +0200 |
This is an automated email from the git hooks/post-receive script.
marc-stibane pushed a commit to branch master
in repository taler-ios.
commit 10f6373f868ad25be573090bfa5c695099c25039
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri May 24 08:11:38 2024 +0200
RelativeTime
---
taler-swift/Sources/taler-swift/Time.swift | 45 ++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/taler-swift/Sources/taler-swift/Time.swift
b/taler-swift/Sources/taler-swift/Time.swift
index 98f0e27..084ad09 100644
--- a/taler-swift/Sources/taler-swift/Time.swift
+++ b/taler-swift/Sources/taler-swift/Time.swift
@@ -16,6 +16,51 @@ enum TimestampError: Error {
case invalidUInt64Value
}
+public enum RelativeTime: Codable, Hashable, Sendable {
+ // Duration in microseconds or "forever"
+ // to represent an infinite duration. Numeric
+ // values are capped at 2^53 - 1 inclusive.
+ case microseconds(UInt64)
+ case forever
+
+ enum CodingKeys: String, CodingKey {
+ case d_us = "d_us"
+ }
+
+ public init(from decoder: Decoder) throws {
+ let container = try decoder.container(keyedBy: CodingKeys.self)
+ do {
+ self = RelativeTime.microseconds(try container.decode(UInt64.self,
forKey: .d_us))
+ } catch { // rethrows or never
+ let stringValue = try container.decode(String.self, forKey: .d_us)
+ if stringValue == "forever" {
+ self = RelativeTime.forever
+ } else {
+ throw TimestampError.invalidStringRepresentation
+ }
+ }
+ }
+ public func hash(into hasher: inout Hasher) {
+ switch self {
+ case .microseconds(let d_us):
+ hasher.combine(d_us)
+ case .forever:
+ hasher.combine("forever")
+ }
+ }
+ public func encode(to encoder: Encoder) throws {
+ var value = encoder.container(keyedBy: CodingKeys.self)
+ switch self {
+ case .microseconds(let d_us):
+ try value.encode(d_us, forKey: .d_us)
+ case .forever:
+ try value.encode("forever", forKey: .d_us)
+ }
+ }
+}
+
+
+
/// A point in time, represented by milliseconds from January 1, 1970..
public enum Timestamp: Codable, Hashable, Sendable {
case milliseconds(UInt64)
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-taler-ios] 18/29: don't announce debugView, (continued)
- [taler-taler-ios] 18/29: don't announce debugView, gnunet, 2024/05/28
- [taler-taler-ios] 21/29: Localization hints, gnunet, 2024/05/28
- [taler-taler-ios] 09/29: debugging, gnunet, 2024/05/28
- [taler-taler-ios] 11/29: cleanup, gnunet, 2024/05/28
- [taler-taler-ios] 25/29: checkPayForTemplate, gnunet, 2024/05/28
- [taler-taler-ios] 22/29: localizedState, gnunet, 2024/05/28
- [taler-taler-ios] 27/29: Spanish localization, gnunet, 2024/05/28
- [taler-taler-ios] 17/29: make announce() passable in closures, gnunet, 2024/05/28
- [taler-taler-ios] 12/29: Bump version to 0.10.3 (0.10.8), gnunet, 2024/05/28
- [taler-taler-ios] 08/29: canonical, gnunet, 2024/05/28
- [taler-taler-ios] 20/29: RelativeTime,
gnunet <=
- [taler-taler-ios] 16/29: Networking: hintNetworkAvailability(), gnunet, 2024/05/28
- [taler-taler-ios] 28/29: prepare bankIntegrated without amount, gnunet, 2024/05/28