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

A comprehensive set of functions for converting timestamps to formatted strings. More...

Functions

void time_shield::process_format_impl (char last_char, size_t repeat_count, ts_t ts, tz_t utc_offset, const DateTimeStruct &dt, std::string &result)
 
template<class T = ts_t>
const std::string time_shield::to_string (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Convert timestamp to string with custom format.
 
template<class T = ts_t>
const std::string time_shield::to_str (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Alias for to_string function.
 
template<class T = ts_ms_t>
const std::string time_shield::to_string_ms (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Convert timestamp in milliseconds to string with custom format.
 
template<class T = ts_t>
const std::string time_shield::to_str_ms (const std::string &format_str, T timestamp, tz_t utc_offset=0)
 Alias for to_string function.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601 (T ts)
 Converts a timestamp to an ISO8601 string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_date (T ts)
 Converts a timestamp to an ISO8601 date string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_time (T ts)
 Converts a timestamp to an ISO8601 time string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_time_utc (T ts)
 Converts a timestamp to an ISO8601 UTC time string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601_utc (T ts)
 Converts a timestamp to an ISO8601 string in UTC format.
 
const std::string time_shield::to_iso8601_utc_ms (ts_ms_t ts_ms)
 Converts a timestamp in milliseconds to an ISO8601 string in UTC format.
 
const std::string time_shield::to_iso8601_ms (ts_ms_t ts_ms)
 Converts a timestamp in milliseconds to an ISO8601 string.
 
template<class T = ts_t>
const std::string time_shield::to_iso8601 (T ts, tz_t utc_offset)
 Converts a timestamp to an ISO8601 string with timezone offset.
 
const std::string time_shield::to_iso8601_ms (ts_ms_t ts_ms, tz_t utc_offset)
 Converts a timestamp in milliseconds to an ISO8601 string with timezone offset.
 
const std::string time_shield::to_mql5_date_time (ts_t ts)
 Converts a timestamp to a string in MQL5 date and time format.
 
const std::string time_shield::to_mql5_full (ts_t ts)
 Alias for to_mql5_date_time_str function.
 
const std::string time_shield::to_mql5_date (ts_t ts)
 Converts a timestamp to a string in MQL5 date format.
 
const std::string time_shield::to_mql5_time (ts_t ts)
 Converts a timestamp to a string in MQL5 time format.
 
const std::string time_shield::to_windows_filename (ts_t ts)
 Converts a timestamp in seconds to a Windows-compatible filename format.
 
const std::string time_shield::to_windows_filename_ms (ts_ms_t ts)
 Converts a timestamp in milliseconds to a Windows-compatible filename format.
 
std::string time_shield::to_human_readable (ts_t ts)
 Converts a timestamp in seconds to a human-readable format.
 
std::string time_shield::to_human_readable_ms (ts_ms_t ts)
 Converts a timestamp in milliseconds to a human-readable format.
 
const std::string time_shield::time_zone_struct_to_string (const TimeZoneStruct &tz)
 Converts a TimeZoneStruct to a string representation.
 
const std::string time_shield::to_string (const TimeZoneStruct &tz)
 Alias for time_zone_struct_to_string function.
 
const std::string time_shield::to_str (const TimeZoneStruct &tz)
 Alias for time_zone_struct_to_string function.
 

Detailed Description

A comprehensive set of functions for converting timestamps to formatted strings.

This module provides utilities for formatting timestamps into human-readable strings, custom formats, ISO8601, and other standardized formats.

Key Features:

Usage Examples:

Function Documentation

◆ process_format_impl()

void time_shield::process_format_impl ( char last_char,
size_t repeat_count,
ts_t ts,
tz_t utc_offset,
const DateTimeStruct & dt,
std::string & result )
inline

Definition at line 48 of file time_formatting.hpp.

◆ time_zone_struct_to_string()

const std::string time_shield::time_zone_struct_to_string ( const TimeZoneStruct & tz)
inline

Converts a TimeZoneStruct to a string representation.

Parameters
tzThe TimeZoneStruct to convert.
Returns
A string representation of the TimeZoneStruct.

Definition at line 66 of file time_zone_struct.hpp.

◆ to_human_readable()

std::string time_shield::to_human_readable ( ts_t ts)

Converts a timestamp in seconds to a human-readable format.

Parameters
timestamp_msThe timestamp in seconds.
Returns
A string in the format "YYYY-MM-DD HH:MM:SS".

Definition at line 777 of file time_formatting.hpp.

◆ to_human_readable_ms()

std::string time_shield::to_human_readable_ms ( ts_ms_t ts)

Converts a timestamp in milliseconds to a human-readable format.

Parameters
timestamp_msThe timestamp in milliseconds.
Returns
A string in the format "YYYY-MM-DD HH:MM:SS.SSS".

Definition at line 787 of file time_formatting.hpp.

◆ to_iso8601() [1/2]

template<class T = ts_t>
const std::string time_shield::to_iso8601 ( T ts)
inline

Converts a timestamp to an ISO8601 string.

This function converts a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in ISO8601 format.

Definition at line 552 of file time_formatting.hpp.

◆ to_iso8601() [2/2]

template<class T = ts_t>
const std::string time_shield::to_iso8601 ( T ts,
tz_t utc_offset )
inline

Converts a timestamp to an ISO8601 string with timezone offset.

This function converts a timestamp to a string in ISO8601 format with timezone offset.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
utc_offsetThe timezone offset in seconds.
Returns
A string representing the timestamp in ISO8601 format with timezone offset.

Definition at line 670 of file time_formatting.hpp.

◆ to_iso8601_date()

template<class T = ts_t>
const std::string time_shield::to_iso8601_date ( T ts)
inline

Converts a timestamp to an ISO8601 date string.

This function converts the date part of a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the date part of the timestamp in ISO8601 format.

Definition at line 571 of file time_formatting.hpp.

◆ to_iso8601_ms() [1/2]

const std::string time_shield::to_iso8601_ms ( ts_ms_t ts_ms)
inline

Converts a timestamp in milliseconds to an ISO8601 string.

This function converts a timestamp in milliseconds to a string in ISO8601 format.

Parameters
ts_msThe timestamp in milliseconds to convert.
Returns
A string representing the timestamp in ISO8601 format with milliseconds.

Definition at line 654 of file time_formatting.hpp.

◆ to_iso8601_ms() [2/2]

const std::string time_shield::to_iso8601_ms ( ts_ms_t ts_ms,
tz_t utc_offset )
inline

Converts a timestamp in milliseconds to an ISO8601 string with timezone offset.

This function converts a timestamp in milliseconds to a string in ISO8601 format with timezone offset.

Parameters
ts_msThe timestamp in milliseconds to convert.
utc_offsetThe timezone offset in seconds.
Returns
A string representing the timestamp in ISO8601 format with timezone offset and milliseconds.

Definition at line 697 of file time_formatting.hpp.

◆ to_iso8601_time()

template<class T = ts_t>
const std::string time_shield::to_iso8601_time ( T ts)
inline

Converts a timestamp to an ISO8601 time string.

This function converts the time part of a timestamp to a string in ISO8601 format.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in ISO8601 format.

Definition at line 586 of file time_formatting.hpp.

◆ to_iso8601_time_utc()

template<class T = ts_t>
const std::string time_shield::to_iso8601_time_utc ( T ts)
inline

Converts a timestamp to an ISO8601 UTC time string.

This function converts the time part of a timestamp to a string in ISO8601 format with 'Z' indicating UTC.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in ISO8601 format with 'Z' indicating UTC.

Definition at line 605 of file time_formatting.hpp.

◆ to_iso8601_utc()

template<class T = ts_t>
const std::string time_shield::to_iso8601_utc ( T ts)
inline

Converts a timestamp to an ISO8601 string in UTC format.

This function converts a timestamp to a string in ISO8601 format with UTC timezone.

Template Parameters
TThe type of the timestamp (default is ts_t).
Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in ISO8601 UTC format.

Definition at line 624 of file time_formatting.hpp.

◆ to_iso8601_utc_ms()

const std::string time_shield::to_iso8601_utc_ms ( ts_ms_t ts_ms)
inline

Converts a timestamp in milliseconds to an ISO8601 string in UTC format.

This function converts a timestamp in milliseconds to a string in ISO8601 format with UTC timezone.

Parameters
ts_msThe timestamp in milliseconds to convert.
Returns
A string representing the timestamp in ISO8601 UTC format with milliseconds.

Definition at line 641 of file time_formatting.hpp.

◆ to_mql5_date()

const std::string time_shield::to_mql5_date ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 date format.

This function converts a timestamp to a string in MQL5 date format (yyyy.mm.dd).

Parameters
tsThe timestamp to convert.
Returns
A string representing the date part of the timestamp in MQL5 format.

Definition at line 734 of file time_formatting.hpp.

◆ to_mql5_date_time()

const std::string time_shield::to_mql5_date_time ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 date and time format.

This function converts a timestamp to a string in MQL5 date and time format (yyyy.mm.dd hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the timestamp in MQL5 date and time format.

Definition at line 715 of file time_formatting.hpp.

◆ to_mql5_full()

const std::string time_shield::to_mql5_full ( ts_t ts)
inline

Alias for to_mql5_date_time_str function.

Definition at line 724 of file time_formatting.hpp.

◆ to_mql5_time()

const std::string time_shield::to_mql5_time ( ts_t ts)
inline

Converts a timestamp to a string in MQL5 time format.

This function converts a timestamp to a string in MQL5 time format (hh:mm:ss).

Parameters
tsThe timestamp to convert.
Returns
A string representing the time part of the timestamp in MQL5 format.

Definition at line 747 of file time_formatting.hpp.

◆ to_str() [1/2]

template<class T = ts_t>
const std::string time_shield::to_str ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )
inline

Alias for to_string function.

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 454 of file time_formatting.hpp.

◆ to_str() [2/2]

const std::string time_shield::to_str ( const TimeZoneStruct & tz)
inline

Alias for time_zone_struct_to_string function.

Converts a TimeZoneStruct to a string representation.

Parameters
tzThe TimeZoneStruct to convert.
Returns
A string representation of the TimeZoneStruct.

Definition at line 83 of file time_zone_struct.hpp.

◆ to_str_ms()

template<class T = ts_t>
const std::string time_shield::to_str_ms ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )
inline

Alias for to_string function.

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 537 of file time_formatting.hpp.

◆ to_string() [1/2]

template<class T = ts_t>
const std::string time_shield::to_string ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )

Convert timestamp to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 405 of file time_formatting.hpp.

◆ to_string() [2/2]

const std::string time_shield::to_string ( const TimeZoneStruct & tz)
inline

Alias for time_zone_struct_to_string function.

Converts a TimeZoneStruct to a string representation.

Parameters
tzThe TimeZoneStruct to convert.
Returns
A string representation of the TimeZoneStruct.

Definition at line 75 of file time_zone_struct.hpp.

◆ to_string_ms()

template<class T = ts_ms_t>
const std::string time_shield::to_string_ms ( const std::string & format_str,
T timestamp,
tz_t utc_offset = 0 )

Convert timestamp in milliseconds to string with custom format.

This function is similar to the strftime function and supports the majority of its specifiers, as well as additional ones: YY, YYYY, YYYYYY, WWW, www, hh, mm, ss, dd, sss.

The function accepts the following format specifiers as parameters:

  • YYYYYY: Year with reduction in the number of millennia.
  • YYYY: Year represented by 4 digits.
  • YY: Last two digits of the year.
  • MM: Month (01-12).
  • MMM: Abbreviated month name.
  • DD: Day of the month (01-31).
  • hh: Hour of the day in 24-hour format (00-23).
  • mm: Minute of the hour (00-59).
  • ss: Second (00-59).
  • sss: Millisecond (000-999).
  • WWW: Abbreviated day of the week name in uppercase (SUN, MON, TUE, etc.).
  • www: Abbreviated day of the week name (Sun, Mon, Tue, etc.).

For more information, see the strftime specifiers documentation:

See also
https://manpages.debian.org/bullseye/manpages-dev/strftime.3.en.html
Parameters
format_strFormat string with custom parameters, e.g., "%H:%M:%S".
timestampTimestamp in milliseconds.
utc_offsetUTC offset in seconds (default is 0).
Returns
Returns a string in the format specified by the user.

Definition at line 488 of file time_formatting.hpp.

◆ to_windows_filename()

const std::string time_shield::to_windows_filename ( ts_t ts)
inline

Converts a timestamp in seconds to a Windows-compatible filename format.

Parameters
timestamp_msThe timestamp in seconds.
Returns
A string in the format "YYYY-MM-DD_HH-MM-SS".

Definition at line 757 of file time_formatting.hpp.

◆ to_windows_filename_ms()

const std::string time_shield::to_windows_filename_ms ( ts_ms_t ts)
inline

Converts a timestamp in milliseconds to a Windows-compatible filename format.

Parameters
timestamp_msThe timestamp in milliseconds.
Returns
A string in the format "YYYY-MM-DD_HH-MM-SS-SSS".

Definition at line 767 of file time_formatting.hpp.