Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
time_conversions.hpp File Reference

Header file for time conversion functions. More...

Go to the source code of this file.

Namespaces

namespace  time_shield
 Main namespace for the Time Shield library.
 

Functions

template<class T = int>
constexpr const T time_shield::ns_of_sec (fts_t ts) noexcept
 Get the nanosecond part of the second from a floating-point timestamp.
 
template<class T = int>
constexpr const T time_shield::us_of_sec (fts_t ts) noexcept
 Get the microsecond part of the second from a floating-point timestamp.
 
template<class T = int>
constexpr const T time_shield::ms_of_sec (fts_t ts) noexcept
 Get the millisecond part of the second from a floating-point timestamp.
 
template<class T = int>
constexpr const T time_shield::ms_of_ts (ts_ms_t ts) noexcept
 Get the millisecond part of the timestamp.
 
template<class T>
constexpr ts_ms_t time_shield::sec_to_ms_impl (T t, std::true_type tag) noexcept
 Helper function for converting seconds to milliseconds (floating-point version).
 
template<class T>
constexpr ts_ms_t time_shield::sec_to_ms_impl (T t, std::false_type tag) noexcept
 Helper function for converting seconds to milliseconds (integral version).
 
template<class T1 = ts_ms_t, class T2>
constexpr T1 time_shield::sec_to_ms (T2 ts) noexcept
 Converts a timestamp from seconds to milliseconds.
 
ts_ms_t time_shield::fsec_to_ms (fts_t ts) noexcept
 Converts a floating-point timestamp from seconds to milliseconds.
 
template<class T1 = ts_t, class T2 = ts_ms_t>
constexpr const T1 time_shield::ms_to_sec (T2 ts_ms) noexcept
 Converts a timestamp from milliseconds to seconds.
 
template<class T = ts_ms_t>
constexpr const fts_t time_shield::ms_to_fsec (T ts_ms) noexcept
 Converts a timestamp from milliseconds to floating-point seconds.
 
template<class T>
constexpr ts_ms_t time_shield::min_to_ms_impl (T t, std::true_type tag) noexcept
 Helper function for converting minutes to milliseconds (floating-point version).
 
template<class T>
constexpr ts_ms_t time_shield::min_to_ms_impl (T t, std::false_type tag) noexcept
 Helper function for converting minutes to milliseconds (integral version).
 
template<class T1 = ts_ms_t, class T2>
constexpr T1 time_shield::min_to_ms (T2 ts) noexcept
 Converts a timestamp from minutes to milliseconds.
 
template<class T1 = int, class T2 = ts_ms_t>
constexpr T1 time_shield::ms_to_min (T2 ts) noexcept
 Converts a timestamp from milliseconds to minutes.
 
template<class T>
constexpr ts_t time_shield::min_to_sec_impl (T t, std::true_type tag) noexcept
 Helper function for converting minutes to seconds (floating-point version).
 
template<class T>
constexpr ts_t time_shield::min_to_sec_impl (T t, std::false_type tag) noexcept
 Helper function for converting minutes to seconds (integral version).
 
template<class T1 = ts_t, class T2>
constexpr T1 time_shield::min_to_sec (T2 ts) noexcept
 Converts a timestamp from minutes to seconds.
 
template<class T1 = int, class T2 = ts_t>
constexpr T1 time_shield::sec_to_min (T2 ts) noexcept
 Converts a timestamp from seconds to minutes.
 
template<class T = int>
constexpr fts_t time_shield::min_to_fsec (T min) noexcept
 Converts a timestamp from minutes to floating-point seconds.
 
template<class T = ts_t>
constexpr double time_shield::sec_to_fmin (T ts) noexcept
 Converts a timestamp from seconds to floating-point minutes.
 
template<class T>
constexpr ts_ms_t time_shield::hour_to_ms_impl (T t, std::true_type tag) noexcept
 Helper function for converting hours to milliseconds (floating-point version).
 
template<class T>
constexpr ts_ms_t time_shield::hour_to_ms_impl (T t, std::false_type tag) noexcept
 Helper function for converting hours to milliseconds (integral version).
 
template<class T1 = ts_ms_t, class T2>
constexpr T1 time_shield::hour_to_ms (T2 ts) noexcept
 Converts a timestamp from hours to milliseconds.
 
template<class T1 = int, class T2 = ts_ms_t>
constexpr T1 time_shield::ms_to_hour (T2 ts) noexcept
 Converts a timestamp from milliseconds to hours.
 
