3#ifndef _TIME_SHIELD_TIME_UNIT_CONVERSIONS_HPP_INCLUDED
4#define _TIME_SHIELD_TIME_UNIT_CONVERSIONS_HPP_INCLUDED
25 template<
class T =
int>
28 return static_cast<T
>(std::round(std::modf(
ts, &temp) *
static_cast<fts_t>(
NS_PER_SEC)));
35 template<
class T =
int>
38 return static_cast<T
>(std::round(std::modf(
ts, &temp) *
static_cast<fts_t>(
US_PER_SEC)));
45 template<
class T =
int>
48 return static_cast<T
>(std::round(std::modf(
ts, &temp) *
static_cast<fts_t>(
MS_PER_SEC)));
55 template<
class T =
int>
60# ifndef TIME_SHIELD_CPP17
87 template<
class T1 = ts_ms_t,
class T2>
89# ifdef TIME_SHIELD_CPP17
90 if constexpr (std::is_floating_point_v<T2>) {
91 return static_cast<T1
>(std::round(
ts *
static_cast<T2
>(
MS_PER_SEC)));
93 return static_cast<T1
>(
ts) *
static_cast<T1
>(
MS_PER_SEC);
97 (std::is_same<T2, double>::value || std::is_same<T2, float>::value),
116 template<
class T1 = ts_t,
class T2 = ts_ms_t>
125 template<
class T = ts_ms_t>
133# ifndef TIME_SHIELD_CPP17
160 template<
class T1 = ts_ms_t,
class T2>
162# ifdef TIME_SHIELD_CPP17
163 if constexpr (std::is_floating_point_v<T2>) {
164 return static_cast<T1
>(std::round(
ts *
static_cast<T2
>(
MS_PER_MIN)));
166 return static_cast<T1
>(
ts) *
static_cast<T1
>(
MS_PER_MIN);
170 (std::is_same<T2, double>::value || std::is_same<T2, float>::value),
182 template<
class T1 =
int,
class T2 = ts_ms_t>
184 return static_cast<T1
>(
ts) /
static_cast<T1
>(
MS_PER_MIN);
190# ifndef TIME_SHIELD_CPP17
217 template<
class T1 = ts_t,
class T2>
219# ifdef TIME_SHIELD_CPP17
220 if constexpr (std::is_floating_point_v<T2>) {
221 return static_cast<T1
>(std::round(
ts *
static_cast<T2
>(
SEC_PER_MIN)));
227 (std::is_same<T2, double>::value || std::is_same<T2, float>::value),
239 template<
class T1 =
int,
class T2 = ts_t>
248 template<
class T =
int>
257 template<
class T = ts_t>
259 return static_cast<double>(
ts) /
static_cast<double>(
SEC_PER_MIN);
266# ifndef TIME_SHIELD_CPP17
293 template<
class T1 = ts_ms_t,
class T2>
295# ifdef TIME_SHIELD_CPP17
296 if constexpr (std::is_floating_point_v<T2>) {
297 return static_cast<T1
>(std::round(
ts *
static_cast<T2
>(
MS_PER_HOUR)));
303 (std::is_same<T2, double>::value || std::is_same<T2, float>::value),
315 template<
class T1 =
int,
class T2 = ts_ms_t>
324# ifndef TIME_SHIELD_CPP17
351 template<
class T1 = ts_t,
class T2>
353# ifdef TIME_SHIELD_CPP17
354 if constexpr (std::is_floating_point_v<T2>) {
355 return static_cast<T1
>(std::round(
ts *
static_cast<T2
>(
SEC_PER_HOUR)));
361 (std::is_same<T2, double>::value || std::is_same<T2, float>::value),
373 template<
class T1 =
int,
class T2 = ts_t>
382 template<
class T =
int>
391 template<
class T = ts_t>
393 return static_cast<double>(
ts) /
static_cast<double>(
SEC_PER_HOUR);
400 template<
class T =
int>
402 if (hour == 0 || hour > 12)
return 12;
Configuration macros for the library.
Header file with time-related constants.
constexpr int64_t MS_PER_MIN
Milliseconds per minute.
constexpr int64_t SEC_PER_HOUR
Seconds per hour.
constexpr int64_t MS_PER_SEC
Milliseconds per second.
constexpr int64_t SEC_PER_MIN
Seconds per minute.
constexpr int64_t NS_PER_SEC
Nanoseconds per second.
constexpr int64_t MS_PER_HOUR
Milliseconds per hour.
constexpr int64_t US_PER_SEC
Microseconds per second.
constexpr T1 min_to_sec(T2 ts) noexcept
Converts a timestamp from minutes to seconds.
constexpr T1 hour_to_ms(T2 ts) noexcept
Converts a timestamp from hours to milliseconds.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
constexpr T ms_of_ts(ts_ms_t ts) noexcept
Get the millisecond part of the timestamp.
constexpr double sec_to_fhour(T ts) noexcept
Converts a timestamp from seconds to floating-point hours.
constexpr ts_ms_t sec_to_ms_impl(T t, std::true_type tag) noexcept
Helper function for converting seconds to milliseconds (floating-point version).
TIME_SHIELD_CONSTEXPR T hour24_to_12(T hour) noexcept
Converts a 24-hour format hour to a 12-hour format.
constexpr T1 ms_to_hour(T2 ts) noexcept
Converts a timestamp from milliseconds to hours.
TIME_SHIELD_CONSTEXPR ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
constexpr T1 hour_to_sec(T2 ts) noexcept
Converts a timestamp from hours to seconds.
constexpr ts_t min_to_sec_impl(T t, std::true_type tag) noexcept
Helper function for converting minutes to seconds (floating-point version).
constexpr double sec_to_fmin(T ts) noexcept
Converts a timestamp from seconds to floating-point minutes.
constexpr ts_t hour_to_sec_impl(T t, std::true_type tag) noexcept
Helper function for converting hours to seconds (floating-point version).
constexpr fts_t hour_to_fsec(T hr) noexcept
Converts a timestamp from hours to floating-point seconds.
constexpr fts_t min_to_fsec(T min) noexcept
Converts a timestamp from minutes to floating-point seconds.
constexpr T1 ms_to_sec(T2 ts_ms) noexcept
Converts a timestamp from milliseconds to seconds.
constexpr T1 min_to_ms(T2 ts) noexcept
Converts a timestamp from minutes to milliseconds.
constexpr T1 ms_to_min(T2 ts) noexcept
Converts a timestamp from milliseconds to minutes.
constexpr T1 sec_to_min(T2 ts) noexcept
Converts a timestamp from seconds to minutes.
constexpr T1 sec_to_hour(T2 ts) noexcept
Converts a timestamp from seconds to hours.
constexpr T1 sec_to_ms(T2 ts) noexcept
Converts a timestamp from seconds to milliseconds.
constexpr ts_ms_t hour_to_ms_impl(T t, std::true_type tag) noexcept
Helper function for converting hours to milliseconds (floating-point version).
constexpr ts_ms_t min_to_ms_impl(T t, std::true_type tag) noexcept
Helper function for converting minutes to milliseconds (floating-point version).
constexpr fts_t ms_to_fsec(T ts_ms) noexcept
Converts a timestamp from milliseconds to floating-point seconds.
ts_ms_t fsec_to_ms(fts_t ts) noexcept
Converts a floating-point timestamp from seconds to milliseconds.
int64_t ts_t
Unix timestamp in seconds since 1970‑01‑01T00:00:00Z.
int64_t ts_ms_t
Unix timestamp in milliseconds since epoch.
double fts_t
Floating-point timestamp (fractional seconds since epoch).
T ns_of_sec() noexcept
Get the nanosecond part of the current second.
T ms_of_sec() noexcept
Get the millisecond part of the current second.
T us_of_sec() noexcept
Get the microsecond part of the current second.
Main namespace for the Time Shield library.
Type definitions for time-related units and formats.