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

A comprehensive set of functions for parsing and converting date and time strings. More...

Functions

template<class T = Month>
const T time_shield::get_month_number (const std::string &month)
 Get the month number by name.
 
template<class T = Month>
const T time_shield::month_of_year (const std::string &month)
 Alias for get_month_number function.
 
template<class T = Month>
const bool time_shield::try_get_month_number (const std::string &month, T &value)
 Get the month number by name, with output parameter.
 
template<class T = Month>
const bool time_shield::get_month_number (const std::string &month, T &value)
 Alias for try_get_month_number function.
 
template<class T = Month>
const bool time_shield::month_of_year (const std::string &month, T &value)
 Alias for try_get_month_number function.
 
const bool time_shield::parse_time_zone (const std::string &tz_str, TimeZoneStruct &tz)
 Parse a time zone string into a TimeZoneStruct.
 
const bool time_shield::parse_tz (const std::string &tz_str, TimeZoneStruct &tz)
 Alias for parse_time_zone function.
 
const bool time_shield::parse_iso8601 (const std::string &input, DateTimeStruct &dt, TimeZoneStruct &tz)
 Parse a date and time string in ISO8601 format.
 
const bool time_shield::str_to_ts (const std::string &str, ts_t &ts)
 Convert an ISO8601 string to a timestamp (ts_t).
 
const bool time_shield::str_to_ts_ms (const std::string &str, ts_ms_t &ts)
 Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).
 
const bool time_shield::str_to_fts (const std::string &str, fts_t &ts)
 Convert an ISO8601 string to a floating-point timestamp (fts_t).
 
const ts_t time_shield::ts (const std::string &str)
 Convert an ISO8601 string to a timestamp (ts_t).
 
const ts_ms_t time_shield::ts_ms (const std::string &str)
 Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).
 
const fts_t time_shield::fts (const std::string &str)
 Convert an ISO8601 string to a floating-point timestamp (fts_t).
 
const ts_t time_shield::ts (const char *str)
 Convert an ISO8601 C-style string to a timestamp (ts_t).
 
const ts_ms_t time_shield::ts_ms (const char *str)
 Convert an ISO8601 C-style string to a millisecond timestamp (ts_ms_t).
 
const fts_t time_shield::fts (const char *str)
 Convert an ISO8601 C-style string to a floating-point timestamp (fts_t).
 

Detailed Description

A comprehensive set of functions for parsing and converting date and time strings.

This module provides utilities for parsing date and time strings in ISO8601 format, extracting date components, and converting them into various timestamp formats.

Key Features:

Usage Examples:

Function Documentation

◆ fts() [1/2]

const fts_t time_shield::fts ( const char * str)
inline

Convert an ISO8601 C-style string to a floating-point timestamp (fts_t).

This function parses a string in ISO8601 format and converts it to a floating-point timestamp. If the parsing fails, it returns 0.

Parameters
strThe ISO8601 C-style string.
Returns
The floating-point timestamp if successful, 0 otherwise.

Definition at line 335 of file time_parser.hpp.

◆ fts() [2/2]

const fts_t time_shield::fts ( const std::string & str)
inline

Convert an ISO8601 string to a floating-point timestamp (fts_t).

This function parses a string in ISO8601 format and converts it to a floating-point timestamp. If the parsing fails, it returns 0.

Parameters
strThe ISO8601 string.
Returns
The floating-point timestamp if successful, 0 otherwise.

Definition at line 301 of file time_parser.hpp.

◆ get_month_number() [1/2]

template<class T = Month>
const T time_shield::get_month_number ( const std::string & month)

Get the month number by name.

Template Parameters
TThe return type, default is Month enum.
Parameters
monthThe name of the month as a string.
Returns
The month number corresponding to the given name.
Exceptions
std::invalid_argumentif the month name is invalid.

Definition at line 62 of file time_parser.hpp.

◆ get_month_number() [2/2]

template<class T = Month>
const bool time_shield::get_month_number ( const std::string & month,
T & value )

Alias for try_get_month_number function.

Get the month number by name, with output parameter.

Template Parameters
TThe type for the month number, default is Month enum.
Parameters
monthThe name of the month as a string.
valueThe reference to store the month number if found.
Returns
True if the month name is valid, false otherwise.

Definition at line 133 of file time_parser.hpp.

◆ month_of_year() [1/2]

template<class T = Month>
const T time_shield::month_of_year ( const std::string & month)

Alias for get_month_number function.

Get the month number by name.

Template Parameters
TThe return type, default is Month enum.
Parameters
monthThe name of the month as a string.
Returns
The month number corresponding to the given name.
Exceptions
std::invalid_argumentif the month name is invalid.

Definition at line 91 of file time_parser.hpp.

◆ month_of_year() [2/2]

template<class T = Month>
const bool time_shield::month_of_year ( const std::string & month,
T & value )

Alias for try_get_month_number function.

Get the month number by name, with output parameter.

Template Parameters
TThe type for the month number, default is Month enum.
Parameters
monthThe name of the month as a string.
valueThe reference to store the month number if found.
Returns
True if the month name is valid, false otherwise.

Definition at line 140 of file time_parser.hpp.

◆ parse_iso8601()