template<class T>
constexpr ts_t time_shield::hour_to_sec_impl (T t, std::true_type tag) noexcept
 Helper function for converting hours to seconds (floating-point version).
 
template<class T>
constexpr ts_t time_shield::hour_to_sec_impl (T t, std::false_type tag) noexcept
 Helper function for converting hours to seconds (integral version).
 
template<class T1 = ts_t, class T2>
constexpr T1 time_shield::hour_to_sec (T2 ts) noexcept
 Converts a timestamp from hours to seconds.
 
template<class T1 = int, class T2 = ts_t>
constexpr T1 time_shield::sec_to_hour (T2 ts) noexcept
 Converts a timestamp from seconds to hours.
 
template<class T = int>
constexpr fts_t time_shield::hour_to_fsec (T hr) noexcept
 Converts a timestamp from hours to floating-point seconds.
 
template<class T = ts_t>
constexpr double time_shield::sec_to_fhour (T ts) noexcept
 Converts a timestamp from seconds to floating-point hours.
 
template<class T = year_t>
constexpr const T time_shield::get_unix_year (ts_t ts) noexcept
 Converts a UNIX timestamp to a year.
 
template<class T = int>
TIME_SHIELD_CONSTEXPR const T time_shield::hour24_to_12 (T hour) noexcept
 Converts a 24-hour format hour to a 12-hour format.
 
