-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Foundation | ||
|
||
public protocol TimeProvider: Sendable { | ||
func getTime() -> UInt32 | ||
} | ||
|
||
public struct SystemTimeProvider: TimeProvider { | ||
public init() {} | ||
|
||
public func getTime() -> UInt32 { | ||
Date().timeIntervalSinceJamCommonEra | ||
} | ||
} | ||
|
||
public struct FixedTimeProvider: TimeProvider { | ||
private let time: UInt32 | ||
|
||
public init(time: UInt32) { | ||
self.time = time | ||
} | ||
|
||
public func getTime() -> UInt32 { | ||
time | ||
} | ||
} | ||
|
||
extension Date { | ||
public var timeIntervalSinceJamCommonEra: UInt32 { | ||
// the Jam Common Era: 1200 UTC on January 1, 2024 | ||
// number of seconds since the Unix epoch | ||
let beginning = 1_704_110_400.0 | ||
let now = timeIntervalSince1970 | ||
return UInt32(now - beginning) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters