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

Structures for representing and working with time and date components. More...

Classes

struct  time_shield::DateStruct
 Structure to represent a date. More...
 
struct  time_shield::DateTimeStruct
 Structure to represent date and time. More...
 
struct  time_shield::TimeStruct
 Structure to represent time. More...
 
struct  time_shield::TimeZoneStruct
 Structure to represent time zone information. More...
 

Functions

const DateStruct time_shield::create_date_struct (int64_t year, int32_t mon=1, int32_t day=1)
 Creates a DateStruct instance.
 
const DateTimeStruct time_shield::create_date_time_struct (int64_t year, int mon=1, int day=1, int hour=0, int min=0, int sec=0, int ms=0)
 Creates a DateTimeStruct instance.
 
template<class T1 , class T2 = ts_t>
T1 time_shield::to_date_time (T2 ts)
 Converts a timestamp to a date-time structure.
 
template<class T1 , class T2 = ts_t>
T1 time_shield::to_dt (T2 ts)
 Alias for to_date_time function.
 
template<class T >
time_shield::to_date_time_ms (ts_ms_t ts)
 Converts a timestamp in milliseconds to a date-time structure with milliseconds.
 
template<class T >
time_shield::to_dt_ms (ts_ms_t ts)
 Alias for to_date_time_ms function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::dt_to_timestamp (const T &date_time)
 Converts a date-time structure to a timestamp.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_timestamp (const T &date_time)
 Alias for dt_to_timestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_ts (const T &date_time)
 Alias for dt_to_timestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::ts (const T &date_time)
 Alias for dt_to_timestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::timestamp (const T &date_time)
 Alias for dt_to_timestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::dt_to_timestamp_ms (const T &date_time)
 Converts a date-time structure to a timestamp in milliseconds.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_timestamp_ms (const T &date_time)
 Alias for dt_to_timestamp_ms function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_ts_ms (const T &date_time)
 Alias for dt_to_timestamp_ms function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::ts_ms (const T &date_time)
 Alias for dt_to_timestamp_ms function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::timestamp_ms (const T &date_time)
 Alias for dt_to_timestamp_ms function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::dt_to_ftimestamp (const T &date_time)
 Converts a date-time structure to a floating-point timestamp.
 
template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::to_ftimestamp (const T &date_time)
 Alias for dt_to_ftimestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::to_fts (const T &date_time)
 Alias for dt_to_ftimestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::fts (const T &date_time)
 Alias for dt_to_ftimestamp function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::ftimestamp (const T &date_time)
 Alias for dt_to_ftimestamp function.
 
template<class T1 = Weekday, class T2 >
constexpr const T1 time_shield::get_weekday_from_date (const T2 &date)
 Get the day of the week from a date structure.
 
template<class T1 = int, class T2 >
constexpr const T1 time_shield::day_of_week_dt (const T2 &date)
 Alias for get_weekday_from_date function that accepts a date structure.
 
template<class T1 = int, class T2 >
constexpr const T1 time_shield::day_of_week (const T2 &date)
 Alias for get_weekday_from_date function that accepts a date structure.
 
const TimeStruct time_shield::create_time_struct (int16_t hour, int16_t min, int16_t sec=0, int16_t ms=0)
 Creates a TimeStruct instance.
 
const TimeZoneStruct time_shield::create_time_zone_struct (int hour, int min, bool is_positive=true)
 Creates a TimeZoneStruct instance.
 
template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time_zone_offset (const T &time_zone) noexcept
 Check if the time zone is valid.
 
template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time_zone (const T &time_zone)
 Alias for is_valid_time_zone_offset function.
 
template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_tz (const T &time_zone)
 Alias for is_valid_time_zone_offset function.
 
template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time (const T &time) noexcept
 Checks the correctness of the specified time.
 
template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_date (const T &date) noexcept
 Checks the correctness of the specified date.
 
template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_date_time (const T &date_time) noexcept
 Checks the correctness of a date and time.
 

Detailed Description

Structures for representing and working with time and date components.

This group includes various structures used for representing time, date, and date-time combinations, along with related utility functions for creating and manipulating these structures.

Included Structures:

Example Usage:

