15 DateTimeOffset GetUtcNow()
const override {
19 GetSystemTimePreciseAsFileTime(&ft);
20 int64_t ticks = (((int64_t)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
25 auto now = std::chrono::system_clock::now();
26 auto duration = now.time_since_epoch();
27 auto ticks = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count() / 100;
34 DateTimeOffset GetLocalNow()
const override {
40 SystemTimeToFileTime(&st, &ft);
41 int64_t ticks = (((int64_t)ft.dwHighDateTime) << 32) | ft.dwLowDateTime;
49 int64_t GetTimestamp()
const override {
53 QueryPerformanceCounter(&li);
56 auto now = std::chrono::steady_clock::now();
57 return std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch()).count();
61 int64_t GetTimestampFrequency()
const override {
65 QueryPerformanceFrequency(&li);
Provides an abstraction for time, timestamps, and elapsed time calculation.
DateTimeOffset()
Initializes a new instance of DateTimeOffset to 0 ticks.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
An abstraction that provides time-related functions to enable testability of time-dependent code.
TimeSpan GetElapsedTime(int64_t startingTimestamp) const
Gets the elapsed time since the startingTimestamp was recorded.
static TimeProviderPtr GetSystem()
Gets a TimeProvider that provides the system's current time and high-resolution timer.
virtual int64_t GetTimestampFrequency() const =0
Gets the frequency of the high-frequency counter in ticks per second.
virtual int64_t GetTimestamp() const =0
Gets the current high-frequency counter value in ticks.
Represents a time interval (duration of time or elapsed time) measured as a positive or negative numb...
static constexpr int64_t TicksPerSecond
The number of ticks in 1 second.
TimeSpan()
Initializes a new instance of TimeSpan to zero duration.
SmartPointer< TimeProvider > TimeProviderPtr
Alias for a smart pointer to a TimeProvider.
SmartPointer< To > DynamicCast(const SmartPointer< From > &sp)