59 static_cast<size_t>(std::numeric_limits<int>::max()) +
tm_epoch_year;
61 static_cast<time_t>(24 * 60 * 60);
67 return (
yy % 4 == 0
and yy % 100 != 0)
or (
yy % 400 == 0);
83 {31u, 28u, 31u, 30u, 31u, 30u, 31u, 31u, 30u, 31u, 30u, 31u};
96 <<
"Year " <<
yy <<
" is outside the supported range ["
100 <<
"Invalid date components"
101 <<
" (dd=" <<
dd <<
", mm=" <<
mm <<
", yy=" <<
yy <<
')';
104 tm.tm_mday =
static_cast<int>(
dd);
105 tm.tm_mon =
static_cast<int>(
mm) - 1;
106 tm.tm_year =
static_cast<int>(
yy) - 1900;
109 return std::mktime(&
tm);
118 <<
"Input string '" << s <<
"' does not match format '" <<
format <<
'\'';
121 return std::mktime(&
tm);
127 return to_time_t(s,
"%Y-%m-%d %H:%M:%S");
134 <<
"to_days() expects non-negative timestamps";
142 const std::tm *
tm_ptr = std::localtime(&t);
149 <<
"Unable to format time using pattern '" <<
format <<
"'";
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
#define ah_range_error_if(C)
Throws std::range_error if condition holds.
constexpr size_t tm_epoch_year
constexpr time_t seconds_per_day
constexpr size_t max_supported_year
Main namespace for Aleph-w library functions.
size_t to_days(const time_t t)
Return the number of whole days represented by t.
bool valid_month(const size_t mm) noexcept
Check whether the month number is within the [1, 12] range.
bool is_leap_year(const size_t yy) noexcept
Return true if the provided year is a leap year.
bool valid_day(const size_t yy, const size_t mm, const size_t dd) noexcept
Check whether a given day exists for the supplied month/year.
time_t to_time_t(const size_t dd, const size_t mm, const size_t yy)
Convert a (day, month, year) triple to a POSIX time_t value.
std::string to_string(const time_t t, const std::string &format)
Format a time_t value into a string using format.
DynList< T > maps(const C &c, Op op)
Classic map operation.