auto time = time_shield::create_time_struct(12, 30, 45); // 12:30:45
auto date = time_shield::create_date_struct(2024, 11, 25); // 2024-11-25
auto date_time = time_shield::create_date_time_struct(2024, 11, 25, 12, 30, 45);
auto tz = time_shield::to_time_zone_struct(3600); // +01:00
const TimeZoneStruct to_time_zone_struct(tz_t offset)
Converts an integer to a TimeZoneStruct.
const DateStruct create_date_struct(int64_t year, int32_t mon=1, int32_t day=1)
Creates a DateStruct instance.
const TimeStruct create_time_struct(int16_t hour, int16_t min, int16_t sec=0, int16_t ms=0)
Creates a TimeStruct instance.
const DateTimeStruct create_date_time_struct(int64_t year, int mon=1, int day=1, int hour=0, int min=0, int sec=0, int ms=0)
Creates a DateTimeStruct instance.

Function Documentation

◆ create_date_struct()

const DateStruct time_shield::create_date_struct ( int64_t year,
int32_t mon = 1,
int32_t day = 1 )
inline

Creates a DateStruct instance.

Parameters
yearThe year component of the date.
monThe month component of the date, defaults to 1 (January).
dayThe day component of the date, defaults to 1.
Returns
A DateStruct instance with the provided date components.

Definition at line 25 of file date_struct.hpp.

◆ create_date_time_struct()

const DateTimeStruct time_shield::create_date_time_struct ( int64_t year,
int mon = 1,
int day = 1,
int hour = 0,
int min = 0,
int sec = 0,
int ms = 0 )
inline

Creates a DateTimeStruct instance.

Parameters
yearThe year component of the date.
monThe month component of the date, defaults to 1 (January).
dayThe day component of the date, defaults to 1.
hourThe hour component of the time, defaults to 0.
minThe minute component of the time, defaults to 0.
secThe second component of the time, defaults to 0.
msThe millisecond component of the time, defaults to 0.
Returns
A DateTimeStruct instance with the provided date and time components.

Definition at line 33 of file date_time_struct.hpp.

◆ create_time_struct()

const TimeStruct time_shield::create_time_struct ( int16_t hour,
int16_t min,
int16_t sec = 0,
int16_t ms = 0 )
inline

Creates a TimeStruct instance.

Parameters
hourThe hour component of the time.
minThe minute component of the time.
secThe second component of the time, defaults to 0.
msThe millisecond component of the time, defaults to 0.
Returns
A TimeStruct instance with the provided time components.

Definition at line 27 of file time_struct.hpp.

◆ create_time_zone_struct()

const TimeZoneStruct time_shield::create_time_zone_struct ( int hour,
int min,
bool is_positive = true )
inline

Creates a TimeZoneStruct instance.

Parameters
hourThe hour component of the time.
minThe minute component of the time.
is_positiveTrue if the time zone offset is positive, false if negative.
Returns
A TimeZoneStruct instance with the provided time components.

Definition at line 29 of file time_zone_struct.hpp.

◆ day_of_week()

template<class T1 = int, class T2 >
const T1 time_shield::day_of_week ( const T2 & date)
constexpr

Alias for get_weekday_from_date function that accepts a date structure.

Get the day of the week from a date structure.

This function takes a date structure with fields 'year', 'mon', and 'day', and returns the day of the week (SUN = 0, MON = 1, ... SAT = 6).

Parameters
dateStructure containing year, month, and day.
Returns
Day of the week (SUN = 0, MON = 1, ... SAT = 6).

Definition at line 2114 of file time_conversions.hpp.

◆ day_of_week_dt()

template<class T1 = int, class T2 >
const T1 time_shield::day_of_week_dt ( const T2 & date)
constexpr

Alias for get_weekday_from_date function that accepts a date structure.

Get the day of the week from a date structure.

This function takes a date structure with fields 'year', 'mon', and 'day', and returns the day of the week (SUN = 0, MON = 1, ... SAT = 6).

Parameters
dateStructure containing year, month, and day.
Returns
Day of the week (SUN = 0, MON = 1, ... SAT = 6).

Definition at line 2106 of file time_conversions.hpp.

◆ dt_to_ftimestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::dt_to_ftimestamp ( const T & date_time)
inline

Converts a date-time structure to a floating-point timestamp.

This function converts a given date and time structure to a floating-point timestamp, which is the number of seconds (with fractional milliseconds) since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure containing year, month, day, hour, minute, second, and millisecond fields.
Returns
Floating-point timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 871 of file time_conversions.hpp.

◆ dt_to_timestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::dt_to_timestamp ( const T & date_time)
inline

Converts a date-time structure to a timestamp.

This function converts a given date and time to a timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 511 of file time_conversions.hpp.

◆ dt_to_timestamp_ms()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::dt_to_timestamp_ms ( const T & date_time)
inline

Converts a date-time structure to a timestamp in milliseconds.