template<class T1 = DateTimeStruct, class T2 = ts_t>
T1 time_shield::to_date_time (T2 ts)
 Converts a timestamp to a date-time structure.
 
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 T1 = year_t, class T2 = int>
TIME_SHIELD_CONSTEXPR const ts_t time_shield::to_timestamp (T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
 Converts a date and time to a timestamp.
 
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.
 
TIME_SHIELD_CONSTEXPR const ts_t time_shield::tm_to_timestamp (const std::tm *timeinfo)
 Converts a std::tm structure to a timestamp.
 
template<class T1 = year_t, class T2 = int>
TIME_SHIELD_CONSTEXPR const ts_ms_t time_shield::to_timestamp_ms (T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T2 ms=0)
 Converts a date and time to a timestamp in milliseconds.
 
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.
 
TIME_SHIELD_CONSTEXPR const ts_t time_shield::tm_to_timestamp_ms (const std::tm *timeinfo)
 Converts a std::tm structure to a timestamp in milliseconds.
 
template<class T1 = year_t, class T2 = int, class T3 = int>
TIME_SHIELD_CONSTEXPR const fts_t time_shield::to_ftimestamp (T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T3 ms=0)
 Converts a date and time to a floating-point timestamp.
 
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.
 
TIME_SHIELD_CONSTEXPR const fts_t time_shield::tm_to_ftimestamp (const std::tm *timeinfo)
 Converts a std::tm structure to a floating-point timestamp.
 
template<class T = uday_t>
constexpr const T time_shield::get_unix_day (ts_t ts=time_shield::ts()) noexcept
 Get UNIX day.
 
template<class T = int>
constexpr const T time_shield::get_days_difference (ts_t start, ts_t stop) noexcept
 Get the number of days between two timestamps.
 
template<class T = uday_t>
constexpr const T time_shield::get_unix_day_ms (ts_ms_t t_ms=time_shield::ts_ms()) noexcept
 Get UNIX day from milliseconds timestamp.
 
template<class T = ts_t>
constexpr const T time_shield::unix_day_to_timestamp (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp in seconds.
 
template<class T = ts_t>
constexpr const T time_shield::unix_day_to_timestamp_ms (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp in milliseconds.
 
template<class T = ts_t>
constexpr const T time_shield::end_of_day_from_unix_day (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp representing the end of the day in seconds.
 
template<class T = ts_ms_t>
constexpr const T time_shield::end_of_day_from_unix_day_ms (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp representing the end of the day in milliseconds.
 
template<class T = ts_ms_t>
constexpr const T time_shield::start_of_next_day_from_unix_day (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp representing the start of the next day in seconds.
 
template<class T = ts_ms_t>
constexpr const T time_shield::start_of_next_day_from_unix_day_ms (uday_t unix_day) noexcept
 Converts a UNIX day to a timestamp representing the start of the next day in milliseconds.
 
template<class T = int64_t>
constexpr const T time_shield::get_unix_min (ts_t ts=ts())
 Get UNIX minute.
 
template<class T = int>
constexpr const T time_shield::sec_of_day (ts_t ts=ts()) noexcept
 Get the second of the day.
 
template<class T = int>
constexpr const T time_shield::sec_of_day_ms (ts_ms_t ts_ms) noexcept
 Get the second of the day from milliseconds timestamp.
 
template<class T1 = int, class T2 = int>
constexpr const T1 time_shield::sec_of_day (T2 hour, T2 min, T2 sec) noexcept
 Get the second of the day.
 
template<class T = int>
constexpr const T time_shield::sec_of_min (ts_t ts=ts())
 Get the second of the minute.
 
template<class T = int>
constexpr const T time_shield::sec_of_hour (ts_t ts=ts())
 Get the second of the hour.
 
template<class T = year_t>
TIME_SHIELD_CONSTEXPR const T time_shield::get_year (ts_t ts=ts())
 Get the year from the timestamp.
 
template<class T = year_t>
TIME_SHIELD_CONSTEXPR const T time_shield::get_year_ms (ts_ms_t ts_ms=ts_ms())
 Get the year from the timestamp in milliseconds.
 
TIME_SHIELD_CONSTEXPR const ts_t time_shield::start_of_year (ts_t ts) noexcept
 Get the start of the year timestamp.
 
TIME_SHIELD_CONSTEXPR const ts_ms_t time_shield::start_of_year_ms (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the start of the year timestamp in milliseconds.
 
template<class T = year_t>
TIME_SHIELD_CONSTEXPR const ts_t time_shield::start_of_year_date (T year)
 Get the timestamp of the start of the year.
 
template<class T = year_t>
TIME_SHIELD_CONSTEXPR const ts_ms_t time_shield::start_of_year_date_ms (T year)
 Get the timestamp in milliseconds of the start of the year.
 
TIME_SHIELD_CONSTEXPR ts_t time_shield::end_of_year (ts_t ts=time_shield::ts())
 Get the end-of-year timestamp.
 
template<class T = year_t>
TIME_SHIELD_CONSTEXPR const ts_ms_t time_shield::end_of_year_ms (ts_ms_t ts_ms=ts_ms())
 Get the timestamp in milliseconds of the end of the year.
 
template<class T = int>
const T time_shield::day_of_year (ts_t ts=time_shield::ts())
 Get the day of the year.
 
template<class T = Month>
TIME_SHIELD_CONSTEXPR const T time_shield::month_of_year (ts_t ts) noexcept
 Get the month of the year.
 
template<class T = int>
TIME_SHIELD_CONSTEXPR const T time_shield::day_of_month (ts_t ts=time_shield::ts())
 Get the day of the month.
 
template<class T1 = int, class T2 = year_t, class T3 = int>
constexpr const T1 time_shield::num_days_in_month (T2 year, T3 month) noexcept
 Get the number of days in a month.
 
template<class T1 = int>
TIME_SHIELD_CONSTEXPR const T1 time_shield::num_days_in_month_ts (ts_t ts=time_shield::ts()) noexcept
 Get the number of days in the month of the given timestamp.
 
template<class T1 = int, class T2 = year_t>
constexpr const T1 time_shield::num_days_in_year (T2 year) noexcept
 Get the number of days in a given year.
 
template<class T = int>
constexpr const T time_shield::num_days_in_year_ts (ts_t ts=time_shield::ts())
 Get the number of days in the current year.
 
constexpr const ts_t time_shield::start_of_day (ts_t ts=time_shield::ts()) noexcept
 Get the start of the day timestamp.
 
template<class T = int>
constexpr const ts_t time_shield::start_of_prev_day (ts_t ts=time_shield::ts(), T days=1) noexcept
 Get timestamp of the start of the previous day.
 
constexpr const ts_t time_shield::start_of_day_sec (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the start of the day timestamp in seconds.
 
constexpr const ts_ms_t time_shield::start_of_day_ms (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the start of the day timestamp in milliseconds.
 
template<class T = int>
constexpr const ts_t time_shield::start_of_next_day (ts_t ts, T days=1) noexcept
 Get the timestamp of the start of the day after a specified number of days.
 
template<class T = int>
constexpr const ts_ms_t time_shield::start_of_next_day_ms (ts_ms_t ts_ms, T days=1) noexcept
 Get the timestamp of the start of the day after a specified number of days.
 
template<class T = int>
constexpr const ts_t time_shield::next_day (ts_t ts, T days=1) noexcept
 Calculate the timestamp for a specified number of days in the future.
 
template<class T = int>
constexpr const ts_ms_t time_shield::next_day_ms (ts_ms_t ts_ms, T days=1) noexcept
 Calculate the timestamp for a specified number of days in the future (milliseconds).
 
constexpr const ts_t time_shield::end_of_day (const ts_t &ts=time_shield::ts()) noexcept
 Get the timestamp at the end of the day.
 
constexpr const ts_t time_shield::end_of_day_sec (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the end of the day in seconds.
 
constexpr const ts_ms_t time_shield::end_of_day_ms (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the end of the day in milliseconds.
 
template<class T1 = Weekday, class T2 = year_t, class T3 = int, class T4 = int>
constexpr const T1 time_shield::day_of_week_date (T2 year, T3 month, T4 day)
 Get the day of the week.
 
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 T = Weekday>
constexpr const T time_shield::get_weekday_from_ts (ts_t ts) noexcept
 Get the weekday from a timestamp.
 
template<class T = Weekday>
constexpr const T time_shield::get_weekday_from_ts_ms (ts_ms_t ts_ms)
 Get the weekday from a timestamp in milliseconds.
 
TIME_SHIELD_CONSTEXPR const ts_t time_shield::start_of_month (ts_t ts=time_shield::ts())
 Get the timestamp at the start of the current month.
 
TIME_SHIELD_CONSTEXPR const ts_t time_shield::end_of_month (ts_t ts=time_shield::ts())
 Get the last timestamp of the current month.
 
TIME_SHIELD_CONSTEXPR ts_t time_shield::last_sunday_of_month (ts_t ts=time_shield::ts())
 Get the timestamp of the last Sunday of the current month.
 
template<class T1 = int, class T2 = year_t, class T3 = int>
TIME_SHIELD_CONSTEXPR const T1 time_shield::last_sunday_month_day (T2 year, T3 month)
 Get the day of the last Sunday of the given month and year.
 
constexpr const ts_t time_shield::start_of_hour (ts_t ts=time_shield::ts()) noexcept
 Get the timestamp at the start of the hour.
 
constexpr const ts_t time_shield::start_of_hour_sec (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the start of the hour.
 
constexpr const ts_ms_t time_shield::start_of_hour_ms (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the start of the hour. This function sets the minute and second to zero.
 
constexpr const ts_t time_shield::end_of_hour (ts_t ts=time_shield::ts()) noexcept
 Get the timestamp at the end of the hour. This function sets the minute and second to 59.
 
constexpr const ts_t time_shield::end_of_hour_sec (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the end of the hour.
 
constexpr const ts_ms_t time_shield::end_of_hour_ms (ts_ms_t ts_ms=time_shield::ts_ms()) noexcept
 Get the timestamp at the end of the hour.
 
template<class T = int>
constexpr const T time_shield::hour_of_day (ts_t ts=time_shield::ts()) noexcept
 Get the hour of the day.
 
constexpr const ts_t time_shield::start_of_week (ts_t ts=time_shield::ts())
 Get the timestamp of the beginning of the week.
 
constexpr const ts_t time_shield::end_of_week (ts_t ts=time_shield::ts())
 Get the timestamp of the end of the week.
 
constexpr const ts_t time_shield::start_of_saturday (ts_t ts=time_shield::ts())
 Get the timestamp of the start of Saturday.
 
constexpr const ts_t time_shield::start_of_min (ts_t ts=time_shield::ts()) noexcept
 Get the timestamp of the beginning of the minute.
 
constexpr const ts_t time_shield::end_of_min (ts_t ts=time_shield::ts()) noexcept
 Get the timestamp of the end of the minute.
 
template<class T = int>
constexpr const T time_shield::min_of_day (ts_t ts=time_shield::ts()) noexcept
 Get minute of day. This function returns a value between 0 to 1439 (minute of day).
 
template<class T = int>
constexpr const T time_shield::min_of_hour (ts_t ts=time_shield::ts()) noexcept
 Get minute of hour. This function returns a value between 0 to 59.
 
template<class T = int>
constexpr const ts_t time_shield::start_of_period (T p, ts_t ts=time_shield::ts())
 Get the timestamp of the start of the period.
 
template<class T = int>
constexpr const ts_t time_shield::end_of_period (T p, ts_t ts=time_shield::ts())
 Get the timestamp of the end of the period.
 
template<class T = TimeZoneStruct>
const T time_shield::to_time_zone (tz_t offset)
 Converts an integer to a time zone structure.
 

Detailed Description

Header file for time conversion functions.

This file contains functions for converting between different time representations and performing various time-related calculations.

Definition in file time_conversions.hpp.