Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Sources/AWSLambdaRuntime/LambdaClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions Tests/AWSLambdaRuntimeTests/LambdaClockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}