diff --git a/Sources/AWSLambdaRuntime/LambdaClock.swift b/Sources/AWSLambdaRuntime/LambdaClock.swift index 6f3df393..53b641cc 100644 --- a/Sources/AWSLambdaRuntime/LambdaClock.swift +++ b/Sources/AWSLambdaRuntime/LambdaClock.swift @@ -62,7 +62,7 @@ public struct LambdaClock: Clock { /// ## Thread Safety /// /// `Instant` is a value type and is inherently thread-safe. - public struct Instant: InstantProtocol { + public struct Instant: InstantProtocol, CustomStringConvertible { /// The number of milliseconds since the Unix epoch. let instant: Int64 @@ -122,6 +122,11 @@ public struct LambdaClock: Clock { public init(millisecondsSinceEpoch milliseconds: Int64) { self.instant = milliseconds } + + /// Renders an Instant as an EPOCH value + public var description: String { + "\(self.instant)" + } } /// The current instant according to this clock. diff --git a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift index 413a3aa2..b1d6f974 100644 --- a/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift +++ b/Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift @@ -136,4 +136,19 @@ struct LambdaClockTests { "LambdaClock and Foundation Date should be within 10ms of each other, difference was \(difference)ms" ) } + @Test("Instant renders as string with an epoch number") + func instantRendersAsStringWithEpochNumber() { + let clock = LambdaClock() + let instant = clock.now + + let expectedString = "\(instant)" + #expect(expectedString.allSatisfy { $0.isNumber }, "String should only contain numbers") + + if let expectedNumber = Int64(expectedString) { + let newInstant = LambdaClock.Instant(millisecondsSinceEpoch: expectedNumber) + #expect(instant == newInstant, "Instant should match the expected number") + } else { + Issue.record("expectedString is not a number") + } + } }