const bool time_shield::parse_iso8601 ( const std::string & input,
DateTimeStruct & dt,
TimeZoneStruct & tz )

Parse a date and time string in ISO8601 format.

This function parses a date and time string in the ISO8601 format and fills the provided DateTimeStruct and TimeZoneStruct with the parsed values.

Parameters
inputThe input string in ISO8601 format.
dtThe DateTimeStruct to be filled with the parsed date and time values.
tzThe TimeZoneStruct to be filled with the parsed time zone values.
Returns
True if the parsing is successful and the date and time values are valid, false otherwise.

Definition at line 186 of file time_parser.hpp.

◆ parse_time_zone()

const bool time_shield::parse_time_zone ( const std::string & tz_str,
TimeZoneStruct & tz )

Parse a time zone string into a TimeZoneStruct.

This function parses a time zone string in the format "+hh:mm" or "Z" into a TimeZoneStruct. If the string is empty or "Z", it sets the time zone to UTC.

Parameters
tz_strThe time zone string.
tzThe TimeZoneStruct to be filled.
Returns
True if the parsing is successful and the time zone is valid, false otherwise.

Definition at line 152 of file time_parser.hpp.

◆ parse_tz()

const bool time_shield::parse_tz ( const std::string & tz_str,
TimeZoneStruct & tz )
inline

Alias for parse_time_zone function.

Parse a time zone string into a TimeZoneStruct.

This function parses a time zone string in the format "+hh:mm" or "Z" into a TimeZoneStruct. If the string is empty or "Z", it sets the time zone to UTC.

Parameters
tz_strThe time zone string.
tzThe TimeZoneStruct to be filled.
Returns
True if the parsing is successful and the time zone is valid, false otherwise.

Definition at line 173 of file time_parser.hpp.

◆ str_to_fts()

const bool time_shield::str_to_fts ( const std::string & str,
fts_t & ts )
inline

Convert an ISO8601 string to a floating-point timestamp (fts_t).

This function parses a string in ISO8601 format and converts it to a floating-point timestamp.

Parameters
strThe ISO8601 string.
tsThe floating-point timestamp to be filled.
Returns
True if the parsing and conversion are successful, false otherwise.

Definition at line 263 of file time_parser.hpp.

◆ str_to_ts()

const bool time_shield::str_to_ts ( const std::string & str,
ts_t & ts )
inline

Convert an ISO8601 string to a timestamp (ts_t).

This function parses a string in ISO8601 format and converts it to a timestamp.

Parameters
strThe ISO8601 string.
tsThe timestamp to be filled.
Returns
True if the parsing and conversion are successful, false otherwise.

Definition at line 231 of file time_parser.hpp.

◆ str_to_ts_ms()

const bool time_shield::str_to_ts_ms ( const std::string & str,
ts_ms_t & ts )
inline

Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).

This function parses a string in ISO8601 format and converts it to a millisecond timestamp.

Parameters
strThe ISO8601 string.
tsThe millisecond timestamp to be filled.
Returns
True if the parsing and conversion are successful, false otherwise.

Definition at line 247 of file time_parser.hpp.

◆ try_get_month_number()

template<class T = Month>
const bool time_shield::try_get_month_number ( const std::string & month,
T & value )

Get the month number by name, with output parameter.

Template Parameters
TThe type for the month number, default is Month enum.
Parameters
monthThe name of the month as a string.
valueThe reference to store the month number if found.
Returns
True if the month name is valid, false otherwise.

Definition at line 103 of file time_parser.hpp.

◆ ts() [1/2]

const ts_t time_shield::ts ( const char * str)
inline

Convert an ISO8601 C-style string to a timestamp (ts_t).

This function parses a string in ISO8601 format and converts it to a timestamp. If parsing fails, it returns 0.

Parameters
strThe ISO8601 C-style string.
Returns
The timestamp value. Returns 0 if parsing fails.

Definition at line 313 of file time_parser.hpp.

◆ ts() [2/2]

const ts_t time_shield::ts ( const std::string & str)
inline

Convert an ISO8601 string to a timestamp (ts_t).

This function parses a string in ISO8601 format and converts it to a timestamp. If parsing fails, it returns 0.

Parameters
strThe ISO8601 string.
Returns
The timestamp value. Returns 0 if parsing fails.

Definition at line 279 of file time_parser.hpp.

◆ ts_ms() [1/2]

const ts_ms_t time_shield::ts_ms ( const char * str)
inline

Convert an ISO8601 C-style string to a millisecond timestamp (ts_ms_t).

This function parses a string in ISO8601 format and converts it to a millisecond timestamp. If parsing fails, it returns 0.

Parameters
strThe ISO8601 C-style string.
Returns
The parsed millisecond timestamp, or 0 if parsing fails.

Definition at line 324 of file time_parser.hpp.

◆ ts_ms() [2/2]

const ts_ms_t time_shield::ts_ms ( const std::string & str)
inline

Convert an ISO8601 string to a millisecond timestamp (ts_ms_t).

This function parses a string in ISO8601 format and converts it to a millisecond timestamp. If parsing fails, it returns 0.

Parameters
strThe ISO8601 string.
Returns
The parsed millisecond timestamp, or 0 if parsing fails.

Definition at line 290 of file time_parser.hpp.