6#ifndef _TIME_SHIELD_VALIDATION_HPP_INCLUDED
7#define _TIME_SHIELD_VALIDATION_HPP_INCLUDED
19 template<
class T = year_t>
21 return ((
year & 3) == 0 && ((
year % 25) != 0 || (
year & 15) == 0));
26 template<
class T = year_t>
33 template<
class T = year_t>
52 constexpr int64_t BIAS_292277022000 = 9223371890843040000LL;
53 constexpr int64_t BIAS_2000 = 946684800LL;
56 int64_t secs = -((
ts - BIAS_2000) - BIAS_292277022000);
60 y -= n_400_years * 400;
64 y -= n_100_years * 100;
74 y = secs == 0 ? y : y - 1;
103 template<
class T =
int>
106 const T& min)
noexcept {
107 if (hour < 0 || hour > 23)
return false;
108 if (min < 0 || min > 59)
return false;
114 template<
class T =
int>
127 template<
class T = TimeZoneStruct>
129 const T& time_zone)
noexcept {
135 template<
class T = TimeZoneStruct>
137 const T& time_zone) {
143 template<
class T = TimeZoneStruct>
145 const T& time_zone) {
159 template<
class T1 =
int,
class T2 =
int>
164 const T2& ms = 0) noexcept {
165 if (hour < 0 || hour > 23)
return false;
166 if (min < 0 || min > 59)
return false;
167 if (sec < 0 || sec > 59)
return false;
168 if (ms < 0 || ms > 999)
return false;
178 const T& time)
noexcept {
179 return is_valid_time(time.hour, time.min, time.sec, time.ms);
189 template<
class T1 = year_t,
class T2 =
int>
193 const T2& day)
noexcept {
194 if (day > 31 &&
year <= 31) {
198 if (month < 1 || month > 12)
return false;
199 if (day < 1 || day > 31)
return false;
210 if (day > 30)
return false;
239 template<
class T1 = year_t,
class T2 =
int,
class T3 =
int>
247 const T3& ms = 0) noexcept {
259 const T &date_time)
noexcept {
275 return (wd ==
SUN || wd ==
SAT);
291 template<
class T = uday_t>
294 return (wd ==
SUN || wd ==
SAT);
299 template<
class T = uday_t>
Header file with preprocessor definitions.
#define TIME_SHIELD_CONSTEXPR
Header file with time-related constants.
Main namespace for the Time Shield library.
int64_t ts_t
Integer timestamp type.
constexpr const bool is_leap_year_date(const T &year) noexcept
Checks if the given year is a leap year.
TIME_SHIELD_CONSTEXPR bool is_valid_tz(const T &hour, const T &min)
Alias for is_valid_time_zone function.
TIME_SHIELD_CONSTEXPR const bool check_leap_year_ts(const ts_t &ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR const bool is_leap_year_ts(const ts_t &ts)
Checks if the given year is a leap year.
constexpr const bool check_leap_year(const T &year) noexcept
Alias for is_leap_year_date function.
TIME_SHIELD_CONSTEXPR const bool is_valid_time_zone(const T &hour, const T &min) noexcept
Check if the time zone is valid.
TIME_SHIELD_CONSTEXPR const bool is_day_off(const ts_t &ts) noexcept
Check if a given timestamp corresponds to a weekend day (Saturday or Sunday).
constexpr int64_t SEC_PER_DAY
Seconds per day.
constexpr const bool leap_year(const T &year) noexcept
Alias for is_leap_year_date function.
TIME_SHIELD_CONSTEXPR bool is_weekend_unix_day(const T &unix_day) noexcept
Alias for is_day_off_unix_day function.
constexpr const T unix_day(const ts_t &ts=ts()) noexcept
Alias for get_unix_day function.
TIME_SHIELD_CONSTEXPR const bool is_valid_date(const T1 &year, const T2 &month, const T2 &day) noexcept
Checks the correctness of the specified date.
TIME_SHIELD_CONSTEXPR const bool is_valid_time(const T1 &hour, const T1 &min, const T1 &sec, const T2 &ms=0) noexcept
Checks the correctness of the specified time.
constexpr int64_t DAYS_PER_WEEK
Days per week.
TIME_SHIELD_CONSTEXPR const bool leap_year_ts(const ts_t &ts)
Alias for is_leap_year_ts function.
constexpr int64_t SEC_PER_4_YEARS
Seconds per 4 years.
constexpr int64_t SEC_PER_100_YEARS
Seconds per 100 years.
TIME_SHIELD_CONSTEXPR const T year(const ts_t &ts=ts())
Alias for get_year function.
TIME_SHIELD_CONSTEXPR const bool is_weekend(const ts_t &ts) noexcept
Alias for is_day_off function.
TIME_SHIELD_CONSTEXPR bool is_day_off_unix_day(const T &unix_day) noexcept
Check if a given day (since Unix epoch) corresponds to a weekend day (Saturday or Sunday)....
TIME_SHIELD_CONSTEXPR const bool is_valid_date_time(const T1 &year, const T2 &month, const T2 &day, const T2 &hour=0, const T2 &min=0, const T2 &sec=0, const T3 &ms=0) noexcept
Checks the correctness of a date and time.
TIME_SHIELD_CONSTEXPR const bool is_leap_year(const ts_t &ts)
Alias for is_leap_year_ts function.
constexpr int64_t SEC_PER_400_YEARS
Seconds per 400 years.
constexpr int64_t MAX_YEAR
Maximum representable year.
TIME_SHIELD_CONSTEXPR const bool is_valid_time_zone_offset(const T &time_zone) noexcept
Check if the time zone is valid.
const ts_t ts() noexcept
Get the current UTC timestamp in seconds.
constexpr int64_t SEC_PER_YEAR
Seconds per year (365 days)
Header file with type definitions.