3#ifndef _TIME_SHIELD_VALIDATION_HPP_INCLUDED
4#define _TIME_SHIELD_VALIDATION_HPP_INCLUDED
55 template<
class T = year_t>
57 return ((
year & 3) == 0 && ((
year % 25) != 0 || (
year & 15) == 0));
62 template<
class T = year_t>
69 template<
class T = year_t>
88 constexpr int64_t BIAS_292277022000 = 9223371890843040000LL;
89 constexpr int64_t BIAS_2000 = 946684800LL;
92 int64_t secs = -((
ts - BIAS_2000) - BIAS_292277022000);
96 y -= n_400_years * 400;
100 y -= n_100_years * 100;
110 y = secs == 0 ? y : y - 1;
139 template<
class T =
int>
143 if (hour < 0 || hour > 23)
return false;
144 if (min < 0 || min > 59)
return false;
150 template<
class T =
int>
164 template<
class T = TimeZoneStruct>
166 const T& time_zone)
noexcept {
173 template<
class T = TimeZoneStruct>
175 const T& time_zone) {
182 template<
class T = TimeZoneStruct>
184 const T& time_zone) {
198 template<
class T1 =
int,
class T2 =
int>
203 T2 ms = 0) noexcept {
204 if (hour < 0 || hour > 23)
return false;
205 if (min < 0 || min > 59)
return false;
206 if (sec < 0 || sec > 59)
return false;
207 if (ms < 0 || ms > 999)
return false;
218 const T& time)
noexcept {
219 return is_valid_time(time.hour, time.min, time.sec, time.ms);
229 template<
class T1 = year_t,
class T2 =
int>
234 if (day > 31 &&
year <= 31) {
238 if (month < 1 || month > 12)
return false;
239 if (day < 1 || day > 31)
return false;
250 if (day > 30)
return false;
280 template<
class T1 = year_t,
class T2 =
int,
class T3 =
int>
288 T3 ms = 0) noexcept {
301 const T &date_time)
noexcept {
317 return (wd ==
SUN || wd ==
SAT);
333 template<
class T = uday_t>
336 return (wd ==
SUN || wd ==
SAT);
341 template<
class T = uday_t>
369 const auto m =
static_cast<int>(month);
370 const auto d =
static_cast<int>(day);
375 const int64_t adj_y =
static_cast<int64_t
>(y) - (
static_cast<int64_t
>(m) <= 2 ? 1 : 0);
376 const int64_t adj_m =
static_cast<int64_t
>(m) <= 2
377 ?
static_cast<int64_t
>(m) + 9
378 :
static_cast<int64_t
>(m) - 3;
379 const int64_t era = (adj_y >= 0 ? adj_y : adj_y - 399) / 400;
380 const int64_t yoe = adj_y - era * 400;
381 const int64_t doy = (153 * adj_m + 2) / 5 +
static_cast<int64_t
>(d) - 1;
382 const int64_t doe = yoe * 365 + yoe / 4 - yoe / 100 + doy;
Configuration macros for the library.
Header file with time-related constants.
Header file with enumerations for weekdays, months, and other time-related categories.
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 MS_PER_SEC
Milliseconds per second.
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.
constexpr T unix_day(ts_t ts=time_shield::ts()) noexcept
Alias for get_unix_day function.
TIME_SHIELD_CONSTEXPR ts_t ts(year_t year, int month, int day)
Alias for to_timestamp.
constexpr ts_ms_t ts_ms(year_t year, int month, int day)
Alias for to_timestamp_ms.
TIME_SHIELD_CONSTEXPR T year(ts_t ts=time_shield::ts())
Alias for get_year function.
bool is_workday(const std::string &str)
Parse an ISO8601 string and check if it falls on a workday using second precision.
bool is_workday_ms(const std::string &str)
Parse an ISO8601 string and check if it falls on a workday using millisecond precision.
TIME_SHIELD_CONSTEXPR bool is_valid_time_zone_offset(const T &time_zone) noexcept
Check if the time zone is valid.
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.
int64_t uday_t
Unix day count since 1970‑01‑01 (days since epoch).
int64_t year_t
Year as an integer (e.g., 2024).
TIME_SHIELD_CONSTEXPR bool is_day_off(ts_t ts) noexcept
Check if a given timestamp corresponds to a weekend day (Saturday or Sunday).
constexpr bool check_leap_year(T year) noexcept
Alias for is_leap_year_date function.
TIME_SHIELD_CONSTEXPR bool is_leap_year(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR bool is_valid_tz(T hour, T min)
Alias for is_valid_time_zone function.
TIME_SHIELD_CONSTEXPR bool is_valid_time_zone(T hour, T min) noexcept
Check if the time zone is valid.
TIME_SHIELD_CONSTEXPR bool is_valid_date(T1 year, T2 month, T2 day) noexcept
Checks the correctness of the specified date.
TIME_SHIELD_CONSTEXPR bool is_weekend(ts_t ts) noexcept
Alias for is_day_off function.
TIME_SHIELD_CONSTEXPR bool is_valid_time(T1 hour, T1 min, T1 sec, T2 ms=0) noexcept
Checks the correctness of the specified time.
TIME_SHIELD_CONSTEXPR bool leap_year_ts(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR 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 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)....
constexpr bool is_leap_year_date(T year) noexcept
Checks if the given year is a leap year.
TIME_SHIELD_CONSTEXPR bool check_leap_year_ts(ts_t ts)
Alias for is_leap_year_ts function.
TIME_SHIELD_CONSTEXPR bool is_leap_year_ts(ts_t ts)
Checks if the given year is a leap year.
constexpr bool leap_year(T year) noexcept
Alias for is_leap_year_date function.
Main namespace for the Time Shield library.
Header for time zone structure and related functions.
Type definitions for time-related units and formats.