Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
Time Utilities

Utility functions for working with timestamps and time components. More...

Functions

const struct timespec time_shield::get_timespec_impl () noexcept
 Get the current timespec.
 
int64_t time_shield::now_realtime_us ()
 Get current real time in microseconds using a hybrid method.
 
template<class T = int>
const T time_shield::ns_of_sec () noexcept
 Get the nanosecond part of the current second.
 
template<class T = int>
const T time_shield::us_of_sec () noexcept
 Get the microsecond part of the current second.
 
template<class T = int>
const T time_shield::ms_of_sec () noexcept
 Get the millisecond part of the current second.
 
const ts_t time_shield::timestamp () noexcept
 Get the current UTC timestamp in seconds.
 
const fts_t time_shield::fts () noexcept
 Get the current UTC timestamp in floating-point seconds.
 
const fts_t time_shield::ftimestamp () noexcept
 Get the current UTC timestamp in floating-point seconds.
 
const ts_ms_t time_shield::ts_ms () noexcept
 Get the current UTC timestamp in milliseconds.
 
const ts_ms_t time_shield::timestamp_ms () noexcept
 Get the current UTC timestamp in milliseconds.
 
const ts_ms_t time_shield::now () noexcept
 Get the current UTC timestamp in milliseconds.
 
const ts_us_t time_shield::ts_us () noexcept
 Get the current UTC timestamp in microseconds.
 
const ts_us_t time_shield::timestamp_us () noexcept
 Get the current UTC timestamp in microseconds.
 
double time_shield::get_cpu_time () noexcept
 Get the CPU time used by the current process.
 
long time_shield::microseconds ()
 Get the number of microseconds since the UNIX epoch.
 
long time_shield::ns_of_sec ()
 Get the nanosecond part of the current second.
 
int time_shield::us_of_sec ()
 Get the microsecond part of the current second.
 
int time_shield::ms_of_sec ()
 Get the millisecond part of the current second.
 
const ts_t time_shield::ts () noexcept
 Get the current UTC timestamp in seconds.
 

Detailed Description

Utility functions for working with timestamps and time components.

A collection of utility functions for working with timestamps and time components.

This module provides functions for obtaining the current timestamps in various formats (e.g., seconds, milliseconds, microseconds, floating-point seconds) and extracting sub-second components such as nanoseconds, microseconds, and milliseconds.

Key Features:

Usage Examples:

Function Documentation

◆ ftimestamp()

double time_shield::ftimestamp ( )
inlinenoexcept

Get the current UTC timestamp in floating-point seconds.

Alias for fts().

Returns
fts_t Current UTC timestamp in floating-point seconds.

Get the current UTC timestamp in floating-point seconds.

Returns
fts_t Current UTC timestamp in floating-point seconds.
Current UTC timestamp in floating-point seconds.

Definition at line 147 of file time_utils.hpp.

◆ fts()

double time_shield::fts ( )
inlinenoexcept

Get the current UTC timestamp in floating-point seconds.

Returns
fts_t Current UTC timestamp in floating-point seconds.
Current UTC timestamp in floating-point seconds.

Definition at line 139 of file time_utils.hpp.

◆ get_cpu_time()

double time_shield::get_cpu_time ( )
inlinenoexcept

Get the CPU time used by the current process.

Returns
CPU time in seconds, or NaN if not available.
Note
This function attempts multiple fallback methods depending on platform capabilities.
See also
https://habr.com/ru/articles/282301/ — original implementation idea

Definition at line 197 of file time_utils.hpp.

◆ get_timespec_impl()

const struct timespec time_shield::get_timespec_impl ( )
inlinenoexcept

Get the current timespec.

Returns
struct timespec The current timespec.

Definition at line 35 of file time_utils.hpp.

◆ microseconds()

long time_shield::microseconds ( )

Get the number of microseconds since the UNIX epoch.

Returns
Microseconds since 1 January 1970.

Definition at line 32 of file time_utils.mqh.

◆ ms_of_sec() [1/2]

int time_shield::ms_of_sec ( )

Get the millisecond part of the current second.

Returns
Millisecond part of the current second.

Definition at line 63 of file time_utils.mqh.

◆ ms_of_sec() [2/2]

template<class T = int>
const T time_shield::ms_of_sec ( )
noexcept