This function converts a given date-time structure to a timestamp in milliseconds, which is the number of milliseconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp in milliseconds representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 699 of file time_conversions.hpp.

◆ ftimestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::ftimestamp ( const T & date_time)
inline

Alias for dt_to_ftimestamp function.

Converts a date-time structure to a floating-point timestamp.

This function converts a given date and time structure to a floating-point timestamp, which is the number of seconds (with fractional milliseconds) since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure containing year, month, day, hour, minute, second, and millisecond fields.
Returns
Floating-point timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 908 of file time_conversions.hpp.

◆ fts()

template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::fts ( const T & date_time)
inline

Alias for dt_to_ftimestamp function.

Converts a date-time structure to a floating-point timestamp.

This function converts a given date and time structure to a floating-point timestamp, which is the number of seconds (with fractional milliseconds) since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure containing year, month, day, hour, minute, second, and millisecond fields.
Returns
Floating-point timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 899 of file time_conversions.hpp.

◆ get_weekday_from_date()

template<class T1 = Weekday, class T2 >
const T1 time_shield::get_weekday_from_date ( const T2 & date)
constexpr

Get the day of the week from a date structure.

This function takes a date structure with fields 'year', 'mon', and 'day', and returns the day of the week (SUN = 0, MON = 1, ... SAT = 6).

Parameters
dateStructure containing year, month, and day.
Returns
Day of the week (SUN = 0, MON = 1, ... SAT = 6).

Definition at line 2098 of file time_conversions.hpp.

◆ is_valid_date()

template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_date ( const T & date)
inlinenoexcept

Checks the correctness of the specified date.

Template Parameters
TThe type of the date-time structure.
Parameters
dateDate-time structure.
Returns
true if the date is valid, false otherwise.

Definition at line 261 of file validation.hpp.

◆ is_valid_date_time()

template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_date_time ( const T & date_time)
inlinenoexcept

Checks the correctness of a date and time.

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeDate-time structure.
Returns
true if the date and time are valid, false otherwise.

Definition at line 297 of file validation.hpp.

◆ is_valid_time()

template<class T >
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time ( const T & time)
inlinenoexcept

Checks the correctness of the specified time.

Template Parameters
TThe type of the time structure.
Parameters
timeTime structure.
Returns
true if the time is valid, false otherwise.

Definition at line 214 of file validation.hpp.

◆ is_valid_time_zone()

template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time_zone ( const T & time_zone)
inline

Alias for is_valid_time_zone_offset function.

Check if the time zone is valid.

Template Parameters
TThe type of the time zone structure (default is TimeZoneStruct).
Parameters
time_zoneThe time zone structure containing hour and minute components.
Returns
True if the time zone is valid, false otherwise.

Definition at line 171 of file validation.hpp.

◆ is_valid_time_zone_offset()

template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_time_zone_offset ( const T & time_zone)
inlinenoexcept

Check if the time zone is valid.

Template Parameters
TThe type of the time zone structure (default is TimeZoneStruct).
Parameters
time_zoneThe time zone structure containing hour and minute components.
Returns
True if the time zone is valid, false otherwise.

Definition at line 162 of file validation.hpp.

◆ is_valid_tz()

template<class T = TimeZoneStruct>
TIME_SHIELD_CONSTEXPR const bool time_shield::is_valid_tz ( const T & time_zone)
inline

Alias for is_valid_time_zone_offset function.

Check if the time zone is valid.

Template Parameters
TThe type of the time zone structure (default is TimeZoneStruct).
Parameters
time_zoneThe time zone structure containing hour and minute components.
Returns
True if the time zone is valid, false otherwise.

Definition at line 180 of file validation.hpp.

◆ timestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::timestamp ( const T & date_time)
inline

Alias for dt_to_timestamp function.

Converts a date-time structure to a timestamp.

This function converts a given date and time to a timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 553 of file time_conversions.hpp.

◆ timestamp_ms()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::timestamp_ms ( const T & date_time)
inline

Alias for dt_to_timestamp_ms function.

Converts a date-time structure to a timestamp in milliseconds.

This function converts a given date-time structure to a timestamp in milliseconds, which is the number of milliseconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp in milliseconds representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 735 of file time_conversions.hpp.

◆ to_date_time()

template<class T1 , class T2 = ts_t>
T1 time_shield::to_date_time ( T2 ts)

Converts a timestamp to a date-time structure.

This function converts a timestamp (usually an integer representing seconds since epoch) to a custom date-time structure. The default type for the timestamp is int64_t.

