As explained in detail in the documentation of module ALib Time, a steady time model is supported with class Ticks and a non-steady one representing the system clock with class DateTime. Only values of the latter type can be converted to human-readable (calendar) date and time values.
In some situations however, a software that requires steady, monotonic time points, may also be required to present these time points in human-readable format. It is of course possible to do some sort of conversion. For that, simply both clocks need to be probed at the same point in time and then time points of both notions can be put in relation to these two probes.
The effect however is that the conversion results will change for all values as soon as the system clock is changed and the probe values of the two clocks are updated. This is true also for values that are "older" than the point in time that the clock change happened. The reason is quickly understood: The system clock's counter changes, while the steady clock's counter does not.
To give the user of ALib full control about how system clock changes are reflected, the conversion of time points is encapsulated by this class together with one pair of clock probe data. A software can use one ore more instances of this class and update (synchronize) these instances independently.
Definition at line 38 of file tickconverter.hpp.
#include <tickconverter.hpp>
Public Method Index: | |
TickConverter () | |
Constructor. Invokes SyncClocks. | |
void | SetAs (const TickConverter &other) |
ALIB_API void | SyncClocks (int qtyRepeats=5) |
DateTime | ToDateTime (Ticks ticks) |
Ticks | ToTicks (DateTime dateTime) |
Protected Field Index: | |
Ticks::TTimePoint | steadyClockSyncTime |
Time point of steady clock of last invocation of SyncClocks. | |
DateTime::TTimePoint | systemClockSyncTime |
Time point of system clock of last invocation of SyncClocks. | |
|
protected |
Time point of steady clock of last invocation of SyncClocks.
Definition at line 42 of file tickconverter.hpp.
|
protected |
Time point of system clock of last invocation of SyncClocks.
Definition at line 45 of file tickconverter.hpp.
|
inline |
Constructor. Invokes SyncClocks.
Definition at line 51 of file tickconverter.hpp.
|
inline |
Sets the pair of conversion times to equal the other converter object. This is useful to avoid differences in conversion across converter instances used in a software.
other | Another converter object to copy the synchronization information from. |
Definition at line 86 of file tickconverter.hpp.
void SyncClocks | ( | int | qtyRepeats = 5 | ) |
Generates a set of "probes" of the steady, monotonic clock and the system clock. The measurement of both clocks is repeated the given number of times and the pair with the smallest difference between both is chosen. This approach mitigates the risk of using a pair for which thread execution had been interrupted during the two measurements.
Note that after a call to this method, the conversion methods may return slightly different values than before the call, even if the system clock was not changed.
If this method is not invoked after a change of the system clock, such change of the system clock is not reflected by the conversion methods. In other words, the conversion methods always work just as if the system clock had not changed since the last invocation of this method.
qtyRepeats | The number of measurements to perform. Defaults to 5 . |
Converts a Ticks object to a DateTime object.
ticks | The ticks object to convert. |
Definition at line 97 of file tickconverter.hpp.
Converts a DateTime object to a Ticks object.
dateTime | The date/time object to convert. |
Definition at line 109 of file tickconverter.hpp.