Simple high resolution time stamps for swift developers, along with helpful tools to work with them.
Install via the Swift Package Manger by declaring Nanoseconds as a dependency in your
.package(url: "https://github.com/dominicegginton/Nanoseconds", from: "1.0.0")
Remember to add Nanoseconds to your target as a dependency.
Creating high resolution timestamps with nanosecond accuracy is easy, simply create a instant of
let foo = Now()
Use the built-in operators overloads to easily calculate and initialize TimeInterval:
let start = Now() sleep(1) let end = Now() let duration = end - start print(duration) //=> 1004222113.0
To convert TimeInterval objects from nanosecond to a different unit simply use a provided extension:
print(duration.milliseconds) //=> 1004.22211 print(duration.seconds) //=> 1.004222113
Use a provided init method to create a TimeInterval object from any time unit
let duration = TimeInterval(seconds: 8)
Use the provided
timeString variable to convert TimeInterval objects into a human readable format:
let duration = TimeInterval(hours: 1) + TimeInterval(seconds: 120) print(duration.timeString) //=> 1h 1m 30s
|Last commit: 1 week ago|