Template Parameters
T1The date-time structure type to be returned.
T2The type of the timestamp (default is int64_t).
Parameters
tsThe timestamp to be converted.
Returns
A date-time structure of type T1.

Definition at line 233 of file time_conversions.hpp.

◆ to_date_time_ms()

template<class T >
T time_shield::to_date_time_ms ( ts_ms_t ts)
inline

Converts a timestamp in milliseconds to a date-time structure with milliseconds.

Template Parameters
TThe type of the date-time structure to return.
Parameters
tsThe timestamp in milliseconds to convert.
Returns
T A date-time structure with the corresponding date and time components.

Definition at line 346 of file time_conversions.hpp.

◆ to_dt()

template<class T1 , class T2 = ts_t>
T1 time_shield::to_dt ( T2 ts)

Alias for to_date_time function.

Converts a timestamp to a date-time structure.

This function converts a timestamp (usually an integer representing seconds since epoch) to a custom date-time structure. The default type for the timestamp is int64_t.

Template Parameters
T1The date-time structure type to be returned.
T2The type of the timestamp (default is int64_t).
Parameters
tsThe timestamp to be converted.
Returns
A date-time structure of type T1.

Definition at line 334 of file time_conversions.hpp.

◆ to_dt_ms()

template<class T >
T time_shield::to_dt_ms ( ts_ms_t ts)
inline

Alias for to_date_time_ms function.

Converts a timestamp in milliseconds to a date-time structure with milliseconds.

Template Parameters
TThe type of the date-time structure to return.
Parameters
tsThe timestamp in milliseconds to convert.
Returns
T A date-time structure with the corresponding date and time components.

Definition at line 356 of file time_conversions.hpp.

◆ to_ftimestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::to_ftimestamp ( const T & date_time)
inline

Alias for dt_to_ftimestamp function.

Converts a date-time structure to a floating-point timestamp.

This function converts a given date and time structure to a floating-point timestamp, which is the number of seconds (with fractional milliseconds) since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure containing year, month, day, hour, minute, second, and millisecond fields.
Returns
Floating-point timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 881 of file time_conversions.hpp.

◆ to_fts()

template<class T >
TIME_SHIELD_CONSTEXPR const fts_t time_shield::to_fts ( const T & date_time)
inline

Alias for dt_to_ftimestamp function.

Converts a date-time structure to a floating-point timestamp.

This function converts a given date and time structure to a floating-point timestamp, which is the number of seconds (with fractional milliseconds) since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure containing year, month, day, hour, minute, second, and millisecond fields.
Returns
Floating-point timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 890 of file time_conversions.hpp.

◆ to_timestamp()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_timestamp ( const T & date_time)
inline

Alias for dt_to_timestamp function.

Converts a date-time structure to a timestamp.

This function converts a given date and time to a timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 526 of file time_conversions.hpp.

◆ to_timestamp_ms()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_timestamp_ms ( const T & date_time)
inline

Alias for dt_to_timestamp_ms function.

Converts a date-time structure to a timestamp in milliseconds.

This function converts a given date-time structure to a timestamp in milliseconds, which is the number of milliseconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp in milliseconds representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 708 of file time_conversions.hpp.

◆ to_ts()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_ts ( const T & date_time)
inline

Alias for dt_to_timestamp function.

Converts a date-time structure to a timestamp.

This function converts a given date and time to a timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 535 of file time_conversions.hpp.

◆ to_ts_ms()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_ts_ms ( const T & date_time)
inline

Alias for dt_to_timestamp_ms function.

Converts a date-time structure to a timestamp in milliseconds.

This function converts a given date-time structure to a timestamp in milliseconds, which is the number of milliseconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp in milliseconds representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 717 of file time_conversions.hpp.

◆ ts()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::ts ( const T & date_time)
inline

Alias for dt_to_timestamp function.

Converts a date-time structure to a timestamp.

This function converts a given date and time to a timestamp, which is the number of seconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 544 of file time_conversions.hpp.

◆ ts_ms()

template<class T >
TIME_SHIELD_CONSTEXPR const ts_t time_shield::ts_ms ( const T & date_time)
inline

Alias for dt_to_timestamp_ms function.

Converts a date-time structure to a timestamp in milliseconds.

This function converts a given date-time structure to a timestamp in milliseconds, which is the number of milliseconds since the Unix epoch (January 1, 1970).

Template Parameters
TThe type of the date-time structure.
Parameters
date_timeThe date-time structure.
Returns
Timestamp in milliseconds representing the given date and time.
Exceptions
std::invalid_argumentif the date-time combination is invalid.

Definition at line 726 of file time_conversions.hpp.