9#include <botan/calendar.h>
10#include <botan/exceptn.h>
20std::tm do_gmtime(std::time_t time_val)
24#if defined(BOTAN_TARGET_OS_HAS_WIN32)
25 ::gmtime_s(&tm, &time_val);
26#elif defined(BOTAN_TARGET_OS_HAS_POSIX1)
27 ::gmtime_r(&time_val, &tm);
29 std::tm* tm_p = std::gmtime(&time_val);
31 throw Encoding_Error(
"time_t_to_tm could not convert");
47size_t days_since_epoch(uint32_t year, uint32_t month, uint32_t day)
51 const uint32_t era = year / 400;
52 const uint32_t yoe = year - era * 400;
53 const uint32_t doy = (153*(month + (month > 2 ? -3 : 9)) + 2)/5 + day-1;
54 const uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy;
55 return era * 146097 + doe - 719468;
63 throw Invalid_Argument(
"calendar_point::to_std_timepoint() does not support years before 1970");
73 throw Invalid_Argument(
"calendar_point::to_std_timepoint() does not support years after 2037 on this system");
80 throw Invalid_Argument(
"calendar_point::to_std_timepoint() does not support years after 2400");
86 const time_t seconds_time_t =
static_cast<time_t
>(seconds_64);
88 if(seconds_64 - seconds_time_t != 0)
93 return std::chrono::system_clock::from_time_t(seconds_time_t);
99 std::stringstream output;
100 output << std::setfill(
'0')
101 << std::setw(4) <<
get_year() <<
"-"
103 << std::setw(2) <<
get_day() <<
"T"
104 << std::setw(2) <<
get_hour() <<
":"
112 const std::chrono::system_clock::time_point& time_point)
114 std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point));
uint32_t get_minutes() const
std::string to_string() const
std::chrono::system_clock::time_point to_std_timepoint() const
uint32_t get_month() const
uint32_t get_seconds() const
uint32_t get_hour() const
uint32_t get_year() const
#define BOTAN_IF_CONSTEXPR
calendar_point calendar_value(const std::chrono::system_clock::time_point &time_point)