A small utility to handle timestamps and intervals.
Create some time
let now = Time.Now
Get the system timestamp value. This is the mach_absolute_time
on macOS and the result of clock_gettime
using CLOCK_MONOTONIC_RAW
, in nano seconds.
let ts = now.systemTimeStamp
Create some time with a system time stamp value
_ = Time.FromSystemTimeStamp(ts)
Add a second
let aSecondFromNow = now + Time.FromInterval(1, unit: .Seconds)
Subtract some micros
_ = aSecondFromNow - Time.FromInterval(1234, unit: .Microseconds)
Compare
_ = aSecondFromNow == now
_ = aSecondFromNow != now
Make a second
aSecond = aSecondFromNow - now