7#ifndef __TIME_SHIELD_VALIDATION_MQH__
8#define __TIME_SHIELD_VALIDATION_MQH__
17#property copyright "Copyright 2025, NewYaroslav"
18#property link "https://github.com/NewYaroslav/time-shield-cpp"
31 return ((
year & 3) == 0 && ((
year % 25) != 0 || (
year & 15) == 0));
48 const long BIAS_292277022000 = 9223371890843040000LL;
49 const long BIAS_2000 = 946684800LL;
52 long secs = -((
ts - BIAS_2000) - BIAS_292277022000);
56 y -= n_400_years * 400;
60 y -= n_100_years * 100;
70 y = secs == 0 ? y : y - 1;
93 if (hour < 0 || hour > 23)
return false;
94 if (min < 0 || min > 59)
return false;
131 bool is_valid_time(
const int hour,
const int min,
const int sec,
const int ms = 0) {
132 if (hour < 0 || hour > 23)
return false;
133 if (min < 0 || min > 59)
return false;
134 if (sec < 0 || sec > 59)
return false;
135 if (ms < 0 || ms > 999)
return false;
152 if (day > 31 &&
year <= 31)
155 if (month < 1 || month > 12)
return false;
156 if (day < 1 || day > 31)
return false;
159 if (leap && day > 29)
return false;
160 if (!leap && day > 28)
return false;
167 if (day > 30)
return false;
221 return (wd ==
SUN || wd ==
SAT);
233 return (wd ==
SUN || wd ==
SAT);
constexpr int64_t DAYS_PER_WEEK
Days per week.
constexpr int64_t SEC_PER_YEAR
Seconds per year (365 days)
constexpr int64_t SEC_PER_100_YEARS
Seconds per 100 years.
constexpr int64_t MAX_YEAR
Maximum representable year.
constexpr int64_t SEC_PER_400_YEARS
Seconds per 400 years.
constexpr int64_t SEC_PER_DAY
Seconds per day.
constexpr int64_t SEC_PER_4_YEARS
Seconds per 4 years.
TIME_SHIELD_CONSTEXPR const ts_t ts(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0)
Alias for to_timestamp function.
constexpr const T unix_day(ts_t ts=ts()) noexcept
Alias for get_unix_day function.
TIME_SHIELD_CONSTEXPR const T year(ts_t ts=ts())
Alias for get_year function.
TIME_SHIELD_CONSTEXPR const bool is_valid_time_zone_offset(const T &time_zone) noexcept
Check if the time zone is valid.
constexpr const bool is_leap_year_date(T year) noexcept
Checks if the given year is a leap year.
TIME_SHIELD_CONSTEXPR bool is_valid_tz(T hour, T min)
Alias for is_valid_time_zone function.
TIME_SHIELD_CONSTEXPR const bool is_day_off(ts_t ts) noexcept
Check if a given timestamp corresponds to a weekend day (Saturday or Sunday).
constexpr const bool check_leap_year(T year) noexcept
Alias for is_leap_year_date function.
TIME_SHIELD_CONSTEXPR const bool is_valid_date(T1 year, T2 month, T2 day) noexcept
Checks the correctness of the specified date.
TIME_SHIELD_CONSTEXPR const bool leap_year_ts(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR const bool is_valid_time(T1 hour, T1 min, T1 sec, T2 ms=0) noexcept
Checks the correctness of the specified time.
TIME_SHIELD_CONSTEXPR const bool is_valid_date_time(T1 year, T2 month, T2 day, T2 hour=0, T2 min=0, T2 sec=0, T3 ms=0) noexcept
Checks the correctness of a date and time.
TIME_SHIELD_CONSTEXPR const bool check_leap_year_ts(ts_t ts)
Alias for is_leap_year_ts function.
constexpr const bool leap_year(T year) noexcept
Alias for is_leap_year_date function.
TIME_SHIELD_CONSTEXPR const bool is_valid_time_zone(T hour, T min) noexcept
Check if the time zone is valid.
TIME_SHIELD_CONSTEXPR const bool is_leap_year(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR const bool is_leap_year_ts(ts_t ts)
Checks if the given year is a leap year.
TIME_SHIELD_CONSTEXPR const bool is_weekend(ts_t ts) noexcept
Alias for is_day_off function.
TIME_SHIELD_CONSTEXPR bool is_weekend_unix_day(T unix_day) noexcept
Alias for is_day_off_unix_day function.
TIME_SHIELD_CONSTEXPR bool is_day_off_unix_day(T unix_day) noexcept
Check if a given day (since Unix epoch) corresponds to a weekend day (Saturday or Sunday)....
Main namespace for the Time Shield library.
Structure to represent a date.
int32_t mon
Month component of the date (1-12).
int32_t day
Day component of the date (1-31).
int64_t year
Year component of the date.
Structure to represent date and time.
Structure to represent time.
int16_t ms
Millisecond component of time (0-999)
int16_t hour
Hour component of time (0-23)
int16_t sec
Second component of time (0-59)
int16_t min
Minute component of time (0-59)
Structure to represent time zone information.
int hour
Hour component of time (0-23)
int min
Minute component of time (0-59)