Skip to content

Commit

Permalink
Clean up NetTime
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed May 22, 2024
1 parent 4236c92 commit ce6ad10
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Sources/NetTime/Date+NetTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Logger
/**
* - Description: class which will provide the best estimate of the difference in time between the device's system clock and the time returned by a collection of time servers
* - Note: This class has Unit-tests
* - Fixme: ⚠️️ If you want to sync your time to a specific server (e.g. your API server).
* - Fixme: ⚠️️ If for some reason the Date format your HTTP Server returns is different than the one specified.
* - Fixme: ⚠️️ If you want to sync your time to a specific server (e.g. your API server)
* - Fixme: ⚠️️ If for some reason the Date format your HTTP Server returns is different than the one specified
* ## Examples:
* Date.updateTime { // Call when app launches etc
* print("☀️ Current Date: \(Date().formatted())")
Expand All @@ -30,7 +30,7 @@ extension Date {
* - Remark: Set this at the first opertunity when using the app
* - Remark: Call this on background queue
* - Remark: If this is not called e use system time
* - Fixme: ⚠️️ Add error to `onComplete` closure, use Result maybe? 👈
* - Fixme: ⚠️️ Add error to `onComplete` closure, use Result maybe? 👈 This way we can log the error in the caller etc
* - Parameter onComplete: Callback when server has responded
*/
public static func updateTime(onComplete: @escaping OnComplete = defaultOnComplete) {
Expand Down
7 changes: 5 additions & 2 deletions Tests/NetTimeTests/util/Date+TimeZone.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Foundation
// Fix: im not sure we use this anymore as we jsut use UTC, maybe move to a gist?
/**
* - Fixme: ⚠️️ I'm not sure we use this anymore as we just use UTC, maybe move to a gist?
* - Fixme: ⚠️️ I guess we convert back to the users timezone in the presentation layer, so maybe keep around?
*/
extension TimeZone {
/**
* The Central European Time (CET) time zone.
Expand Down Expand Up @@ -55,7 +58,7 @@ extension Date {
return self.convert(from: TimeZone.current, to: timeZone) // Convert date from current time zone to specified time zone
}
/**
* Converts the date from one time zone to another.
* Converts the date from one time zone to another
* - Parameters:
* - timeZone: The time zone of the original date.
* - destinationTimeZone: The time zone to convert the date to.
Expand Down
3 changes: 1 addition & 2 deletions Tests/NetTimeTests/util/Reachability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ internal class Reachability {
* - Note: The reason why we do async: https://stackoverflow.com/a/40764725/5389500
* - Parameters:
* - completionHandler: The closure to call with the result of the network check.
*
* ## Example:
* Self.checkNetwork { Swift.print("Net: \($0)") }
* - Fixme: ⚠️️ Add result? to print error etc? or just throw error?
* - Fixme: ⚠️️ Add semaphore with timeout as well, or add timeout some other way?
* - Fixme: ⚠️️ Add semaphore with timeout as well, or add timeout some other way? Check with copilots
*/
internal static func checkNetwork(completionHandler: @escaping (_ internet: Bool) -> Void) {
guard let url: URL = .init(string: "https://www.google.com/") else { completionHandler(false); return; } // Create a URL object for Google's homepage
Expand Down
6 changes: 3 additions & 3 deletions Tests/NetTimeTests/util/TimeMeasure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal final class TimeMeasure {
internal typealias Operation = () throws -> Void
/**
* Measures how long a closure takes to complete
* - Note: Great for UnitTesting
* - Note: it's also possible to use. let startTime = CFAbsoluteTimeGetCurrent(); CFAbsoluteTimeGetCurrent() - startTime
* fix: add param comment
* - Note: This method is great for UnitTesting
* - Note: it's also possible to use. `let startTime = CFAbsoluteTimeGetCurrent(); CFAbsoluteTimeGetCurrent() - startTime`
* - Fixme: ⚠️️ Add param comment
* ## Examples:
* print("\(timeElapsed { sleep(2.2) })") // 2.20000
*/
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTIN
## License

NetTime is released under the MIT License. See [LICENSE](LICENSE) for details.

## Todo:
- Do more exploration into side-effects
- Comb the competitors for ways to improve

0 comments on commit ce6ad10

Please sign in to comment.