Azure C++ Utils 1.5.2+3
Azure REST API Helpers for Modern C++
siddiqsoft::DateUtils Struct Reference

Date Time utilities for REST API. More...

#include <date-utils.hpp>

Static Public Member Functions

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > ISO8601 (const std::chrono::system_clock::time_point &rawtp=std::chrono::system_clock::now())
 Converts the argument to ISO8601 format. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > RFC7231 (const std::chrono::system_clock::time_point &rawtp=std::chrono::system_clock::now())
 Build a time and date string compliant with the RFC7231. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > toTimespan (const std::chrono::seconds &arg)
 Returns D.HH:MM:SS ; days.hours:minutes:seconds. More...
 
template<class T = std::string>
requires std::same_as<T, std::string> || std::same_as<T, std::wstring> || std::same_as<T, uint64_t>
static std::chrono::system_clock::time_point parseEpoch (const T &arg)
 Converts the epoch time into a time_point. The reason for string is due to the permissibility of epoch with decimals where the portion after the decimal represents milliseconds. More...
 
template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::tuple< std::chrono::milliseconds, std::basic_string< T > > diff (const std::chrono::time_point< std::chrono::system_clock > &end, const std::chrono::time_point< std::chrono::system_clock > &start)
 Returns a tuple where the first is the chrono::duration<Z> and the second is std::basic_string<T> as. More...
 
template<typename T = char, typename D = std::chrono::microseconds>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > durationString (const D &arg)
 Return string with weeks days hours minutes seconds for the provided duration (default microseconds) More...
 
template<class T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::chrono::system_clock::time_point parseISO8601 (const std::basic_string< T > &arg)
 Converts from ISO8601 format string into time_point. More...
 

Detailed Description

Date Time utilities for REST API.

Definition at line 69 of file date-utils.hpp.

Member Function Documentation

◆ diff()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::tuple< std::chrono::milliseconds, std::basic_string< T > > siddiqsoft::DateUtils::diff ( const std::chrono::time_point< std::chrono::system_clock > &  end,
const std::chrono::time_point< std::chrono::system_clock > &  start 
)
inlinestatic

Returns a tuple where the first is the chrono::duration<Z> and the second is std::basic_string<T> as.

Template Parameters
TOutput type (char or wchar_t)
Parameters
endtime_point of end
starttime_point of start
Returns
Returns a tuple where the first is the chrono::duration<Z> and the second is std::basic_string<T> as "HH:MM:SS.mmm"

Definition at line 236 of file date-utils.hpp.

◆ durationString()

template<typename T = char, typename D = std::chrono::microseconds>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::DateUtils::durationString ( const D &  arg)
inlinestatic

Return string with weeks days hours minutes seconds for the provided duration (default microseconds)

Parameters
argExpressed as uint64_t so we can relay any resolution: us, ms, ns, s..
Returns
string years/months/weeks days and hour minute second and millis The years/months are in "parallel" to the weeks days hours minutes seconds The seconds is rounded up if we end up with 500ms after the split years / months / weeks days hours minutes seconds months / weeks days hours minutes seconds weeks days hours minutes seconds days hours minutes seconds hours minutes seconds minutes seconds minutes seconds milliseconds

Definition at line 279 of file date-utils.hpp.

◆ ISO8601()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::DateUtils::ISO8601 ( const std::chrono::system_clock::time_point &  rawtp = std::chrono::system_clock::now())
inlinestatic

Converts the argument to ISO8601 format.

Template Parameters
TMust be string or wstring
Parameters
rawtptime_point representing the time. Defaults to "now"
Returns
String representing ISO 8601 format with milliseconds empty if fails
See also
The specification https://en.wikipedia.org/wiki/ISO_8601

Definition at line 78 of file date-utils.hpp.

◆ parseEpoch()

template<class T = std::string>
requires std::same_as<T, std::string> || std::same_as<T, std::wstring> || std::same_as<T, uint64_t>
static std::chrono::system_clock::time_point siddiqsoft::DateUtils::parseEpoch ( const T &  arg)
inlinestatic

Converts the epoch time into a time_point. The reason for string is due to the permissibility of epoch with decimals where the portion after the decimal represents milliseconds.

Template Parameters
TMust be either std::string or std::wstring or as uint64_t
Parameters
argA string or wstring
Returns
time_point

Definition at line 177 of file date-utils.hpp.

◆ parseISO8601()

template<class T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::chrono::system_clock::time_point siddiqsoft::DateUtils::parseISO8601 ( const std::basic_string< T > &  arg)
inlinestatic

Converts from ISO8601 format string into time_point.

Template Parameters
TOne of the following: std::string, std::string_view, std::wstring or std::wstring_view
Parameters
argstring containing the ISO8601 format time
Returns
time_point

Definition at line 345 of file date-utils.hpp.

◆ RFC7231()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::DateUtils::RFC7231 ( const std::chrono::system_clock::time_point &  rawtp = std::chrono::system_clock::now())
inlinestatic

Build a time and date string compliant with the RFC7231.

Template Parameters
TMust be either std::string or std::wstring
Parameters
rawtpOptional. Uses current time if not provided
Returns
Returns a string representation of the form: "Tue, 01 Nov 1994 08:12:31 GMT"

Definition at line 112 of file date-utils.hpp.

◆ toTimespan()

template<typename T = char>
requires std::same_as<T, char> || std::same_as<T, wchar_t>
static std::basic_string< T > siddiqsoft::DateUtils::toTimespan ( const std::chrono::seconds &  arg)
inlinestatic

Returns D.HH:MM:SS ; days.hours:minutes:seconds.

Template Parameters
TMust be either std::string or std::wstring
Parameters
argNumber of seconds
Returns
Returns a string representation of the form: "days.hours:minutes:seconds"

Definition at line 145 of file date-utils.hpp.


The documentation for this struct was generated from the following file: