#[repr(C)]pub struct TimeStamp {
pub mValue: u64,
}
Expand description
Instances of this class represent moments in time, or a special “null” moment. We do not use the non-monotonic system clock or local time, since they can be reset, causing apparent backward travel in time, which can confuse algorithms. Instead we measure elapsed time according to the system. This time can never go backwards (i.e. it never wraps around, at least not in less than five million years of system elapsed time). It might not advance while the system is sleeping. If TimeStamp::SetNow() is not called at all for hours or days, we might not notice the passage of some of that time.
We deliberately do not expose a way to convert TimeStamps to some particular unit. All you can do is compute a difference between two TimeStamps to get a TimeDuration. You can also add a TimeDuration to a TimeStamp to get a new TimeStamp. You can’t do something meaningless like add two TimeStamps.
Internally this is implemented as either a wrapper around
- high-resolution, monotonic, system clocks if they exist on this platform
- PRIntervalTime otherwise. We detect wraparounds of PRIntervalTime and work around them.
This class is similar to C++11’s time_point, however it is explicitly nullable and provides an IsNull() method. time_point is initialized to the clock’s epoch and provides a time_since_epoch() method that functions similiarly. i.e. t.IsNull() is equivalent to t.time_since_epoch() == decltype(t)::duration::zero();
Note that, since TimeStamp objects are small, prefer to pass them by value unless there is a specific reason not to do so.
Fields§
§mValue: u64
When built with PRIntervalTime, a value of 0 means this instance is “null”. Otherwise, the low 32 bits represent a PRIntervalTime, and the high 32 bits represent a counter of the number of rollovers of PRIntervalTime that we’ve seen. This counter starts at 1 to avoid a real time colliding with the “null” value.
PR_INTERVAL_MAX is set at 100,000 ticks per second. So the minimum time to wrap around is about 2^64/100000 seconds, i.e. about 5,849,424 years.
When using a system clock, a value is system dependent.