Get the millisecond part of the current second.

Template Parameters
TType of the returned value (default is int).
Returns
T Millisecond part of the current second.

Definition at line 116 of file time_utils.hpp.

◆ now()

long time_shield::now ( )
inlinenoexcept

Get the current UTC timestamp in milliseconds.

Alias for ts_ms().

Returns
ts_ms_t Current UTC timestamp in milliseconds.

Get the current UTC timestamp in milliseconds.

Returns
ts_ms_t Current UTC timestamp in milliseconds.
Current UTC timestamp in milliseconds.

Definition at line 171 of file time_utils.hpp.

◆ now_realtime_us()

int64_t time_shield::now_realtime_us ( )
inline

Get current real time in microseconds using a hybrid method.

This function combines QueryPerformanceCounter (high-resolution monotonic clock) with GetSystemTimeAsFileTime to compute an accurate, stable UTC timestamp. The base time is initialized only once per process (lazy init).

Returns
Current UTC timestamp in microseconds.
Note
Windows only. Not available on Unix-like systems.

Definition at line 55 of file time_utils.hpp.

◆ ns_of_sec() [1/2]

long time_shield::ns_of_sec ( )

Get the nanosecond part of the current second.

Returns
Nanosecond part of the current second.

Definition at line 51 of file time_utils.mqh.

◆ ns_of_sec() [2/2]

template<class T = int>
const T time_shield::ns_of_sec ( )
inlinenoexcept

Get the nanosecond part of the current second.

Template Parameters
TType of the returned value (default is int).
Returns
T Nanosecond part of the current second.

Definition at line 96 of file time_utils.hpp.

◆ timestamp()

long time_shield::timestamp ( )
inlinenoexcept

Get the current UTC timestamp in seconds.

Alias for ts().

Returns
ts_t Current UTC timestamp in seconds.

Get the current UTC timestamp in seconds.

Returns
ts_t Current UTC timestamp in seconds.
Current UTC timestamp in seconds.

Definition at line 131 of file time_utils.hpp.

◆ timestamp_ms()

long time_shield::timestamp_ms ( )
inlinenoexcept

Get the current UTC timestamp in milliseconds.

Alias for ts_ms().

Returns
ts_ms_t Current UTC timestamp in milliseconds.

Get the current UTC timestamp in milliseconds.

Returns
ts_ms_t Current UTC timestamp in milliseconds.
Current UTC timestamp in milliseconds.

Definition at line 163 of file time_utils.hpp.

◆ timestamp_us()

long time_shield::timestamp_us ( )
inlinenoexcept

Get the current UTC timestamp in microseconds.

Alias for ts_us().

Returns
ts_us_t Current UTC timestamp in microseconds.

Get the current UTC timestamp in microseconds.

Returns
ts_us_t Current UTC timestamp in microseconds.
Current UTC timestamp in microseconds.

Definition at line 187 of file time_utils.hpp.

◆ ts()

long time_shield::ts ( )
inlinenoexcept

Get the current UTC timestamp in seconds.

Returns
ts_t Current UTC timestamp in seconds.
Current UTC timestamp in seconds.

Definition at line 123 of file time_utils.hpp.

◆ ts_ms()

long time_shield::ts_ms ( )
inlinenoexcept

Get the current UTC timestamp in milliseconds.

Returns
ts_ms_t Current UTC timestamp in milliseconds.
Current UTC timestamp in milliseconds.

Definition at line 155 of file time_utils.hpp.

◆ ts_us()

long time_shield::ts_us ( )
inlinenoexcept

Get the current UTC timestamp in microseconds.

Returns
ts_us_t Current UTC timestamp in microseconds.
Current UTC timestamp in microseconds.

Definition at line 179 of file time_utils.hpp.

◆ us_of_sec() [1/2]

int time_shield::us_of_sec ( )

Get the microsecond part of the current second.

Returns
Microsecond part of the current second.

Definition at line 57 of file time_utils.mqh.

◆ us_of_sec() [2/2]

template<class T = int>
const T time_shield::us_of_sec ( )
noexcept

Get the microsecond part of the current second.

Template Parameters
TType of the returned value (default is int).
Returns
T Microsecond part of the current second.

Definition at line 106 of file time_utils.hpp.