UTILLib 2.0
Common C++ library with utilities.
|
The time namespace is used for time and date functions. More...
Typedefs | |
using | SystemClock = std::chrono::system_clock |
Convenience type definition for std::chrono::system_clock;. | |
using | TimeStamp = std::chrono::time_point<SystemClock> |
Convenience type definition for std::chrono::time_point<std::chrono::system_time>;. |
Functions | |
std::string | GetLocalDateTime (TimeStamp timestamp=SystemClock::now()) |
Converts a timestamp (UTC) to a local date and time string in the YYYY-MM-DD hh:mm:ss format. | |
std::string | GetLocalTimestampWithMs (TimeStamp timestamp=SystemClock::now()) |
Converts a timestamp (UTC) to a local dat and time string in the YYYY-MM-DD hh:mm:ss.ms format. | |
std::string | GetLocalTimestampWithUs (TimeStamp timestamp=SystemClock::now()) |
Converts a UTC timestamp to a local date and time string in the YYYY-MM-DD hh:mm:ss.us. | |
std::string | NsToLocalIsoTime (uint64_t ns_since_1970) |
Converts a nanosecond since 1970 timestamp to a local ISO date and time string. | |
std::string | NsToIsoTime (uint64_t ns_since_1970, int format=0) |
Converts a nanosecond since 1970 timestamp to a UTC ISO date and time string. | |
uint64_t | IsoTimeToNs (const std::string &iso_time, bool local_time=false) |
Converts an ISO UTC string (YYYY-MM-DD(T)hh:mm:ss to nanosecond since 1970. | |
uint64_t | TimeStampToNs (TimeStamp timestamp=SystemClock::now()) |
Converts system clock to ns since midnight 1970. | |
std::string | NsToLocalDate (uint64_t ns_since_1970) |
Formats a date string according to the local date format. | |
std::string | NsToLocalTime (uint64_t ns_since_1970, int format=0) |
Formats a time string according to the local time format. | |
uint64_t | OdsDateToNs (const std::string &ods_date) |
Converts an ODS date and time string to nanoseconds since 1970. | |
uint64_t | FileTimeToNs (std::filesystem::file_time_type time) |
Converts from std::filesystem file_clock to ns since 1970. |
The time namespace is used for time and date functions.
uint64_t util::time::FileTimeToNs | ( | std::filesystem::file_time_type | time | ) |
Converts to a file time to nano-seconds since 1970. Note that this function actually hides a problem between MSC and GCC implementation.
time | Time point of a file clock |
std::string util::time::GetLocalDateTime | ( | TimeStamp | timestamp = SystemClock::now() | ) |
The function converts a chrono system clock timestamp to a common ISO type of local timestamp (YYYY-MM-DD hh:mm:ss). This is a common format in log files that should be read by users. Computers should always use UTC time zone.
[in] | timestamp | System clock timestamp (UTC) |
std::string util::time::GetLocalTimestampWithMs | ( | TimeStamp | timestamp = SystemClock::now() | ) |
The function converts a UTC system clock timestamp to a local date and time string including milliseconds. It uses the ISO related format YYYY-MM-DD hh:mm:ss.us. This format commonly used in log files.
[in] | timestamp | System clock timestamp (UTC) |
std::string util::time::GetLocalTimestampWithUs | ( | TimeStamp | timestamp = SystemClock::now() | ) |
The function converts a system clock timestamp (UTC) to a date and time string including microseconds. It uses the YYYY-MM-DD hh:mm:ss.us format.
[in] | timestamp | System clock timestamp (UTC) |
uint64_t util::time::IsoTimeToNs | ( | const std::string & | iso_time, |
bool | local_time = false ) |
Converts an ISO date and time string to nano-seconds since 1970. Note that the function also handle ODS date strings 'YYYYMMDDhhmmssxxxxxxxxxx strings. The date and string doesn't need to have more than years in the input string.
[in] | iso_time | Time stamp string YYYY-MM-DDThh:mm:ss.sssssssssZ |
[in] | local_time | Set to true if the ISO time uses local time. |
std::string util::time::NsToIsoTime | ( | uint64_t | ns_since_1970, |
int | format = 0 ) |
The function converts a nanoseconds since 1970 (Unix time) value to a ISO standard YYYY-MM-DDThh:mm:ss.xxxZ. It always converts to a UTC date and time string. The string can be used to stored the timestamp in both user and computer readable format. The user can define the resolution (format). The format is typical used in XML files and in databases that doesn't have date and time formats (SQLite).
[in] | ns_since_1970 | Nanosecond since 1970 |
[in] | format | 0: Include seconds, 1: Include ms, 2: include micro-seconds, 3: Include ns |
std::string util::time::NsToLocalDate | ( | uint64_t | ns_since_1970 | ) |
Formats a date string according to the local date format.
ns_since_1970 | Number of nanoseconds since 1970 |
std::string util::time::NsToLocalIsoTime | ( | uint64_t | ns_since_1970 | ) |
Converts a nanoseconds since 1970 timestamp (UTC) value. This is a so-called Unix timestamp. The nanosecond timestamp is typical used when computers deal with timestamps. Note that the milliseconds text may be missing in case there is no milliseconds (.000).
[in] | ns_since_1970 | Nanosecond since 1970-01-01. |
std::string util::time::NsToLocalTime | ( | uint64_t | ns_since_1970, |
int | format = 0 ) |
Formats a time string with optional ms..ns. The output format is according to the local time format.
ns_since_1970 | Number of nanoseconds since 1970 |
format | 0 = Show only seconds, 1 = Show ms, 2 = Show microseconds, 3 = Show ns |
uint64_t util::time::OdsDateToNs | ( | const std::string & | ods_date | ) |
Converts an ODS date and time string to nanoseconds since 1970. The ODS DT_DATE string have the format 'YYYYMMDDhhmmsslllcccnnn'. Note that the function also handle ISO time formats as 'YYYY-MM-DD hh:mm:ss(.*)'
ods_date | ODS date string |
uint64_t util::time::TimeStampToNs | ( | TimeStamp | timestamp = SystemClock::now() | ) |
timestamp | System clock time stamp |